Martin
Martin

Reputation: 1582

ffmpeg set output resolution by resizing image

I'm trying to use ffmpeg for rendering video where an audio file and image are taken as inputs, and turned into a video (basically a music video) with the audio file playing for the duration of the video.

My current working command:

ffmpeg -loop 1 -framerate 2 -i "front.png" -i "testWAVfile.wav" -vf "scale=2*trunc(iw/2):2*trunc(ih/2),setsar=1,format=yuv420p" -c:v libx264 -preset medium -tune stillimage -crf 18 -c:a aac -shortest -vf scale=1920:1080  "outputVideo.mp4"

Will set the output resolution of the video to whatever the resolution of the image is. Is there a way I can resize the image to enlarge it by a couple multiplications so that the output video resolution will be higher?

Like if my front.png image was 800x800 pixels, I could add something to my ffmpeg command to triple the resolution, so that the output video resolution is 2400x2400?

Upvotes: 1

Views: 6947

Answers (2)

llogan
llogan

Reputation: 134173

The simplest method is to use scale=iw*3:-1.

However, since using libx264 with yuv420p requires width x height to be divisible by 2 use scale=2*trunc(iw/2*3):-2.

Or just declare the size you want: scale=2400:-1

Example:

ffmpeg -loop 1 -framerate 2 -i "front.png" -i "testWAVfile.wav" -vf "scale=2*trunc(iw/2*3):-2,setsar=1,format=yuv420p" -c:v libx264 -preset medium -tune stillimage -crf 18 -c:a aac -shortest "outputVideo.mp4"
  • See scale filter and expression documentation for more info.
  • Note that you should only use one -vf at a time as the other will be ignored.
  • Upscaling is not recommended if you can avoid it. There quality will not be better as the additional information is simply interpolated.
  • Many players won't like a frame rate of 2, so consider increasing it to 6 or more if you need full compatibility. If you're just uploading to YouTube then don't worry about it as it should be able to handle it.

Upvotes: 3

mail2subhajit
mail2subhajit

Reputation: 1150

Scale the image front.png using the ffmpeg cmd

ffmpeg -i front.png -vf scale=2400:2400 output_2400x2400.png

use the output of this cmd (output_2400x2400.png as input image) in your working video generating cmd

-vf scale=2400:2400

Upvotes: 1

Related Questions