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
ffmpeg -i in.mp4 out.avi
Without re-encoding:
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
-ss
specifies the start time, e.g. 00:01:23.000
or 83
(in seconds)-t
specifies the duration of the clip (same format).ffmpeg
also has a flag to supply the end time with -to
.-c
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 and the AAC Encoding Guide, respectively.
For example:
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4
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
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.-shortest
option will cause the output duration to match the duration of the shortest input stream.-map
option documentation for more info.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 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
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
Use the libass 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
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
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.
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
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
151.101.112.133