From 85cd5a9d113de506c0722acaada68af56c9f9642 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 19 Sep 2022 16:19:41 +0200 Subject: Move scripts to script dir, add youtube-hls-stream script, fix twitch stream script --- README.md | 2 +- interactive.sh | 17 ----------------- list-sinks.sh | 3 --- replay.sh | 6 ------ scripts/interactive.sh | 17 +++++++++++++++++ scripts/list-sinks.sh | 3 +++ scripts/replay.sh | 6 ++++++ scripts/toggle-recording-selected.sh | 9 +++++++++ scripts/twitch-stream-local-copy.sh | 7 +++++++ scripts/twitch-stream.sh | 5 +++++ scripts/youtube-hls-stream.sh | 11 +++++++++++ src/main.cpp | 2 ++ toggle-recording-selected.sh | 9 --------- twitch-stream-local-copy.sh | 7 ------- twitch-stream.sh | 5 ----- 15 files changed, 61 insertions(+), 48 deletions(-) delete mode 100755 interactive.sh delete mode 100755 list-sinks.sh delete mode 100755 replay.sh create mode 100755 scripts/interactive.sh create mode 100755 scripts/list-sinks.sh create mode 100755 scripts/replay.sh create mode 100755 scripts/toggle-recording-selected.sh create mode 100755 scripts/twitch-stream-local-copy.sh create mode 100755 scripts/twitch-stream.sh create mode 100755 scripts/youtube-hls-stream.sh delete mode 100755 toggle-recording-selected.sh delete mode 100755 twitch-stream-local-copy.sh delete mode 100755 twitch-stream.sh diff --git a/README.md b/README.md index 6a796f8..08550ab 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ If you use a distro that isn't user friendly, such as fedora, then you can also Recording monitors requires a gpu with NvFBC support (note: this is not required when recording a single window!). Normally only tesla and quadro gpus support this, but by using [nvidia-patch](https://github.com/keylase/nvidia-patch) or [nvlax](https://github.com/illnyang/nvlax) you can do this on all gpus that support nvenc as well (gpus as old as the nvidia 600 series), provided you are not using outdated gpu drivers. # How to use -Run `interactive.sh` or run gpu-screen-recorder directly, for example: `gpu-screen-recorder -w $(xdotool selectwindow) -c mp4 -f 60 -a "$(pactl get-default-sink).monitor" -o test_video.mp4`\ +Run `scripts/interactive.sh` or run gpu-screen-recorder directly, for example: `gpu-screen-recorder -w $(xdotool selectwindow) -c mp4 -f 60 -a "$(pactl get-default-sink).monitor" -o test_video.mp4`\ Then stop the screen recorder with Ctrl+C, which will also save the recording.\ Send signal SIGUSR1 (`killall -SIGUSR1 gpu-screen-recorder`) to gpu-screen-recorder when in replay mode to save the replay. The paths to the saved files is output to stdout after the recording is saved.\ You can find the default output audio device (headset, speakers) with the command `pactl get-default-sink`. Add `monitor` to the end of that to use that as an audio input in gpu-screen-recorder.\ diff --git a/interactive.sh b/interactive.sh deleted file mode 100755 index c02e7e9..0000000 --- a/interactive.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -e - -selected_audio_input="$(pactl get-default-sink).monitor" - -echo "Select a window to record" -window_id=$(xdotool selectwindow) - -echo -n "Enter video fps: " -read fps - -echo -n "Enter output file name: " -read output_file_name - -output_dir=$(dirname "$output_file_name") -mkdir -p "$output_dir" - -./gpu-screen-recorder -w "$window_id" -c mp4 -f "$fps" -a "$selected_audio_input" -o "$output_file_name" diff --git a/list-sinks.sh b/list-sinks.sh deleted file mode 100755 index e5fc44f..0000000 --- a/list-sinks.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -pactl list | grep -E '(Description: Monitor of)|(Monitor Source: )' diff --git a/replay.sh b/replay.sh deleted file mode 100755 index 6bbbb54..0000000 --- a/replay.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -e - -[ "$#" -ne 4 ] && echo "usage: replay.sh " && exit 1 -active_sink="$(pactl get-default-sink).monitor" -mkdir -p "$4" -./gpu-screen-recorder -w "$1" -c mp4 -f "$2" -a "$active_sink" -r "$3" -o "$4" diff --git a/scripts/interactive.sh b/scripts/interactive.sh new file mode 100755 index 0000000..63b0eae --- /dev/null +++ b/scripts/interactive.sh @@ -0,0 +1,17 @@ +#!/bin/sh -e + +selected_audio_input="$(pactl get-default-sink).monitor" + +echo "Select a window to record" +window_id=$(xdotool selectwindow) + +echo -n "Enter video fps: " +read fps + +echo -n "Enter output file name: " +read output_file_name + +output_dir=$(dirname "$output_file_name") +mkdir -p "$output_dir" + +gpu-screen-recorder -w "$window_id" -c mp4 -f "$fps" -a "$selected_audio_input" -o "$output_file_name" diff --git a/scripts/list-sinks.sh b/scripts/list-sinks.sh new file mode 100755 index 0000000..e5fc44f --- /dev/null +++ b/scripts/list-sinks.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pactl list | grep -E '(Description: Monitor of)|(Monitor Source: )' diff --git a/scripts/replay.sh b/scripts/replay.sh new file mode 100755 index 0000000..cf6c494 --- /dev/null +++ b/scripts/replay.sh @@ -0,0 +1,6 @@ +#!/bin/sh -e + +[ "$#" -ne 4 ] && echo "usage: replay.sh " && exit 1 +active_sink="$(pactl get-default-sink).monitor" +mkdir -p "$4" +gpu-screen-recorder -w "$1" -c mp4 -f "$2" -a "$active_sink" -r "$3" -o "$4" diff --git a/scripts/toggle-recording-selected.sh b/scripts/toggle-recording-selected.sh new file mode 100755 index 0000000..663f360 --- /dev/null +++ b/scripts/toggle-recording-selected.sh @@ -0,0 +1,9 @@ +#!/bin/sh -e + +killall -INT gpu-screen-recorder && notify-send -u low 'GPU Screen Recorder' 'Stopped recording' && exit 0; +window=$(xdotool selectwindow) +active_sink="$(pactl get-default-sink).monitor" +mkdir -p "$HOME/Videos" +video="$HOME/Videos/$(date +"Video_%Y-%m-%d_%H-%M-%S.mp4")" +notify-send -u low 'GPU Screen Recorder' "Started recording video to $video" +gpu-screen-recorder -w "$window" -c mp4 -f 60 -a "$active_sink" -o "$video" diff --git a/scripts/twitch-stream-local-copy.sh b/scripts/twitch-stream-local-copy.sh new file mode 100755 index 0000000..dba9d15 --- /dev/null +++ b/scripts/twitch-stream-local-copy.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Stream on twitch while also saving the video to disk locally + +[ "$#" -ne 4 ] && echo "usage: twitch-stream-local-copy.sh " && exit 1 +active_sink="$(pactl get-default-sink).monitor" +gpu-screen-recorder -w "$1" -c flv -f "$2" -a "$active_sink" | tee -- "$4" | ffmpeg -i pipe:0 -c copy -f flv -- "rtmp://live.twitch.tv/app/$3" diff --git a/scripts/twitch-stream.sh b/scripts/twitch-stream.sh new file mode 100755 index 0000000..cd4737a --- /dev/null +++ b/scripts/twitch-stream.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +[ "$#" -ne 3 ] && echo "usage: twitch-stream.sh " && exit 1 +active_sink="$(pactl get-default-sink).monitor" +gpu-screen-recorder -w "$1" -c flv -f "$2" -a "$active_sink" -o "rtmp://live.twitch.tv/app/$3" diff --git a/scripts/youtube-hls-stream.sh b/scripts/youtube-hls-stream.sh new file mode 100755 index 0000000..21619af --- /dev/null +++ b/scripts/youtube-hls-stream.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +[ "$#" -ne 3 ] && echo "usage: youtube-hls-stream.sh " && exit 1 +mkdir "youtube_stream" +cd "youtube_stream" +active_sink="$(pactl get-default-sink).monitor" +gpu-screen-recorder -w "$1" -c mpegts -f "$2" -a "$active_sink" | ffmpeg -i pipe:0 -c copy -f hls \ + -hls_time 2 -hls_flags independent_segments -hls_flags delete_segments -hls_segment_type mpegts -hls_segment_filename stream%02d.ts -master_pl_name stream.m3u8 out1 & +echo "Waiting until stream segments are created..." +sleep 10 +ffmpeg -i stream.m3u8 -c copy -- "https://a.upload.youtube.com/http_upload_hls?cid=$3©=0&file=stream.m3u8" diff --git a/src/main.cpp b/src/main.cpp index 25b34d4..c1ab013 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -533,6 +533,8 @@ static AVCodecContext *create_video_codec_context(AVFormatContext *av_format_con codec_context->max_b_frames = 0; codec_context->pix_fmt = AV_PIX_FMT_CUDA; codec_context->color_range = AVCOL_RANGE_JPEG; + if(use_hevc) + codec_context->codec_tag = MKTAG('h', 'v', 'c', '1'); switch(video_quality) { case VideoQuality::MEDIUM: codec_context->bit_rate = 10000000 + (codec_context->width * codec_context->height) / 2; diff --git a/toggle-recording-selected.sh b/toggle-recording-selected.sh deleted file mode 100755 index 663f360..0000000 --- a/toggle-recording-selected.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -e - -killall -INT gpu-screen-recorder && notify-send -u low 'GPU Screen Recorder' 'Stopped recording' && exit 0; -window=$(xdotool selectwindow) -active_sink="$(pactl get-default-sink).monitor" -mkdir -p "$HOME/Videos" -video="$HOME/Videos/$(date +"Video_%Y-%m-%d_%H-%M-%S.mp4")" -notify-send -u low 'GPU Screen Recorder' "Started recording video to $video" -gpu-screen-recorder -w "$window" -c mp4 -f 60 -a "$active_sink" -o "$video" diff --git a/twitch-stream-local-copy.sh b/twitch-stream-local-copy.sh deleted file mode 100755 index 1128a5e..0000000 --- a/twitch-stream-local-copy.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -# Stream on twitch while also saving the video to disk locally - -[ "$#" -ne 4 ] && echo "usage: twitch-stream-local-copy.sh " && exit 1 -active_sink="$(pactl get-default-sink).monitor" -./gpu-screen-recorder -w "$1" -c flv -f "$2" -a "$active_sink" | tee -- "$4" | ffmpeg -i pipe:0 -c:v copy -f flv -- "rtmp://live.twitch.tv/app/$3" diff --git a/twitch-stream.sh b/twitch-stream.sh deleted file mode 100755 index 12928c9..0000000 --- a/twitch-stream.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -[ "$#" -ne 3 ] && echo "usage: twitch-stream.sh " && exit 1 -active_sink="$(pactl get-default-sink).monitor" -./gpu-screen-recorder -w "$1" -c flv -f "$2" -a "$active_sink" "rtmp://live.twitch.tv/app/$3" -- cgit v1.2.3