Opened 3 years ago
Last modified 6 months ago
#9210 new enhancement
Concat images produces wrong timings when duration is in milliseconds
Reported by: | demet64 | Owned by: | |
---|---|---|---|
Priority: | wish | Component: | avformat |
Version: | git-master | Keywords: | concat |
Cc: | sycxyc | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description (last modified by )
This issue was also mentioned here: https://www.reddit.com/r/ffmpeg/comments/e1o3hv/ffconcat_filter_with_millisecond_precision_how/ and here: https://forum.videohelp.com/threads/397470-Converting-a-sequence-of-images-to-video-with-variable-framerate
Summary of the bug:
How to reproduce:
A concat file like this
file 000000.jpg duration 116ms file 000001.jpg duration 116ms file 000002.jpg duration 116ms file 000003.jpg duration 116ms file 000004.jpg duration 116ms file 000005.jpg duration 116ms file 000006.jpg duration 116ms file 000007.jpg duration 116ms file 000008.jpg duration 116ms file 000009.jpg duration 1002ms file 000010.jpg duration 116ms file 000011.jpg duration 116ms file 000012.jpg duration 116ms file 000013.jpg duration 1129ms file 000014.jpg duration 73ms file 000015.jpg duration 73ms file 000016.jpg duration 116ms file 000017.jpg duration 116ms file 000018.jpg duration 2184ms file 000018.jpg
The output:
ffprobe -f concat -i concat.txt -show_frames | findstr "pkt_pts" pkt_pts=0 pkt_pts_time=0.000000 pkt_pts=3 pkt_pts_time=0.120000 pkt_pts=6 pkt_pts_time=0.240000 pkt_pts=9 pkt_pts_time=0.360000 pkt_pts=12 pkt_pts_time=0.480000 pkt_pts=15 pkt_pts_time=0.600000 pkt_pts=17 pkt_pts_time=0.680000 pkt_pts=20 pkt_pts_time=0.800000 pkt_pts=23 pkt_pts_time=0.920000 pkt_pts=26 pkt_pts_time=1.040000 pkt_pts=51 pkt_pts_time=2.040000 pkt_pts=54 pkt_pts_time=2.160000 pkt_pts=57 pkt_pts_time=2.280000 pkt_pts=60 pkt_pts_time=2.400000 pkt_pts=88 pkt_pts_time=3.520000 pkt_pts=90 pkt_pts_time=3.600000 pkt_pts=92 pkt_pts_time=3.680000 pkt_pts=95 pkt_pts_time=3.800000 pkt_pts=98 pkt_pts_time=3.920000 pkt_pts=152 pkt_pts_time=6.080000
The output looks correct at first, but timestamps are rounded, and for some reasons the duration here
pkt_pts_time=0.600000 pkt_pts=17 pkt_pts_time=0.680000
is 80ms instead of 120ms (and expected 116ms)
It's not the problem of ffprobe, when converting to webm, for example, or gif
ffmpeg -i concat.txt -c:v libvpx-vp9 -lossless 1 out.webm
timings would be like showed above.
The other case:
file 000000.jpg duration 50ms file 000001.jpg duration 60ms file 000002.jpg duration 50ms file 000003.jpg duration 60ms file 000004.jpg duration 50ms file 000005.jpg duration 60ms file 000006.jpg duration 50ms file 000007.jpg duration 60ms file 000008.jpg duration 60ms file 000009.jpg duration 50ms file 000010.jpg duration 60ms file 000011.jpg duration 50ms file 000012.jpg duration 60ms file 000013.jpg duration 50ms file 000014.jpg duration 60ms file 000015.jpg duration 50ms file 000016.jpg duration 60ms file 000017.jpg duration 60ms file 000018.jpg duration 50ms file 000019.jpg duration 60ms file 000020.jpg duration 50ms file 000021.jpg duration 60ms file 000022.jpg duration 50ms file 000023.jpg duration 60ms file 000023.jpg
Output:
pkt_pts=0 pkt_pts_time=0.000000 pkt_pts=1 pkt_pts_time=0.040000 pkt_pts=3 pkt_pts_time=0.120000 pkt_pts=4 pkt_pts_time=0.160000 pkt_pts=6 pkt_pts_time=0.240000 pkt_pts=7 pkt_pts_time=0.280000 pkt_pts=8 pkt_pts_time=0.320000 pkt_pts=10 pkt_pts_time=0.400000 pkt_pts=11 pkt_pts_time=0.440000 pkt_pts=13 pkt_pts_time=0.520000 pkt_pts=14 pkt_pts_time=0.560000 pkt_pts=15 pkt_pts_time=0.600000 pkt_pts=17 pkt_pts_time=0.680000 pkt_pts=18 pkt_pts_time=0.720000 pkt_pts=19 pkt_pts_time=0.760000 pkt_pts=21 pkt_pts_time=0.840000 pkt_pts=22 pkt_pts_time=0.880000 pkt_pts=24 pkt_pts_time=0.960000 pkt_pts=25 pkt_pts_time=1.000000 pkt_pts=26 pkt_pts_time=1.040000 pkt_pts=28 pkt_pts_time=1.120000 pkt_pts=29 pkt_pts_time=1.160000 pkt_pts=31 pkt_pts_time=1.240000 pkt_pts=32 pkt_pts_time=1.280000 pkt_pts=33 pkt_pts_time=1.320000
Attachments (2)
Change History (12)
comment:1 by , 3 years ago
Description: | modified (diff) |
---|
comment:2 by , 3 years ago
comment:3 by , 3 years ago
It seems as if this is due to rounding to a timebase of 1/25 somewhere.
This is what person from reddit thread I mentioned says too. The problem is that it happens on input stream and it seems there's no way you can specify timebase of the input stream
comment:4 by , 3 years ago
Please (test current FFmpeg git head and) provide the command line you tested together with the complete, uncut console output and the necessary input files to make this a valid ticket.
comment:5 by , 3 years ago
Keywords: | concat added |
---|
by , 3 years ago
Attachment: | ffmpeg-20210501-201727.log added |
---|
by , 3 years ago
Attachment: | concat.txt added |
---|
comment:6 by , 3 years ago
I don't know if input images are necessary. I tried the same concat file with different sets of pictures and it didn't have any impact on timecodes.
follow-up: 8 comment:7 by , 3 years ago
The unwanted 25 fps does seem to be coming from concat
. I tested that along with image2
and found that image2
honors the frame rate passed as a cli option.
Here's a script that creates some sample images, does a concat run and an image2 run, and collects reports for each.
#!/bin/zsh OUT=$(mktemp -d) CATFILE=${OUT}/catfile.txt pushd ${OUT} echo "generating some sample images with Imagemagik's 'convert' tool" for i in {1..60} do IMG=image-$(printf "%03d" ${i}).jpg convert -size 600x300 -gravity center -background black \ -fill purple label:${i} -units PixelsPerInch -density 254 ${IMG} echo "file '${IMG}'" >> ${CATFILE} echo "duration 0.016" >> ${CATFILE} done echo "Wrote sample ffmpeg concat input file: ${CATFILE}" CONCAT_CMD='ffmpeg -f concat -i ${CATFILE} -report concat.mkv 2> /dev/null' export FFREPORT=file=ffprobe-concat.log echo "Probing concat with:\n${CONCAT_CMD}" eval ${CONCAT_CMD} echo "Wrote video ${OUT}/concat.mkv" echo "Reading frame rate of concat.mkv..." ffprobe -v error -show_format -show_streams concat.mkv | grep 'frame_rate' IMAGE2_CMD="ffmpeg -f image2 -framerate 60 -i image-%03d.jpg image2.mkv 2> /dev/null" echo "\nProbing image2 with:\n${IMAGE2_CMD}" export FFREPORT=file=ffprobe-image2.log eval ${IMAGE2_CMD} echo "Wrote video ${OUT}/image2.mkv" echo "Reading frame rate of concat.mkv..." ffprobe -v error -show_format -show_streams image2.mkv | grep 'frame_rate' echo "\nFull reports for each run: " ls -1 ${OUT}/ffprobe*.log open ${OUT} popd
When run on my machine, it looks like this:
andre@boom % ./duration_snooping.sh generating some sample images with Imagemagik's 'convert' tool Wrote sample ffmpeg concat input file: /var/folders/sc/q27bbsbn105gr0d08r3nd2jr0000gn/T/tmp.jAH5RBjv/catfile.txt Probing concat with: ffmpeg -f concat -i ${CATFILE} -report concat.mkv 2> /dev/null Wrote video /var/folders/sc/q27bbsbn105gr0d08r3nd2jr0000gn/T/tmp.jAH5RBjv/concat.mkv Reading frame rate of concat.mkv... r_frame_rate=25/1 avg_frame_rate=25/1 Probing image2 with: ffmpeg -f image2 -framerate 60 -i image-%03d.jpg image2.mkv 2> /dev/null Wrote video /var/folders/sc/q27bbsbn105gr0d08r3nd2jr0000gn/T/tmp.jAH5RBjv/image2.mkv Reading frame rate of concat.mkv... r_frame_rate=60/1 avg_frame_rate=60/1 Full reports for each run: /var/folders/sc/q27bbsbn105gr0d08r3nd2jr0000gn/T/tmp.jAH5RBjv/ffprobe-concat.log /var/folders/sc/q27bbsbn105gr0d08r3nd2jr0000gn/T/tmp.jAH5RBjv/ffprobe-image2.log
Here are the two reports from the above run:
comment:8 by , 3 years ago
Replying to Andre LaBranche:
The unwanted 25 fps does seem to be coming from
concat
. I tested that along withimage2
and found thatimage2
honors the frame rate passed as a cli option.
image2 honors the frame_rate
option, but you never gave that option to the image2
instances below the concat demuxer.
I would not oppose a patch to concat to add a time_base
option.
comment:9 by , 22 months ago
Component: | undetermined → avformat |
---|---|
Priority: | normal → wish |
Type: | defect → enhancement |
Version: | unspecified → git-master |
comment:10 by , 6 months ago
Cc: | added |
---|
It seems as if this is due to rounding to a timebase of 1/25 somewhere. The exact timestamps in your example would be 0, 116, 232, 348, 464, 580, 696... which get rounded to 0, 120, 240, 360, 480, 600, 680... when using a timebase of 1/25.