dt.iki.fi

FFmpeg Tips and Tricks

Cut a video without re-encoding...-up-

...at keyframes only (forsaking time accuracy), and without messing up timestamps:

ffmpeg -noaccurate_seek -ss [START_TIME] -i [INPUT] -t [DURATION] -c copy -avoid_negative_ts make_zero [OUTPUT]

As always with ffmpeg, the order of the options is relevant. Either -ss [START_TIME] or -t [DURATION] can be omitted.

"Fix bad video"-up-

I'm posting this reluctantly because I cannot well explain the problem, and I'm sure there's better ways to a) define a problem, then b) fix it specifically. This is a bit of a sledgehammer fix, but it works well enough.
Anyhow, sometimes a "bad" video file will play OK, but searching or skipping is impossible. In this case it can help to convert it to an uncompressed raw format like ffvhuff:

ffmpeg -i bad_video.ext -c:v ffvhuff -c:a copy good_video.mkv

For some reason I had to choose MKV as output format.

This will take orders of magnitude more space then compressed video, but now you can convert it back to something compressed, and it won't be "broken" anymore.

I did not convert the audio here; the ffmpeg wiki has this to say about audio formats, and this SO Q&A has a few more examples.

Configuration?-up-

I could not find out if it's possible to make ffmpeg read some configuration options. It respects a number of envrionment variables, but again, I could not find documentation for this anywhere.

Anyhow, one thing I really do not need is ffmpeg's huge "banner" listing compile options, so I'll at least add an alias to my shell's rc:

alias ffmpeg='ffmpeg -hide_banner'

Online documentation-up-