{"id":205,"date":"2022-11-29T10:22:10","date_gmt":"2022-11-29T15:22:10","guid":{"rendered":"https:\/\/daveking.com\/blog\/?p=205"},"modified":"2023-03-20T07:19:49","modified_gmt":"2023-03-20T11:19:49","slug":"my-ffmpeg-cheat-sheet","status":"publish","type":"post","link":"https:\/\/daveking.com\/blog\/index.php\/2022\/11\/29\/my-ffmpeg-cheat-sheet\/","title":{"rendered":"My FFmpeg Cheat Sheet"},"content":{"rendered":"\n<hr style=\"border:3px solid green\">\n\n\n\n<p class=\"wp-block-paragraph\">Some videos come with audio and video in one file and subtitles in another.  To merge everything together into a single MKV file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ffmpeg -i VIDEO.mp4 -i SUBTITLES.srt -c:v copy -c:a copy -c:s srt -metadata:s:s language=eng OUTPUT.mkv<\/code><\/pre>\n\n\n\n<hr style=\"border:3px solid green\">\n\n\n\n<p class=\"wp-block-paragraph\">Some MKV video files are huge, with high video bitrates, high frames-per-second rates, and many subtitle streams.  To shrink the file and remove the extra subtitle streams:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ffmpeg -i VIDEO.mkv -c:v libx265 -cq 35 -r 29.97 -c:a copy -c:s copy -map 0:0 -map 0:1 -map 0:3 -map_metadata:s -1 -metadata:s:s language=eng OUTPUT.mkv<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the machine doing the encoding has an NVIDIA GPU with the CUDA drivers installed then replace &#8220;libx265&#8221; with &#8220;hevc_nvenc&#8221; as the video codec in the command above.  This will significantly speed up the process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr style=\"border:3px solid green\">\n\n\n\n<p class=\"wp-block-paragraph\">To merge a video and two subtitle files while dropping all the metadata from the input files, giving each subtitle stream a different title, and having the first subtitle stream play by default:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ffmpeg -i VIDEO.mkv -i SUBTITLE_1.srt -i SUBTITLE_2.srt -map 0:0 -map 0:1 -map 1:0 -map 2:0 -c:v libx265 -cq 35 -c:a copy -c:s copy -map_metadata -1 -metadata:s:s:0 language=eng -metadata:s:s:0 title=English -metadata:s:s:1 language=eng -metadata:s:s:1 title=\"English (SDH)\" -disposition:s:0 default OUTPUT.mkv<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the machine doing the encoding has an NVIDIA GPU with the CUDA drivers installed then replace &#8220;libx265&#8221; with &#8220;hevc_nvenc&#8221; as the video codec in the command above.  This will significantly speed up the process.<\/p>\n\n\n\n<hr style=\"border:3px solid green\">\n","protected":false},"excerpt":{"rendered":"<p>A list of video processing commands that I want to remember.<\/p>\n","protected":false},"author":1,"featured_media":206,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[22,13,26],"tags":[23,12,27],"class_list":["post-205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howto","category-software-that-i-use","category-video-processing","tag-howto","tag-software","tag-video","eq-blocks"],"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/daveking.com\/blog\/wp-content\/uploads\/2022\/11\/ffmpeg_logo.jpg?fit=500%2C281&ssl=1","_links":{"self":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=205"}],"version-history":[{"count":16,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/205\/revisions\/309"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/206"}],"wp:attachment":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}