ret;

Random ffmpeg quirks and flags

Just leaving my findings here so I don't forget about them. They are not necessarily useful.


CUDA NVENC shenanigans

If you are trying to use h264_nvenc or hevc_nvenc and you get an error like No NVENC capable device found!, make sure you don't have a 10-bit color or higher video. NVENC does not like them at all.
If your source video is in 10-bit color, you can use -pix_fmt yuv420p or a similar flag to change the target pixel format to an 8-bit color one.

Remove metadata

You can remove almost all metadata from a file with -map_metadata -1.

Extract subtitles from mkv

If there are embedded subrip subtitles in a video and you need to extract them, you can simply map them -map 0:s[:index] and use -c:s subrip as the codec (or simply name the output file with a .srt extension).

Render embedded dvdsub subtitles

They will look like crap. Not much we can do.

First make sure to use -probesize 100M -analyzeduration 120M in order to not have any problems later. That makes ffmpeg take into account more data when doing things, or at least that is what I understand.
Secondly, we will use some complex filters. We will scale the subtitle stream to the video dimensions with the scale filter and overlay it with a video stream. The scale is needed for it to work consistently. There is also a canvas size flag but it did not work in my experiments. Note that you can use multiple subtitle streams and crop them/reposition them, but that goes beyond this scope. I haven't really needed to investigate that (yet).
Lastly we just map the output of the filters, the audio, and we are done. A quick example for a 360p video, selecting the second subtitle stream (ffmpeg is 0-indexed):

-filter_complex "[0:s:1]scale=640x360[a];[0:v][a]overlay[x]" -map "[x]" -map 0:a 

Technically you can skip typing the "[x]" at the end of the filter and it will auto-map, but it is better to be implicit. And it didn't go well in my experiments.

Normalize audio

Just use loudnorm as an audio filter. Default parameters are fine, but you can tweak them according to the documentation.

Create transparent gif from list of png images

Optimized from Quin Benson

ffmpeg -framerate 6 -i %d.png -filter_complex  "split=2[palette_in][gif];[palette_in]palettegen[palette_out];[gif][palette_out]paletteuse" out.gif
Pseudorestart git history without losing commits

git rebase -i --root.

That's it. Now edit everything.

Found at this issue.