Konubinix' opinionated web of thoughts

Ffmpeg

Fleeting

subtitle encoding currently only possible from text to text or bitmap to bitmap

Change the format or the subtitle codec

ffmpeg -i input output.newformat

or

ffmpeg -i input -scodec webvtt output.newformat

speed up/slow down a video

This does not affect the audio speed. Use -an to not include audio in the output

https://superuser.com/questions/1261678/how-do-i-speed-up-a-video-by-60x-in-ffmpeg

ffmpeg -i input.mkv -filter:v “setpts=PTS/60” output.mkv

https://superuser.com/questions/1261678/how-do-i-speed-up-a-video-by-60x-in-ffmpeg

To double the speed of the video with the setpts filter, you can use:

ffmpeg -i input.mkv -filter:v “setpts=0.5*PTS” output.mkv

https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

faster method, but which can have unexpected results with audio (pauses or async):

ffmpeg -itsscale 0.01666 -i input.mkv -c copy output.mkv

https://superuser.com/questions/1261678/how-do-i-speed-up-a-video-by-60x-in-ffmpeg

re-encode i.e. a timelapse, e.g. ffmpeg -i input -vf framestep=60,setpts=N/30/TB -r 30 -an out.mp4

https://superuser.com/questions/1261678/how-do-i-speed-up-a-video-by-60x-in-ffmpeg

encode VP8

there’s a constant quality mode (like in the x264 encoder) that will ensure that every frame gets the number of bits it deserves to achieve a certain quality level, rather than forcing the stream to have an average bit rate. This results in better overall quality and should be your method of choice when you encode video with libvpx.

https://trac.ffmpeg.org/wiki/Encode/VP8

this case, the target bitrate becomes the maximum allowed bitrate. You enable the constant quality mode with the CRF parameter:

ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webm

https://trac.ffmpeg.org/wiki/Encode/VP8

By default the CRF value can be from 4–63, and 10 is a good starting point. Lower values mean better quality.

https://trac.ffmpeg.org/wiki/Encode/VP8

Important: If neither -b:v nor -crf are set, the encoder will use a low default bitrate and your result will probably look very bad. Always supply one of these options—ideally both.

If you want to tweak the quality even further, you can set two more parameters:

-qmin – the minimum quantizer (default 4, range 0–63) -qmax – the maximum quantizer (default 63, range qmin–63)

These Q values are quantization parameters, and lower generally means “better quality”. If you set the bounds from 0 to 63, this means the encoder has free choice of how to assign the quality. For a better overall quality, you can try to set -qmin to 0 and -qmax to 50 or lower. For example:

ffmpeg -i input.mp4 -c:v libvpx -qmin 0 -qmax 50 -crf 5 -b:v 1M -c:a libvorbis output.webm

https://trac.ffmpeg.org/wiki/Encode/VP8

should use constant bitrate encoding if you need your video files to have a certain size, or if you’re streaming the videos over a channel that only allows a certain bit rate.

https://trac.ffmpeg.org/wiki/Encode/VP8

subtitles

set subtitles track as default

setting metadata in subtitles (like the language in english)

add a bunch of subtitles in a file stored in ipfs

ffmpeg add a bunch of subtitles in a file stored in ipfs Using

while read filename srt
do
    echo "$srt -> $filename"
    ffmpeg -nostdin -y -hide_banner -loglevel warning -stats -i $filename -i $srt -vcodec copy -acodec copy -map 0:a:0 -map 1:s:0 -metadata:s:s:0 language=eng -map 0:v:0 -disposition:s:0 default $srt.webm
done < data.txt

In short,

  1. take the videos and the subtitles put in data.txt,
  2. get the video and audio from the file and the subtitle from the subtitle file,
  3. set the subtitle as shown by default,
  4. tell that it is in English,

making mp4 videos streamable

Fast start Flag: -movflags +faststart. Moves some data to the beginning of the file, allowing the video to be played before it is completely downloaded

https://gist.github.com/jaydenseric/220c785d6289bcfd7366

more silent, quiet, less verbose

make ffmpeg more silent (less verbose)

-hide_banner -loglevel warning -stats

What are reasonable values for -aq when creating mp3?

crop a video

ffmpeg -y -i output_video.mp4 -filter:v “crop=500:200:130:100” a.mp4

set the creation time (for my timelapses)

ffmpeg -i a.mp4 -y -metadata creation_time=2024-12-07T08:12:49 -c copy b.mp4

keeping quality during conversion

  • qmin integer (encoding,video) Set min video quantizer scale (VBR). Must be included between -1 and 69, default value is 2.
  • qmax integer (encoding,video) Set max video quantizer scale (VBR). Must be included between -1 and 1024, default value is 31.

https://ffmpeg.org/ffmpeg-codecs.html

Notes pointant ici