How to use ffmpeg to scale image AND to specify desired frames per second?
Asked Answered
P

1

9

I am using ffmpeg to convert frames from an mp4 to png images.
I would like 20 frames per second AND I would also like the images to be scaled up to 1920x1080. The original mp4 is 240p (426x240).

It lets me specify 20 fps after the -vf flag, but it doesn't let me scale the images.

ffmpeg -i 240_video.mp4 -vf scale=1920:1080 fps=20 240_scaled/out%d.png

If I leave out scale=1920:1080 the command works, but of course, I get 426x240 images.

Portrait answered 28/3, 2020 at 1:12 Comment(0)
S
15

You can chain linear filters together with commas:

ffmpeg -i 240_video.mp4 -vf "fps=20,scale=1920:1080" 240_scaled/out%d.png
  • If your input has more than 20 fps, then ffmpeg will drop frames to convert to 20 fps. If your input has less than 20 fps, then ffmpeg will duplicate frames to convert to 20 fps. If you want all of the frames as is then omit the fps filter.
  • I used the fps filter first because in this case, assuming your input frame rate is higher than 20 fps, it will be slightly more efficient and faster than scaling first because frames will be dropped before the scale filter.

Many players won't like the output because it won't be 4:2:0, so you can add the format filter:

ffmpeg -i 240_video.mp4 -vf "fps=20,scale=1920:1080,format=yuv420p" 240_scaled/out%d.png

426x240 upscaled while keeping the aspect ratio is actually 1920x1082 or 1917x1080, so add pad or crop to compensate. Or refer to the force_original_aspect_ratio option in scale. setsar is added so you don't get a weird SAR. -movflags +faststart is added in case you are doing progressive playback.

ffmpeg -i 240_video.mp4 -vf "fps=20,scale=1920:-1,crop=1920:1080,setsar=1,format=yuv420p" -movflags +faststart 240_scaled/out%d.png
Sat answered 28/3, 2020 at 1:58 Comment(1)
I recently got a similar question, but I ended up using zoompan: #75056695Aubine

© 2022 - 2024 — McMap. All rights reserved.