FFmpeg Tips and Tricks
Table of Contents
Cut a video without re-encoding...
...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.
Encode to 8 bit unsigned PCM WAV Mono
Typically used for game sounds. I had difficulties using the aformat filter, but this syntax worked:
ffmpeg -i speeddown.wav -af "areverse" -ar 22050 -acodec pcm_u8 -ac 1 speedup.wav
It reverses an existing audio snippet.
It would be nice if
ffmpeg had an option to transcode a file, but use the same format as the input.
"Fix bad video"
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 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.
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'
- The Arch wiki has an article with some information.
- ffmpeg has its own documentation and wiki.