ffmpeg


ffmpeg Commonly Used Commands

Trimming Files Without Re-encoding

The following steps is how I trim recorded Zwift rides and/or races. I aim to eliminate the setup at the beginning and the teardown at the end without having to re-encode the video as that’s an expensive process. Using the nearest key frame allows skipping the re-encode and I do it in two separate steps to avoid math caused by the initial seek changing the end time of the video.

The previous versions of these commands used -c:v copy -c:a copy the new version uses -c copy -map 0 as my recording setup now records two audio tracks and without the -map 0 the second audio track is discarded.

Trim Beginning to Nearest Key Frame

Look at the output video to ensure it starts approximately where you want.

ffmpeg -ss hh:mm:ss -i input.mkv -c copy -map 0 beginning.mkv

Trim End to Nearest Key Frame

ffmpeg -i beginning.mkv -t hh:mm:ss -c copy -map 0 trimmed.mkv

Convert from 60 FPS to 30 FPS

ffmpeg -i input.mkv -c:v h264_qsv -filter:v fps=fps=30 -c:a copy output.mkv

This utilizes the h264_qsv Intel Quick Sync Video acceleration hardware. I haven’t figured out a way to get rid of the following extra video metadata components:

Standard        : Component
Writing library : Lavc61.19.101 h264_qsv

Worthless extra metadata as far as I can tell.

Concatenate Multiple MKV Files

Originally from this Stack Overflow Answer

for i in input[12].mkv; do
    printf "file '%s'\n" "$i"
done > concat.txt
ffmpeg -f concat -i concat.txt -c copy -map 0 output.mkv && rm concat.txt