Using ffmpeg for beginners in everything

Anya Name
2 min readMar 3, 2020

I write this mostly for myself. Instead of keeping some notes in notepad why not post it online, right? I’ve been learning Processing language and had a need to create videos from my sketches. Here are some tips:

Install ffmpeg on PC:

  1. Download ffmpeg
  2. Unzip it to desired folder (In my case its D://tools/)
  3. Add this folder to PATH variables. The steps
  • From the desktop, right click the Computer icon.
  • Choose Properties from the context menu.
  • Click the Advanced system settings link.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value ofPATHenvironment variable. Click OK. Close all remaining windows by clicking OK.

Create video from frames:

1. Open folder with frames

2. Open command line from that folder (Shift+Right click)

3. Print set command to the command line to make sure your PATH variable is updated. I had an issue that updated variable was displayed from C drive, but from my frames folder it was not. Internet told me that I only need to close all command line instances and restart them but it did not help. Restarting the computer helped.

I had to experiment with parameters to find what I really need. Sometimes it would make good video but it could not be saved to iPhone which was one of my requirements. So I will just put a result here:

ffmpeg -framerate 60 -i %06d.png  -pix_fmt yuv420p out.mp4
  • -framerate 30 self-explanatory, frame rate
  • -i %06d.png this defines input frames and the mask for their names. The number means number of symbols in the filename. This corresponds to Processing code:
saveFrame(“/frames/######.png”);
  • -pix_fmt yuv420p format that allows video to be saved to iPhone
  • if video should start from specific frame number:
ffmpeg -start_number 0151 -i %4d.png out.mov
  • if video should take frames in reverse order
ffmpeg -start_number 0151  -i %4d.png -vf reverse out.mov
  • if you need to concatenate several videos
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mov

Where files.txt is file with list of files to concatenate:

file 'out1.mov'
file 'out2.mov'

To speed up and convert the video:

ffmpeg -i in.webm -preset veryfast -filter:v “setpts=0.5*PTS” out.mov

To convert from video to gif:

  1. Run this command to generate palette:
ffmpeg -y -i foo.mp4 -vf fps=30,scale=320:-1:flags=lanczos,palettegen palette.png

2. Run this command to convert the mov (or other) file into gif:

ffmpeg -y -i pink2.mov -i palette.png -filter_complex “fps=30,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse” pink2_2.gif

This is a reminder for myself, but it might help somebody as well

P.S. to speed up and convert the video:

ffmpeg -i in.webm -preset veryfast -filter:v "setpts=0.5*PTS" out.mov

--

--