FFmpeg Tips and Tricks
Table of Contents
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.
-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
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 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'