{ "created": "2021-05-16T05:25:33Z", "hierarchy": [ { "name": "ROOT", "type": "folder", "uri": "/ROOT" }, { "name": "FFMpeg Cheatsheet", "type": "article", "uri": "FFMpeg_Cheatsheet" } ], "html": "\n\n \n \n \n \n\n \n \n\n \n \n \n \n \n\n FFMpeg Cheatsheet\n\n \n \n \n \n
\n
\n \n
\n
\n \n \n\n\n

FFMpeg Cheatsheet

\n\n

Source

\n
\n

A list of useful commands for the ffmpeg command line tool.

\n

Download FFmpeg: https://www.ffmpeg.org/download.html

\n

Full documentation: https://www.ffmpeg.org/ffmpeg.html

\n

Basic conversion

\n
ffmpeg -i in.mp4 out.avi\n
\n

Remux an MKV file into MP4

\n
ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n
\n

High-quality encoding

\n

Use the crf (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to -crf 18. Use the preset parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264

\n
ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n
\n

Trimming

\n

Without re-encoding:

\n
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n
\n\n

With re-encoding:

\n

If you leave out the -c copy option, ffmpeg will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the x264 Encoding Guide and the AAC Encoding Guide, respectively.

\n

For example:

\n
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n
\n

Mux video and audio from another video

\n

To copy the video from in0.mp4 and audio from in1.mp4:

\n
ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n
\n\n

Concat demuxer

\n

First, make a text file.

\n
file 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n
\n

Then, run ffmpeg:

\n
ffmpeg -f concat -i list.txt -c copy out.mp4\n
\n

Delay audio/video

\n

Delay video by 3.84 seconds:

\n
ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n
\n

Delay audio by 3.84 seconds:

\n
ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n
\n

Burn subtitles

\n

Use the libass library (make sure your ffmpeg install has the library in the configuration --enable-libass).

\n

First convert the subtitles to .ass format:

\n
ffmpeg -i sub.srt sub.ass\n
\n

Then add them using a video filter:

\n
ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n
\n

Extract the frames from a video

\n

To extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:

\n
ffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n
\n

To extract one frame per second only:

\n
ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n
\n

Rotate a video

\n

Rotate 90 clockwise:

\n
ffmpeg -i in.mov -vf "transpose=1" out.mov\n
\n

For the transpose parameter you can pass:

\n
0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n
\n

Use -vf "transpose=2,transpose=2" for 180 degrees.

\n

Download “Transport Stream” video streams

\n
    \n
  1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8
  2. \n
  3. Download and concatenate the video fragments:
  4. \n
\n
ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4\n
\n

If you get a “Protocol ‘https not on whitelist ‘file,crypto’!” error, add the protocol_whitelist option:

\n
ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4\n
\n

Mute some of the audio

\n

To replace the first 90 seconds of audio with silence:

\n
ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='lte(t,90)':volume=0" out.mp4\n
\n

To replace all audio between 1'20" and 1'30" with silence:

\n
ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,80,90)':volume=0" out.mp4\n
\n

Deinterlace

\n

Deinterlacing using “yet another deinterlacing filter”.

\n
ffmpeg -i in.mp4 -vf yadif out.mp4\n
\n

Create a video slideshow from images

\n

Parameters: -r marks the image framerate (inverse time of each image); -vf fps=25 marks the true framerate of the output.

\n
ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n
\n

Extract images from a video

\n\n

Metadata: Change the title

\n
ffmpeg -i in.mp4 -map_metadata -1 -metadata title="My Title" -c:v copy -c:a copy out.mp4\n
\n

With yt-dlp, make a clip of a video

\n

-ss is the start time, and -s is the duration. More info here.

\n
yt-dlp \\\n  -f 18 \\\n  --external-downloader ffmpeg \\\n  --external-downloader-args "ffmpeg_i:-ss 00:04:56.00 -t 00:00:5.00" \\\n  "https://www.youtube.com/watch?v=-5ZIQ0bDlU8"\n
\n\n\n
\n \n
\n \n \n \n \n \n\n", "id": "836f0dd7-82fa-5066-8f9d-6dd15ce8c581", "modified": "2022-07-21T21:45:17Z", "revisions": [ { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2022-07-21T21:45:17Z", "id": "9c173ad952347489d57b1d41540f6f09c3c2edae", "shortId": "9c173ad9", "subject": "Add note on clipping YT video\n", "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```\nyt-dlp \\\n -f 18 \\\n --external-downloader ffmpeg \\\n --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 00:00:5.00\" \\\n \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n```\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2022-06-13T23:23:48Z", "id": "6be928c4c8de048934c03e3c61539c9ceec7d59a", "shortId": "6be928c4", "subject": "Update config.yml", "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n" }, { "authorEmail": "mail@nikhil.io", "authorName": "Nikhil Anand", "date": "2021-05-16T05:25:33Z", "id": "fc610aee9039090a162daf5cf7f27b96ca20099f", "shortId": "fc610aee", "subject": "Create FFMpeg Cheatsheet.md", "content": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n" } ], "sizeInBytes": 6069, "source": "[Source](https://gist.github.com/steven2358/ba153c642fe2bb1e47485962df07c730)\n\n---\n\nA list of useful commands for the ffmpeg command line tool.\n\nDownload FFmpeg: https://www.ffmpeg.org/download.html\n\nFull documentation: https://www.ffmpeg.org/ffmpeg.html\n\n## Basic conversion\n\n````\nffmpeg -i in.mp4 out.avi\n````\n\n### Remux an MKV file into MP4\n\n````\nffmpeg -i in.mkv -c:v copy -c:a copy out.mp4\n````\n\n### High-quality encoding\n\nUse the `crf` (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to `-crf 18`. Use the `preset` parameter to control the speed of the compression process. Additional info: https://trac.ffmpeg.org/wiki/Encode/H.264\n\n````\nffmpeg -i in.mp4 -preset slower -crf 18 out.mp4\n````\n\n## Trimming\n\nWithout re-encoding:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4\n````\n- [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)\n- [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).\n- Recent `ffmpeg` also has a flag to supply the end time with `-to`.\n- [`-c`](http://ffmpeg.org/ffmpeg-all.html#Main-options) copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.\n\nWith re-encoding:\n\nIf you leave out the `-c copy` option, `ffmpeg` will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the [x264 Encoding Guide](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.\n\nFor example:\n````\nffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4\n````\n\n## Mux video and audio from another video\n\nTo copy the video from in0.mp4 and audio from in1.mp4:\n````\nffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4\n````\n- With [-c copy](http://ffmpeg.org/ffmpeg.html#Stream-copy) the streams will be `stream copied`, not re-encoded, so there will be no quality loss. If you want to re-encode, see [FFmpeg Wiki: H.264 Encoding Guide](https://trac.ffmpeg.org/wiki/Encode/H.264).\n- The `-shortest` option will cause the output duration to match the duration of the shortest input stream.\n- See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.\n\n\n## Concat demuxer\n\nFirst, make a text file.\n````\nfile 'in1.mp4'\nfile 'in2.mp4'\nfile 'in3.mp4'\nfile 'in4.mp4'\n````\nThen, run `ffmpeg`:\n````\nffmpeg -f concat -i list.txt -c copy out.mp4\n````\n\n## Delay audio/video\n\nDelay video by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4\n````\nDelay audio by 3.84 seconds:\n````\nffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4\n````\n\n## Burn subtitles\n\nUse the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).\n\nFirst convert the subtitles to .ass format:\n````\nffmpeg -i sub.srt sub.ass\n````\nThen add them using a video filter:\n\n````\nffmpeg -i in.mp4 -vf ass=sub.ass out.mp4\n````\n\n## Extract the frames from a video\n\nTo extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:\n\n````\nffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png\n````\n\nTo extract one frame per second only:\n\n````\nffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png\n````\n\n## Rotate a video\n\nRotate 90 clockwise:\n\n````\nffmpeg -i in.mov -vf \"transpose=1\" out.mov\n````\n\nFor the transpose parameter you can pass:\n\n````\n0 = 90CounterCLockwise and Vertical Flip (default)\n1 = 90Clockwise\n2 = 90CounterClockwise\n3 = 90Clockwise and Vertical Flip\n````\n\nUse `-vf \"transpose=2,transpose=2\"` for 180 degrees.\n\n## Download \"Transport Stream\" video streams\n\n1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8\n2. Download and concatenate the video fragments:\n\n````\nffmpeg -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\nIf you get a \"Protocol 'https not on whitelist 'file,crypto'!\" error, add the `protocol_whitelist` option:\n\n````\nffmpeg -protocol_whitelist \"file,http,https,tcp,tls\" -i \"path_to_playlist.m3u8\" -c copy -bsf:a aac_adtstoasc out.mp4\n````\n\n## Mute some of the audio\n\nTo replace the first 90 seconds of audio with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='lte(t,90)':volume=0\" out.mp4\n````\n\nTo replace all audio between 1'20\" and 1'30\" with silence:\n\n````\nffmpeg -i in.mp4 -vcodec copy -af \"volume=enable='between(t,80,90)':volume=0\" out.mp4\n````\n\n## Deinterlace\n\nDeinterlacing using \"yet another deinterlacing filter\".\n\n````\nffmpeg -i in.mp4 -vf yadif out.mp4\n````\n\n## Create a video slideshow from images\n\nParameters: `-r` marks the image framerate (inverse time of each image); `-vf fps=25` marks the true framerate of the output.\n\n````\nffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4\n````\n\n## Extract images from a video\n\n- Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`\n- Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`\n- Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`\n\n## Metadata: Change the title\n\n````\nffmpeg -i in.mp4 -map_metadata -1 -metadata title=\"My Title\" -c:v copy -c:a copy out.mp4\n````\n\n## With `yt-dlp`, make a clip of a video\n\n`-ss` is the start time, and `-s` is the duration. More info [here](https://old.reddit.com/r/youtubedl/wiki/howdoidownloadpartsofavideo).\n\n```\nyt-dlp \\\n -f 18 \\\n --external-downloader ffmpeg \\\n --external-downloader-args \"ffmpeg_i:-ss 00:04:56.00 -t 00:00:5.00\" \\\n \"https://www.youtube.com/watch?v=-5ZIQ0bDlU8\"\n```\n", "title": "FFMpeg Cheatsheet", "untracked": false, "uri": "/FFMpeg_Cheatsheet" }