Skip to content

Instantly share code, notes, and snippets.

@mannyoii
Forked from steven2358/ffmpeg.md
Created May 4, 2023 16:21
Show Gist options
  • Save mannyoii/1dadd8e71b5aa517fc4f798c84d55b5d to your computer and use it in GitHub Desktop.
Save mannyoii/1dadd8e71b5aa517fc4f798c84d55b5d to your computer and use it in GitHub Desktop.

Revisions

  1. @steven2358 steven2358 revised this gist Nov 25, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -180,6 +180,12 @@ ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
    - Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`
    - Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`

    ## Display the frame number on each frame

    ````
    ffmpeg -i in.mov -vf "drawtext=fontfile=arial.ttf: text=%{n}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000099: fontsize=72" -y out.mov
    ````

    ## Metadata: Change the title

    ````
  2. @steven2358 steven2358 revised this gist Mar 30, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -179,3 +179,9 @@ ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
    - Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`
    - Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`
    - Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`

    ## Metadata: Change the title

    ````
    ffmpeg -i in.mp4 -map_metadata -1 -metadata title="My Title" -c:v copy -c:a copy out.mp4
    ````
  3. @steven2358 steven2358 revised this gist Apr 11, 2020. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,14 @@ ffmpeg -i in.mp4 out.avi
    ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4
    ````

    ### High-quality encoding

    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

    ````
    ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4
    ````

    ## Trimming

    Without re-encoding:
  4. @steven2358 steven2358 revised this gist Dec 3, 2019. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -157,10 +157,17 @@ Deinterlacing using "yet another deinterlacing filter".
    ````
    ffmpeg -i in.mp4 -vf yadif out.mp4
    ````

    ## Create a video slideshow from images

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

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

    ## Extract images from a video

    - Extract all frames: `ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner`
    - Extract a frame each second: `ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner`
    - Extract only one frame: `ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg`
  5. @steven2358 steven2358 revised this gist Jul 12, 2019. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -157,3 +157,10 @@ Deinterlacing using "yet another deinterlacing filter".
    ````
    ffmpeg -i in.mp4 -vf yadif out.mp4
    ````
    ## Create a video slideshow from images

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

    ````
    ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4
    ````
  6. @steven2358 steven2358 revised this gist Jun 28, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -149,3 +149,11 @@ To replace all audio between 1'20" and 1'30" with silence:
    ````
    ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,80,90)':volume=0" out.mp4
    ````

    ## Deinterlace

    Deinterlacing using "yet another deinterlacing filter".

    ````
    ffmpeg -i in.mp4 -vf yadif out.mp4
    ````
  7. @steven2358 steven2358 revised this gist Mar 2, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,9 @@ ffmpeg -i in.mp4 out.avi

    ### Remux an MKV file into MP4

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

    ## Trimming

  8. @steven2358 steven2358 revised this gist Mar 2, 2019. 1 changed file with 17 additions and 22 deletions.
    39 changes: 17 additions & 22 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,22 @@
    FFmpeg cheat sheet
    ===
    # FFmpeg cheat sheet

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

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

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

    Basic conversion
    ---
    ## Basic conversion

    ````
    ffmpeg -i in.mp4 out.avi
    ````

    Trimming
    ---
    ### Remux an MKV file into MP4

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

    ## Trimming

    Without re-encoding:
    ````
    @@ -34,8 +36,8 @@ For example:
    ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4
    ````

    Mux video and audio from another video
    ---
    ## Mux video and audio from another video

    To copy the video from in0.mp4 and audio from in1.mp4:
    ````
    ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4
    @@ -45,8 +47,7 @@ ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4
    - See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.


    Concat demuxer
    ---
    ## Concat demuxer

    First, make a text file.
    ````
    @@ -60,8 +61,7 @@ Then, run `ffmpeg`:
    ffmpeg -f concat -i list.txt -c copy out.mp4
    ````

    Delay audio/video
    ---
    ## Delay audio/video

    Delay video by 3.84 seconds:
    ````
    @@ -72,8 +72,7 @@ Delay audio by 3.84 seconds:
    ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ````

    Burn subtitles
    ---
    ## Burn subtitles

    Use the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).

    @@ -87,8 +86,7 @@ Then add them using a video filter:
    ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4
    ````

    Extract the frames from a video
    ---
    ## Extract the frames from a video

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

    @@ -102,8 +100,7 @@ To extract one frame per second only:
    ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png
    ````

    Rotate a video
    ---
    ## Rotate a video

    Rotate 90 clockwise:

    @@ -122,8 +119,7 @@ For the transpose parameter you can pass:

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

    Download "Transport Stream" video streams
    ---
    ## Download "Transport Stream" video streams

    1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8
    2. Download and concatenate the video fragments:
    @@ -138,8 +134,7 @@ If you get a "Protocol 'https not on whitelist 'file,crypto'!" error, add the `p
    ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
    ````

    Mute some of the audio
    ---
    ## Mute some of the audio

    To replace the first 90 seconds of audio with silence:

  9. @steven2358 steven2358 revised this gist Dec 7, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -146,3 +146,9 @@ To replace the first 90 seconds of audio with silence:
    ````
    ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='lte(t,90)':volume=0" out.mp4
    ````

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

    ````
    ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,80,90)':volume=0" out.mp4
    ````
  10. @steven2358 steven2358 revised this gist Sep 4, 2018. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -65,11 +65,11 @@ Delay audio/video

    Delay video by 3.84 seconds:
    ````
    ffmpeg -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ````
    Delay audio by 3.84 seconds:
    ````
    ffmpeg -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ````

    Burn subtitles
    @@ -137,3 +137,12 @@ If you get a "Protocol 'https not on whitelist 'file,crypto'!" error, add the `p
    ````
    ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
    ````

    Mute some of the audio
    ---

    To replace the first 90 seconds of audio with silence:

    ````
    ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='lte(t,90)':volume=0" out.mp4
    ````
  11. @steven2358 steven2358 revised this gist Aug 20, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -131,3 +131,9 @@ Download "Transport Stream" video streams
    ````
    ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
    ````

    If you get a "Protocol 'https not on whitelist 'file,crypto'!" error, add the `protocol_whitelist` option:

    ````
    ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
    ````
  12. @steven2358 steven2358 revised this gist Aug 13, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -65,11 +65,11 @@ Delay audio/video

    Delay video by 3.84 seconds:
    ````
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ffmpeg -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ````
    Delay audio by 3.84 seconds:
    ````
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ffmpeg -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ````

    Burn subtitles
  13. @steven2358 steven2358 revised this gist Aug 2, 2018. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -121,3 +121,13 @@ For the transpose parameter you can pass:
    ````

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

    Download "Transport Stream" video streams
    ---

    1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8
    2. Download and concatenate the video fragments:

    ````
    ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4
    ````
  14. @steven2358 steven2358 revised this gist Jul 19, 2018. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -101,3 +101,23 @@ To extract one frame per second only:
    ````
    ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png
    ````

    Rotate a video
    ---

    Rotate 90 clockwise:

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

    For the transpose parameter you can pass:

    ````
    0 = 90CounterCLockwise and Vertical Flip (default)
    1 = 90Clockwise
    2 = 90CounterClockwise
    3 = 90Clockwise and Vertical Flip
    ````

    Use `-vf "transpose=2,transpose=2"` for 180 degrees.
  15. @steven2358 steven2358 revised this gist Jun 25, 2018. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -86,3 +86,18 @@ Then add them using a video filter:
    ````
    ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4
    ````

    Extract the frames from a video
    ---

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

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

    To extract one frame per second only:

    ````
    ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png
    ````
  16. @steven2358 steven2358 revised this gist Feb 3, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -65,11 +65,11 @@ Delay audio/video

    Delay video by 3.84 seconds:
    ````
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i "in.mp4" -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ````
    Delay audio by 3.84 seconds:
    ````
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i "in.mp4" -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ````

    Burn subtitles
  17. @steven2358 steven2358 created this gist Feb 3, 2018.
    88 changes: 88 additions & 0 deletions ffmpeg.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    FFmpeg cheat sheet
    ===

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

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

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

    Basic conversion
    ---
    ````
    ffmpeg -i in.mp4 out.avi
    ````

    Trimming
    ---

    Without re-encoding:
    ````
    ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
    ````
    - [`-ss`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the start time, e.g. `00:01:23.000` or `83` (in seconds)
    - [`-t`](http://ffmpeg.org/ffmpeg-all.html#Main-options) specifies the duration of the clip (same format).
    - Recent `ffmpeg` also has a flag to supply the end time with `-to`.
    - [`-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.

    With re-encoding:

    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](https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide) and the [AAC Encoding Guide](http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide), respectively.

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

    Mux video and audio from another video
    ---
    To copy the video from in0.mp4 and audio from in1.mp4:
    ````
    ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4
    ````
    - 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).
    - The `-shortest` option will cause the output duration to match the duration of the shortest input stream.
    - See the [`-map` option documentation](http://ffmpeg.org/ffmpeg.html#Advanced-options) for more info.


    Concat demuxer
    ---

    First, make a text file.
    ````
    file 'in1.mp4'
    file 'in2.mp4'
    file 'in3.mp4'
    file 'in4.mp4'
    ````
    Then, run `ffmpeg`:
    ````
    ffmpeg -f concat -i list.txt -c copy out.mp4
    ````

    Delay audio/video
    ---

    Delay video by 3.84 seconds:
    ````
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i "in.mp4" -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
    ````
    Delay audio by 3.84 seconds:
    ````
    ffmpeg.exe -i "in.mp4" -itsoffset 3.84 -i "in.mp4" -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4
    ````

    Burn subtitles
    ---

    Use the [libass](http://ffmpeg.org/ffmpeg.html#ass) library (make sure your ffmpeg install has the library in the configuration `--enable-libass`).

    First convert the subtitles to .ass format:
    ````
    ffmpeg -i sub.srt sub.ass
    ````
    Then add them using a video filter:

    ````
    ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4
    ````