Creating a video from a single image for a specific duration in ffmpeg

83,151

Solution 1

ffmpeg -loop 1 -i image.png -c:v libx264 -t 15 -pix_fmt yuv420p -vf scale=320:240 out.mp4
  • The -t 15 makes it 15 seconds long.
  • The -vf scale=320:240 sets the width/height.

Make sure to use the latest ffmpeg version e.g. http://johnvansickle.com/ffmpeg/

Solution 2

Found this to be faster:

ffmpeg -framerate 1/10 -i DJI_0024.JPG -c:v libx264 -t 10 -pix_fmt yuv420p -vf scale=320:240 out.mp4

-t 10 making the video 10 seconds long, and setting -framerate 1/10. Divisor of framerate should be same number as the argument to -t. This made a jpeg with large resolution to be converted to a video in less then a second for me, while the other answer took about 40 sec. Also resulting filesize became slightly smaller. from 3.38MB to 3.17MB

Share:
83,151
Dharmesh
Author by

Dharmesh

Updated on August 22, 2021

Comments

  • Dharmesh
    Dharmesh almost 3 years

    How do I generate a movie using ffmpeg using a single image (image1.png) for a duration of 15 seconds with a specific resolution so when I play the video, the image will appear on screen for 15 seconds.

  • Agey
    Agey about 9 years
    Unable to find a suitable output format for 'scale=1280:1024' scale=1280:1024: Invalid argument Any idea why?
  • user1319182
    user1319182 about 8 years
    @Equanox I've had the same issue, but it was caused by the "\" sign when copying and pasting. Removing it solves the issue.
  • Semi
    Semi over 7 years
    When I try to run this, I get an error: Option loop not found - I'm using ffmpeg version 2.8.4 on windows
  • Yan King Yin
    Yan King Yin over 7 years
    It works when I removed -c:v libx264 -- it complains not finding the library.
  • Arpan Dixit
    Arpan Dixit over 7 years
    while using jpeg image it takes a lot of time to execute in android. how can i solve this?
  • andreas
    andreas over 6 years
    @YanKingYin the libx264 is a non GPL library, which might be missing. If you want to install it, you can do so (on mac using mac ports) by: 'port install ffmpeg +nonfree'
  • joey
    joey about 6 years
    It answers the question, but I don't like the use of all those redundant additions in the command.
  • Doe Johnson
    Doe Johnson over 5 years
    @joey Me neither, especially because OP did not ask for anything specific. You want to make a video from a single pic and don't care about any details at all? ffmpeg -loop 1 -i image.png -t 5 out.mp4
  • WhiteHorse
    WhiteHorse about 4 years
    Perfect. Worked
  • HunterZ
    HunterZ about 4 years
    This is great, but...it takes forever and melts my CPU to generate a 40 minute video based on a single 720p PNG image. Is there a way to speed it up? Compression doesn't matter as long as it stays under a couple GB.
  • tobek
    tobek over 3 years
    Note that if you need to specify the framerate (e.g. you want to concat this with existing video and need them to match) you can add e.g. -r 30 before output to specify 30 FPS
  • RealZombs
    RealZombs over 3 years
    @DoeJohnson YEAH, much simpler command. I think FFmpeg is smart enough to figure out the basics
  • Radical Edward
    Radical Edward over 2 years
    -loop 1 is necessary, otherwise it won't work