DEV Community

Benji 🍙
Benji 🍙

Posted on

TIL you can convert media file extensions with ffmpeg

You can convert a video clips file extension using ffmpeg like this:

$ ffmpeg -i chill.mp4 chill.wav
$ ll
-rw-r--r--  1 hello  world  84317363 21 Jun  2022 chill.mp4
-rw-r--r--  1 hello  world  49074254 28 May 13:13 chill.wav
Enter fullscreen mode Exit fullscreen mode

You can also play directly from the terminal (which opens in a new window)

$ ffplay chill.mp4
Enter fullscreen mode Exit fullscreen mode

Streaming a video file using ffplay

And probably the most useful I found, which is to convert a video clip to a .gif for PRs/MRs

ffmpeg -i in.mov -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
Enter fullscreen mode Exit fullscreen mode

Notes on the arguments:

  • -r 10 tells ffmpeg to reduce the frame rate from 25 fps to 10
  • -s 600x400 tells ffmpeg the max-width and max-height
  • --delay=3 tells gifsicle to delay 30ms between each gif
  • --optimize=3 requests that gifsicle use the slowest/most file-size optimization

(full credits for this one go to this README.md)

Top comments (1)

Collapse
 
Sloan, the sloth mascot
Comment deleted