Last active
April 5, 2021 23:27
-
-
Save aram535/af8d55bbaf5a436c9fa6fef7df106035 to your computer and use it in GitHub Desktop.
ffmpeg recipes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -preset veryslow/slow/medium/fast/veryfast | |
| # add -t 60 to produce a 60 second test file before committing to the full reencode | |
| # for animated video add: -tune animation | |
| # replace or add new metadata with: -metadata title="my description" | |
| # reencode as h264 | |
| # lower crf is better quality | |
| ffmpeg -i input.mkv -c:v h264 -crf 18 output.mkv | |
| # reencode as h265 | |
| ffmpeg -i input.mkv -c:v h265 -crf 18 output.mkv | |
| # fix the plex odd behavior when reencoding the audio/subtitle | |
| ffmpeg -fflags +genpts -i "$i" -c:v h264 -c:a aac -metadata:s:a:0 language=eng $tempdir/"${filename%.*}".mkv | |
| # Map video + (bitmap subtitle), along with first audio: | |
| ffmpeg -i "$i" -i "$subtitle".srt -map 0:v -map 0:a:0 -map 0:a:1 -map 1:s:0 output.mkv | |
| # replace existing sub with english one, no reencoding | |
| ffmpeg -i input.mkv -i input.en.srt -map 0:v -map 0:a -map 1 -c:v copy -c:a copy -c:s copy -metadata:s:s:0 language=eng output.mkv | |
| # extract audio and reencode as mp3 (remove all options other than -i and output, to just extract) | |
| ffmpeg -i input.mkv -vn -ar 44100 -ac 2 -ab 128k -f mp3 output.mp3 | |
| # concat simple | |
| # create files.txt | |
| # win: (for %%i in (*.wmv) do @echo file '%%i') > files.txt | |
| # ps: foreach ($i in Get-ChildItem .\*.wmv) {echo "file '$i'" >> mylist.txt} | |
| # nix: for f in ./*.mp4; do echo "file '$f'" >> files.txt; done | |
| ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4 | |
| # joining two files with conversion | |
| ffmpeg -i in1.mp4 -c copy -bsf h264_mp4toannexb 100.h264 | |
| ffmpeg -i in2.mp4 -c copy -bsf h264_mp4toannexb 200.h264 | |
| ffmpeg -i "concat:100.h264|200.h264" -i audio_in.mp3 -c copy output.mp4 # use mp4box for this | |
| # Reencoding with NVIDIA, reducing to 1.5M b/s, 720p | |
| # -r 30 will add in a 30fps limit, but that will cause a conflict with vsync | |
| ffmpeg -y -vsync 0 -c:v h264_cuvid -i input.mp4 -vf "scale=-1:720" -b:v 1.5M -c:v h264_nvenc -strict -2 -movflags +faststart output.mp4 | |
| -- bash yt downloads: | |
| for x in `ls *webm` | |
| do | |
| echo $x | |
| ffmpeg -i $x -vsync 0 -c:v h264_cuvid -crf 20 -c:v h264_nvenc -c:a ac3 -b:a 384k -ac 2 -c:s copy -max_muxing_queue_size 1024 -movflags +faststart ${x%.*}.mp4 | |
| done | |
| # my current set of options on windows, using a RTX 2080, processing bitrate: 3800 kb/sec | |
| # this is a simple re-encode to the latest x264 codec, removing extra subtitles (only 0:2 is copied), all audio is converted to ac3 | |
| ffmpeg -y -vsync 0 -map 0 -c:v h264_cuvid -crf 20 -c:v h264_nvenc -c:a ac3 -b:a 384K -ac 2 -map 0:2 -c:s copy -max_muxing_queue_size 1024 -movflags +faststart | |
| ## HEVC high quality encoding using GPU - HEVC enabled further compression (reduced file size than H.264) | |
| -c:v hevc_nvenc | |
| -b:v 6M | |
| -maxrate 9M | |
| -bufsize 12M | |
| -preset slow | |
| -pix_fmt p010le | |
| -profile:v main10 | |
| -level 4.1 | |
| -tier high | |
| -refs 3 | |
| -coder 1 | |
| -rc vbr_hq | |
| -rc-lookahead 32 | |
| -bf 3 | |
| -b_ref_mode middle | |
| -b_strategy 1 | |
| -r 24000/1001 | |
| # audio conversion to ac3 if you like | |
| -c:a ac3 -b:a 192K | |
| # Decrease the darks and bright up the video a bit: | |
| -vf eq=gamma=1.6:contrast=1.4:brightness=0.15:saturation=1.4 | |
| # Found a lot of good information and more examples in: https://github.com/chgeuer/mybookmarks/blob/master/ffmpeg%20recipes.md | |
| # HQ Setting from reddit: https://www.reddit.com/r/ffmpeg/comments/k3642t/hq_ffmpeg_encoding_with_gpu_nvenc_part_ii/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment