{"id":1825,"date":"2022-01-27T12:15:00","date_gmt":"2022-01-27T12:15:00","guid":{"rendered":"https:\/\/www.qworqs.com\/?p=1825"},"modified":"2025-08-12T19:24:08","modified_gmt":"2025-08-12T19:24:08","slug":"ffmpeg-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2022\/01\/27\/ffmpeg-cheat-sheet\/","title":{"rendered":"ffmpeg cheat sheet"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Combine video and audio (yt-dlp)<\/h2>\n\n\n\n<p>First of all, after using yt-dlp to download 2 webm files for a video, you can combine them without reencoding using the following command (See <a href=\"http:\/\/ffmpeg -i ao.webm -i vo.webm -c:v copy -c:a copy output.webm\">here<\/a>), Just make sure both files are VP8 or VP9<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i ao.webm -i vo.webm -c:v copy -c:a copy output.webm<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Extract segment from video<\/h2>\n\n\n\n<p>To extract the section from the file resulting from the first command above<\/p>\n\n\n\n<p>1- From second x, and duration in seconds<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -ss 285 -i g_in.mkv -t 5475 -map 0 -c copy g_out.mkv<\/pre>\n\n\n\n<p>2- From second x to second y<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -copyts -ss 4633 -i g_in.mkv -to 5470 -map 0 -c copy g_p2.mkv<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Convert file<\/h2>\n\n\n\n<p>Converting a file you have downloaded using 1 or any other file into MP4 (H264), since some windows computers will not play a webm file !<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i source264.mp4 -c:v libx265 -crf 28 -preset fast -c:a aac -b:a 128k  -filter:v fps=25 out265.mp4<\/pre>\n\n\n\n<p>If you want to cut a part of the video, without re-encoding it<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i input.mp4 -vcodec copy -acodec copy -ss 00:01:00.000 -t 00:00:02.000 output.mp4<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">nVidia (GPU) : Convert H264\/H265<\/h2>\n\n\n\n<p>Nvidia graphics card to convert H265 (MKV) to H264 MP4, Using nvidia hardware encoder to encode video into H264 or H265 !<\/p>\n\n\n\n<p>To checks whether hardware encoders are available or not, run the command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -encoders | findstr \/ic:\"NVIDIA\"<\/pre>\n\n\n\n<p>If the following two lines are in the command, you can use the nVidia encoder, the first codec is H264, and the second is for H265 (HEVC)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)\nV....D hevc_nvenc           NVIDIA NVENC hevc encoder (codec hevc)<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg.exe -vsync 0 -hwaccel cuda -i &lt;input_file&gt; -map 0  -c:a copy -c:v h264_nvenc -pix_fmt yuv420p -preset hq &lt;output_file&gt;<\/pre>\n\n\n\n<p>-vsync : Synchronize video audio and metadata using the video timestamp<br>-hwaccel cuda : Use nVidia&#8217;s cuda for hardware accelleration<\/p>\n\n\n\n<p><strong>Example<\/strong>, Convert mkv to mp4 (<strong>Tested OK<\/strong>)<\/p>\n\n\n\n<p>Now, with the above out of the way, the following command should encode your 1080P mkv H265 video to H264 ! all within GPU, so this re-encodes an nVidia compatible format to another nVidia compatible format, on my 1650 card, it was encoding at 12x. this provides better compatibility, if smaller file size and quality are what you seek, then you should do it the other way around<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i \"1080p.mkv\" -c:v h264_nvenc -pix_fmt yuv420p -minrate 500k -maxrate 1000k -c:a mp3 -b:a 128k \"1080p.mp4\"<\/pre>\n\n\n\n<p>The other way around<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i \"1080p.mp4\" -c:v hevc_nvenc -pix_fmt yuv420p -minrate 200k -maxrate 1000k -c:a aac -b:a 128k \"1080p.mkv\"<\/pre>\n\n\n\n<p>NOTE: The above does everything within the GPU, if for example you wanted the decoding on CPU, that will make things much slower because the decoded video (Huge) will still need to be copied to the GPU,<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">nVidia : DVD to H265<\/h2>\n\n\n\n<p>Encoding H265 with my entry level GPU (1650) is around <strong>five to fifteen times faster<\/strong> than with CPU (6 core, 12 thread i7-4930K), CPU was running at around 50% load through the encoding<\/p>\n\n\n\n<p>Now one very common task people want to execute is converting their old, bulky DVD collection to H265 (Or H264 if they value compatibility over size and clarity), DVD files are usually on a DVD in the Video_TS folder, and the AudioTS folder, So this will create a few cases<\/p>\n\n\n\n<p><strong>Case 1<\/strong>: Audio_ts folder is empty, Video TS folder has files that you know the order they should be displayed in, the objective is to put them all in one video file (Assuming MKV but the container is your choice), in this case, I usually start by converting all the videos to H265, then combine them, here, most of my videos are interlaced (that will be dealt with with yadif), and sometimes, they are files of different resolutions, so I will unify their size<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i \"v1.VOB\" -c:v hevc_nvenc -c:a aac -b:a 256k -vf yadif,scale=1920:1080 -x265-params \"crf=22:min-keyint=25:keyint=50\" -preset slow \"d1.mkv\"<\/pre>\n\n\n\n<p>Now, create a list of the files<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(for %i in (*.mkv) do @echo file '%i') &gt; mylist.txt<\/pre>\n\n\n\n<p>And concatenate the videos<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -f concat -i mylist.txt -c copy output.mkv<br><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Now, to batch process a folder on the command line... in this example i am lowering the resolution of files to FHD from 4K<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>for \/f \"tokens=1 delims=.\" %a in ('dir \/B *.mp4') do ffmpeg -i \"%a.mp4\" \"%a.1080.mp4\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">And here is one meant to extract the audio from all the MP4 files<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Windows<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">for \/f \"tokens=1 delims=.\" %a in ('dir \/B *.mp4') do ffmpeg -i \"%a.mp4\" -vn -acodec copy \"%a.aac\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Linux<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in *.mp4; do ffmpeg -i \"$i\" -vn -acodec copy \"${i%.*}.aac\"; done<\/pre>\n\n\n\n<p>Split audio file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ffmpeg -i 2024-07-27_20_38_2.m4a -f segment -segment_time 1740 output_%03d.m4a<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Converting MKV to MP4<\/h3>\n\n\n\n<p>Here is a case where my MKV file contains the audio in AAC, and the video in H264, As you slide the slider in VLC media player, it tells you what the section is about, i should be able to copy the streams exactly as they are, but I was concerned that the &#8220;Slider Hints&#8221; would disappear, hence I split it into audio and video without re-encoding, checked that the hints are still there in the video, then combined them into an MP4, also without encoding, the reason I wanted the container to be MP4 is that sometimes I access my network files in a browser, and browsers seem more comfortable playing MP4 files than MKV<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">* ffmpeg -i My_Dinner_With_Andre_1981.mkv -vn -acodec copy ao.aac<br>* ffmpeg -i My_Dinner_With_Andre_1981.mkv -an -c:v copy vo.mp4<br>* ffmpeg -i ao.aac -i vo.mp4 -c:v copy -c:a copy My_Dinner_With_Andre_1981.mp4<\/pre>\n\n\n\n<p>3D printing<\/p>\n\n\n\n<p>When i 3D print a part, I usually want it to be 10X faster, with good compression and no audio, I also want the idle time at the end of the video cropped, here is the command to do tat<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ffmpeg -i 20240927_145610.mp4 \\<br>-t 00:12:24 \\<br>-vf \"select='not(mod(n,5))',setpts=N\/FRAME_RATE\/TB,scale=1280:-1\" \\<br>-an -c:v libx265 -crf 30 -preset slow 20240927_145610_5x.mp4<\/pre>\n\n\n\n<p><code>-t 00:12:24<\/code> \u2192 stops processing after 1 hour 2 minutes of input (62 minutes\/5).<br>select=&#8217;not(mod(n,10))&#8217; \u2192 keep 1 out of every 10 frames \u2192 10\u00d7 speedup.<br>setpts=N\/FRAME_RATE\/TB \u2192 adjust timestamps so playback is fast, not choppy in duration.<br>scale=1280:-1 \u2192 shrink to 1280 px width, preserving aspect ratio.<br>-an \u2192 remove audio.<br>-c:v libx265 \u2192 H.265 video codec (much smaller than H.264 for the same quality).<br>-crf 30 \u2192 aggressive compression (higher = smaller file, lower quality).<br>-preset slow \u2192 better compression efficiency (slower encode).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Combine video and audio (yt-dlp) First of all, after using yt-dlp to download 2 webm files for a video, you can combine them without reencoding using the following command (See here), Just make sure both files are VP8 or VP9 ffmpeg -i ao.webm -i vo.webm -c:v copy -c:a copy output.webm Extract segment from video To [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137,6],"tags":[],"class_list":["post-1825","post","type-post","status-publish","format-standard","hentry","category-ffmpeg","category-multimedia"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=1825"}],"version-history":[{"count":27,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1825\/revisions"}],"predecessor-version":[{"id":5626,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/1825\/revisions\/5626"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=1825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=1825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=1825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}