1

I'm trying to create a video file, either .mp4 or .mov, that has a specific length, for example 59 hours. It doesn't matter what's inside the video, it can be just blank. I found this command:

ffmpeg -loop 1 -i image.png -c:v libx264 -t 15 -pix_fmt yuv420p -vf scale=320:240 out.mp4

Which takes an images and creates a fixed-length video from that image. It works, but it takes a long time to do that. Are there any other ways one can create blank videos of fixed length that doesn't take long to make?

2

If you don't have specific requirements in terms of video codec settings, you can generate the video based on one black frame (see color source):

ffmpeg -f lavfi -i color=black:duration=60:size=320x240:r=1 -c:v libx264 out.mp4

We're using one frame per second (r=1), but you can go even lower (e.g. r=0.01) to encode only one frame for 60 seconds, and nothing else.

Another method suggested by Gyan should be much faster:

ffmpeg -f lavfi -i color=black:size=320x240 -vf trim=end_frame=2,setpts=N*59*3600/TB -c:v libx264 -vsync 0 -video_track_timescale 100 out.mp4

Here:

  • trim=end_frame=2 removes everything but the first two frames
  • setpts=N*59*3600/TB sets the timestamp of the first frame to 0, and the second one to 59 hours (59 × 3600 seconds), divided by a constant (TB)
  • -vsync 0 makes ffmpeg use these timestamps as-is without forcing a specific framerate (otherwise you'd get duplicated frames)
  • -video_track_timescale sets the time base (TB) to 100, which is required since otherwise the generated PTS numbers would be too large
3
  • Suggest ffmpeg -f lavfi -i color=black:size=320x240 -vf trim=end_frame=2,setpts=N*59*3600/TB -c:v libx264 -vsync 0 -video_track_timescale 100 out.mp4
    – Gyan
    Jan 7 '20 at 10:51
  • Good suggestion, I added it and explained what it means.
    – slhck
    Jan 7 '20 at 11:06
  • I prefer the vsync strings over numbers as it is less cryptic: -vsync passthrough. Using r in color instead of -r would be faster as it would avoid 25 to 1 conversion.
    – llogan
    Jan 7 '20 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.