'FFMPEG - concat demuxer with duration filter issue
I am trying to generate video from images using ffmpeg concat demuxer.I am creating a text file with image file path. Since images can be of different duration, i am using duration filter to specify the duration of each image. Sample text file is like :
file 1.jpg
duration 3
file 2.jpg
duration 3
file 3.jpg
duration 5
1.jpg and 2.jpg both are displayed for specified 3 sec each but 3.jpg comes for just 2 seconds.
FFMPEG command:
ffmpeg -f concat -i D:/textfile.txt -y -r 10 -crf 22 -threads 2 -preset veryfast D:/video.mp4
Solution 1:[1]
My usage
I'm facing a similar issue with different ffmpeg command options to concat a list of JPG images to an MP4 video.
FFmpeg version:
ffmpeg version 5.0.1-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.2.0 (Rev7, Built by MSYS2 project)
Command:
ffmpeg -f concat -i "input.txt" -c:v libx264 -r 30 -pix_fmt yuv420p "output.mp4"
input.txt:
file '1.jpg'
duration 5
file '2.jpg'
duration 5
Reference: https://shotstack.io/learn/use-ffmpeg-to-convert-images-to-video/
The problem I'm facing
The resulting video only shows the 1st image for 5 seconds, but at the end of the video, I can see like a frame of the 2nd image.
From what I have tested so far, the issue only happens when I have 1 or 2 images. For 3 or more images, I get the expected result. For 3 images and duration 5 applied to all 3 files, the output duration is 14.967000 seconds (close to the expected duration of 15 seconds).
Findings
I can see from the below FFmpeg defect ticket that this is a known bug in the concat demuxer.
https://trac.ffmpeg.org/ticket/6128
Resolution
Whoever getting such kind of weird issues, no matter it's a misuse or bug, I think all we can do before it gets fixed in a future release is that, we need to do some hacks.
As Gyan commented below the question, you need to add one more file to the end of the input text file.
I tried but I'm not able to get the expected duration just like what OP replied Gyan.
Then for me, I'll just make the input file like this to just convert images to videos one by one:
file '1.jpg'
duration 5
file '1.jpg'
I get an output duration of 5.034000 seconds.
Then I'll just repeat the same process for the 2nd image, and concat the 2 videos with another ffmpeg command.
ffmpeg -safe 0 -f concat -i "concat_input.txt" -c copy "output.mp4"
concat_input.txt:
file '1.mp4'
file '2.mp4'
The output duration is 10.068000, very close to what I'm expecting.
Other info
The command to check video duration is:
ffprobe output.mp4 -show_entries format=duration -v 0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | blackr1234 |
