diff --git a/aliases b/aliases index 61786b2..27330db 100644 --- a/aliases +++ b/aliases @@ -228,6 +228,14 @@ dl_twitch_vid() { local name_format="%(upload_date)s-shortname-twitch-%(id)s" fi + # Download Twitch chat transcript + local chat_file=$(youtube-dl.exe --get-filename -o "$name_format" $url) + rechat.exe -d $url "$chat_file.json" + rechat.exe -p "$chat_file.json" "$chat_file.txt" -b -o + mv "$chat_file.txt" "${chat_file:0:4}-${chat_file:4:2}-${chat_file:6}.txt" + rm "$chat_file.json" + + # Download the video. local filename=$(youtube-dl.exe --get-filename -o "$name_format.%(ext)s" $url) filename="${filename:0:4}-${filename:4:2}-${filename:6}" @@ -235,13 +243,6 @@ dl_twitch_vid() { error=$? if [[ $error -eq 0 ]]; then - # Download Twitch chat transcript - local chat_file=$(youtube-dl.exe --get-filename -o "$name_format" $url) - rechat.exe -d $url "$chat_file.json" - rechat.exe -p "$chat_file.json" "$chat_file.txt" -b -o - mv "$chat_file.txt" "${chat_file:0:4}-${chat_file:4:2}-${chat_file:6}.txt" - rm "$chat_file.json" - if [[ $compression_level -ne 0 ]]; then compress-video "$filename" $compression_level "temp" extension="${filename##*.}" @@ -549,33 +550,35 @@ alias yt-audio='youtube-dl.exe -f "140"' alias yt-and-hflip='dl_youtube_vid_and_hflip "137+140"' # 1080p alias ig-download-and-hflip='dl_instagram_vid_and_hflip ' +compression_quality=27 # 27 for gpu; 25 for cpu + alias tw='dl_twitch_vid "1080p" 0 0' -alias tw-compressed='dl_twitch_vid "1080p" 0 25' +alias tw-compressed='dl_twitch_vid "1080p" 0 $compression_quality' alias tw-shortname='dl_twitch_vid "1080p" 1 0' -alias tw-shortname-compressed='dl_twitch_vid "1080p" 1 25' +alias tw-shortname-compressed='dl_twitch_vid "1080p" 1 $compression_quality' alias tw-custom='dl_twitch_vid ' alias tw-chat='dl_twitch_chat' alias tw-1080='dl_twitch_vid "1080" 0 0' -alias tw-1080-compressed='dl_twitch_vid "1080" 0 25' +alias tw-1080-compressed='dl_twitch_vid "1080" 0 $compression_quality' alias tw-1080-shortname='dl_twitch_vid "1080" 1 0' -alias tw-1080-shortname-compressed='dl_twitch_vid "1080" 1 25' +alias tw-1080-shortname-compressed='dl_twitch_vid "1080" 1 $compression_quality' -alias tw-60='dl_twitch_vid "1080p60" 0 0' -alias tw-60-compressed='dl_twitch_vid "1080p60" 0 25' -alias tw-60-shortname='dl_twitch_vid "1080p60" 1 0' -alias tw-60-shortname-compressed='dl_twitch_vid "1080p60" 1 25' +alias tw-1080p60='dl_twitch_vid "1080p60" 0 0' +alias tw-1080p60-compressed='dl_twitch_vid "1080p60" 0 $compression_quality' +alias tw-1080p60-shortname='dl_twitch_vid "1080p60" 1 0' +alias tw-1080p60-shortname-compressed='dl_twitch_vid "1080p60" 1 $compression_quality' alias tw-720='dl_twitch_vid "720p" 0 0' -alias tw-720-compressed='dl_twitch_vid "720p-1" 0 25' +alias tw-720-compressed='dl_twitch_vid "720p-1" 0 $compression_quality' alias tw-720-shortname='dl_twitch_vid "720p-1" 1 0' alias tw-720-60='dl_twitch_vid "720p60" 0 0' alias tw-720-60-shortname='dl_twitch_vid "720p60" 1 0' alias tw-4k='dl_twitch_vid "2160p" 0 0' -alias tw-4k-compressed='dl_twitch_vid "2160p" 0 25' +alias tw-4k-compressed='dl_twitch_vid "2160p" 0 $compression_quality' alias tw-4k-shortname='dl_twitch_vid "2160p" 1 0' -alias tw-4k-shortname-compressed='dl_twitch_vid "2160p" 1 25' +alias tw-4k-shortname-compressed='dl_twitch_vid "2160p" 1 $compression_quality' alias tw-source='dl_twitch_vid "Source" 0 0' diff --git a/bin/compress-video b/bin/compress-video index d923a0d..b92ddfc 100644 --- a/bin/compress-video +++ b/bin/compress-video @@ -34,8 +34,8 @@ filename="${filename%.*}" use_crf=$2 default_crf=25 # Programming vids have pretty crisp text @ crf 25. - output_name="$3" +use_cpu=$4 function encode() { crf=$1 @@ -46,7 +46,14 @@ function encode() { fi printf "\n${YELLOW}${BOLD}Encoding '$filename.$extension' with CRF $crf | output: $output${NORMAL}\n" - ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output" + + if [[ $use_cpu -eq 1 ]]; then + ffmpeg -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output" + else + # File will be slightly larger than CPU encoding, but it's much faster to transcode and doesn't max out the CPU cores. + ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -i "$filename.$extension" -c:a copy -c:v h264_nvenc \ + -profile:v high -rc:v vbr_hq -cq:v $crf -b:v 5M -maxrate 5M -max_muxing_queue_size 9999 "$output" + fi printf "\n${GREEN}${BOLD}Done encoding '$filename.$extension' with CRF $crf${NORMAL}\n\n" }