Skip to content

Instantly share code, notes, and snippets.

@locobastos
Last active November 19, 2022 11:21
Show Gist options
  • Save locobastos/5527a11b418b2a95efd5954a36fb410d to your computer and use it in GitHub Desktop.
Save locobastos/5527a11b418b2a95efd5954a36fb410d to your computer and use it in GitHub Desktop.

PERSONAL COMMAND LINE

FFMPEG :

Single source

ffmpeg.exe -i "input with spaces.mkv" -map 0:0 -map 0:1 \
    -c:a eac3 -ab 128k -ac 2 \
    -c:v libx264 -preset:v veryfast -tune:v animation -profile:v high -level:v 4.1 -b:v 3000k -strict -2 \
    -x264-params ref=4:subme=8:me_range=16:trellis=1:threads=18:lookahead_threads=3:bframes=3:keyint=240:keyint_min=24:rc_lookahead=50:ratetol=1.0:cplxblur=20.0:qblur=0.5 \
    -vf "subtitles='input with spaces.mkv':si=0:force_style='Outline=1,Shadow=0'" output.mp4

With -map, we choose the streams inside the mkv, here the 1st and the 2nd With si=0 we choose the subtitles stream index

Source AVI + SRT

ffmpeg.exe -i input.avi -vf subtitles=french.srt:charenc=LATIN1 -b:v <video_bitrate>k vsubfrench.mp4

Source MKV + ASS

ffmpeg.exe -i input.mkv -vf "ass=subtitle.ass" -b:v <video_bitrate>k vsubfrench.mp4

Separated source

ffmpeg.exe -i audio.aac -i video.avc -vf "subtitles=subs.ass:force_style='FontName=Noto Sans,FontSize=20,OutlineColour=&H00000000,Outline=1,Shadow=0" -b:v 3000k output.mp4
ffmpeg.exe -i audio.aac -i video.avc -vf "subtitles=subs.ass:force_style='Outline=1,Shadow=0" -b:v 3000k output.mp4

-vf to create a filtergraph to add the subtitles and -b:v to specify the bitrate for the video stream

2pass encode with ffmpeg using libx264 and converting x264 10 bit to x264 8 bit

ffmpeg.exe -i audio_input.flac -i video_input.avc \
    -c:a eac3 -ab 128k -ac 2 \
    -c:v libx264 -preset:v veryfast -tune:v animation -profile:v high -level:v 4.1 -b:v 3000k -pass 1 \
    -x264-params ref=4:subme=8:me_range=16:trellis=1:threads=18:lookahead_threads=3:bframes=3:keyint=240:keyint_min=24:rc_lookahead=50:ratetol=1.0:cplxblur=20.0:qblur=0.5 \
    -vf "format=yuv420p,subtitles=sub_input.ass:force_style='Outline=1,Shadow=0" -an -f mp4 NUL
ffmpeg.exe -i audio_input.flac -i video_input.avc \
    -c:a eac3 -ab 128k -ac 2 \
    -c:v libx264 -preset:v veryfast -tune:v animation -profile:v high -level:v 4.1 -b:v 3000k -pass 2 \
    -x264-params ref=4:subme=8:me_range=16:trellis=1:threads=18:lookahead_threads=3:bframes=3:keyint=240:keyint_min=24:rc_lookahead=50:ratetol=1.0:cplxblur=20.0:qblur=0.5 \
    -vf "format=yuv420p,subtitles=sub_input.ass:force_style='Outline=1,Shadow=0" My.Final.HardSubbed.VIDEO.Output.mp4

format=yuv420p is the option to convert from 10 bit to 8 bit

E-AC-3 5.1 to 2.0

ffmpeg.exe -i source.eac3 -c:a eac3 -ab 128k -ac 2 a.eac3

Extract DTS core from DTS-HDMA

ffmpeg.exe -i source.mkv -map 0:a:1 -bsf:a dca_core -c:a copy dts_core.dts

2016p to 1080p

Add scale=1920:-2:flags=lanczos in -vf filtergram:
-vf "scale=1920:-2:flags=lanczos"    

-2 allow the program to keep the aspect ratio and divisible by 2 lanczos is just the algorithm

Change MKV headers with MKVPROPEDIT :

mkvpropedit.exe source.mkv --edit track:a1 --set flag-default=0 --set flag-forced=0 --edit track:a2 --set flag-default=1 --edit track:s1 --set flag-default=1
mkvpropedit.exe source.mkv --edit track:s1 --set name="New_Name"
mkvpropedit.exe source.mkv --edit track:a1 --set track-number=3 --edit track:a2 --set track-number=2
mkvpropedit.exe source.mkv --edit info --set title="New movie name"

HandBrakeCLI queue import :

  • With HandBrake GUI, create your queue then "Export queue (CLI only)"

  • With HandBrake CLI run this command:

    handbrakecli.exe --queue-import-file my-queue.json
    

HandBrakeCLI re-encode 1080p HDLIGHT (3000 kbps max)

HandBrakeCLI.exe -i source.mkv --title 1 --main-feature -o output.mkv --format av_mkv --markers --encoder x264 --encoder-preset veryslow --encoder-tune film --encoder-profile high --encoder-level 4.1 --vb 3000 --two-pass --no-turbo --aencoder eac3 --ab 640k --mixdown 5point1 --arate 48 --all-audio --width 1920 --height 1080 --loose-anamorphic --keep-display-aspect -x ref=4:subme=8:me_range=16:trellis=1:threads=18:lookahead_threads=3:bframes=3:keyint=240:keyint_min=24:rc_lookahead=50:ratetol=1.0:cplxblur=20.0:qblur=0.5

x264 :

VIDEO ONLY

x264.exe --preset veryslow --tune animation --profile high --level 4.1 --bitrate 3000 --pass 1 --slow-firstpass --ref 4 --subme 8 --merange 16 --trellis 1 --threads 18 --lookahead-threads 3 --bframes 3 --keyint 240 --min-keyint 24 --rc-lookahead 50 -o encoded_output.avc original_input.avc
x264.exe --preset veryslow --tune animation --profile high --level 4.1 --bitrate 3000 --pass 2 --slow-firstpass --ref 4 --subme 8 --merange 16 --trellis 1 --threads 18 --lookahead-threads 3 --bframes 3 --keyint 240 --min-keyint 24 --rc-lookahead 50 -o encoded_output.avc original_input.avc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment