ffmpeg tips and tricks
Extracting a piece of a file
Copies a piece of the input file starting at time 00:01:00 up to 00:11:00, while maintaining its codecs. It can be done with -to where we specify the end time, or with -t where we specify the duration.
ffmpeg -i input.mp4 -ss 00:01:00.000 -to 00:11:00.000 -acodec copy -vcodec copy output.mp4 ffmpeg -i input.mp4 -ss 00:01:00.000 -t 10 -acodec copy -vcodec copy output.mp4
Properly Convert 4:3 to 16:9 stripping black bars.
Compress a 4:3 TS file with black bars on the sides, scaling to 16:9 aspect to a specific resolution, and cropping out the black bars (88 pixels wide).
ffmpeg -i input.ts -aspect 16:9 -vf "crop=in_w-88:in_h,scale=718:404" output.mp4
Fix a file when codec information is corrupt
Set the parameters for ffmpeg to analyze and find out which codec the input file has – very handy when the file is somehow corrupt.
ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -i input.file output.mp4
Syncing unsynced audio/video
Set parameters for ffmpeg to delay audio/video by 10 seconds. This is accomplished by using two inputs which will be delayed by 10 seconds and mapped together in the end. 0:0 and 1:1 means that we map the input file 0 and stream 0 to stream 0 of the output file, and that we map the input file 1 and stream 1 to stream 1 of the output file. We itsoffset on input file 0 to delay its playback by 10 seconds.
ffmpeg -i input.mp4 -itsoffset 10 -i input.mp4 -map 0:0 -map 1:1 -acodec copy -vcodec copy output.mp4
Deinterlacing video
To deinterlace video we can use the “yet another deinterlacing filter” as a video filter passed to ffmpeg. It’s advised to read its documentation to better understand how to use it.
ffmpeg -i input.mp4 -vf yadif output.mp4
Recent Comments