Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#8464 closed defect (invalid)

`outpoint` directive of `concat` demuxer may be off by 1 frame

Reported by: gdgsdg123 Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: concat
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

X.txt:

file 'merge.avi'
inpoint 87.05
outpoint 88.116667


ffmpeg -y -f concat -safe 0 -i "X.txt" -c copy "temp.avi"
ffmpeg version git-2020-01-02-81172b5 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20191125
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 38.100 / 56. 38.100
  libavcodec     58. 65.102 / 58. 65.102
  libavformat    58. 35.101 / 58. 35.101
  libavdevice    58.  9.102 / 58.  9.102
  libavfilter     7. 70.101 /  7. 70.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
[avi @ 00000000003ca900] decoding for stream 0 failed
Input #0, concat, from 'X.txt':
  Duration: 00:00:01.07, bitrate: 0 kb/s
    Stream #0:0: Video: h264 (High 4:4:4 Intra) (H264 / 0x34363248), gbrp(tv, gbr/unknown/unknown, progressive), 1920x1080, 377584 kb/s, 60 fps, 30 tbr, 60 tbn, 120 tbc
Output #0, avi, to 'temp.avi':
  Metadata:
    ISFT            : Lavf58.35.101
    Stream #0:0: Video: h264 (High 4:4:4 Intra) (H264 / 0x34363248), gbrp(tv, gbr/unknown/unknown, progressive), 1920x1080, q=2-31, 377584 kb/s, 60 fps, 30 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[avi @ 00000000003cf100] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
frame=   33 fps=0.0 q=-1.0 Lsize=   96767kB time=00:00:01.08 bitrate=731740.7kbits/s speed=8.74x
video:96760kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.007367%

The frame at outpoint is included, while according to the documentation it shouldn't... And the behavior is inconsistent with different timestamp values.


ffmpeg -ss 87.05 -to 88.116667 -i "merge.avi" -an -c copy "to.avi"
ffmpeg version git-2020-01-02-81172b5 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20191125
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 38.100 / 56. 38.100
  libavcodec     58. 65.102 / 58. 65.102
  libavformat    58. 35.101 / 58. 35.101
  libavdevice    58.  9.102 / 58.  9.102
  libavfilter     7. 70.101 /  7. 70.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
[avi @ 00000000006504c0] decoding for stream 0 failed
Input #0, avi, from 'merge.avi':
  Metadata:
    encoder         : Lavf58.29.100
  Duration: 00:05:24.67, start: 0.000000, bitrate: 377573 kb/s
    Stream #0:0: Video: h264 (High 4:4:4 Intra) (H264 / 0x34363248), gbrp(tv, gbr/unknown/unknown, progressive), 1920x1080, 377584 kb/s, 60 fps, 30 tbr, 60 tbn, 120 tbc
Output #0, avi, to 'to.avi':
  Metadata:
    ISFT            : Lavf58.35.101
    Stream #0:0: Video: h264 (High 4:4:4 Intra) (H264 / 0x34363248), gbrp(tv, gbr/unknown/unknown, progressive), 1920x1080, q=2-31, 377584 kb/s, 60 fps, 30 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[avi @ 000000000315c900] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
frame=   32 fps=0.0 q=-1.0 Lsize=   93969kB time=00:00:01.05 bitrate=733139.1kbits/s speed=9.13x
video:93962kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.007536%

This approach seemed to produce a reliable output with various -to values tried. (not intensively tested)




For obvious reason I'm not gonna upload the "merge.avi"... But I believe the problem can be reproduced with different input and timestamp values.

Attachments (1)

merge.avi (581.0 KB ) - added by gdgsdg123 5 years ago.
Modified "merge.avi" that can be used to reproduce the problem. (with the original commands)

Download all attachments as: .zip

Change History (7)

comment:1 by Carl Eugen Hoyos, 5 years ago

Component: undeterminedavformat
Keywords: concat added
Resolution: needs_more_info
Status: newclosed

Please reopen this ticket if you can provide an input sample file.

by gdgsdg123, 5 years ago

Attachment: merge.avi added

Modified "merge.avi" that can be used to reproduce the problem. (with the original commands)

comment:2 by gdgsdg123, 5 years ago

Resolution: needs_more_info
Status: closedreopened

Seems only the timestamps matter...

comment:3 by Marton Balint, 5 years ago

Resolution: invalid
Status: reopenedclosed

This is a simple timestamp precision issue. Input file is 60 fps, therefore the timestamp of the last frame is *exactly* 5287/60 which is 88.116666666666 (infinite number of sixes), which is indeed smaller then the outpoint you specified 88.116667 therefore the last frame is included. I suggest you round downwards when you specify the outpoint if you dont want to include the frame at outpoint.

Last edited 5 years ago by Marton Balint (previous) (diff)

in reply to:  3 comment:4 by gdgsdg123, 5 years ago

Type: defectenhancement

Replying to cus:

This is a simple timestamp precision issue. Input file is 60 fps, therefore the timestamp of the last frame is *exactly* 5287/60 which is 88.116666666666 (infinite number of sixes), which is indeed smaller then the outpoint you specified 88.116667 therefore the last frame is included.

Maybe invalid but it doesn't answer the real question...


As those are values reported by FFprobe.

gdgsdg123:

ffprobe -hide_banner -show_entries "frame" -select_streams v:0 -of "xml" "temp.avi"
ffprobe -hide_banner -show_entries "frame=best_effort_timestamp_time" -select_streams v:0 -of "compact=nk=1:p=0" "temp.avi"




Replying to cus:

I suggest you round downwards when you specify the outpoint if you dont want to include the frame at outpoint.

This approach seemed to produce a reliable output with various outpoint values tried. (not intensively tested)

in reply to:  description comment:5 by gdgsdg123, 5 years ago

Resolution: invalidworksforme

The "merge.avi" also serves as a good example for testing the cutting accuracy.


The file is entirely composed of "Black Screen" frames with only 3 exceptions:

Frame Number Presentation Timestamp Duration Content
564 87.05 0.033333 Yellow
595 88.083333 0.033334 Green
596 88.116667 N/A Red

Which resemble all 3 possible outcomes: on point, early, late.


Another thing: possible 0 frame output (null segment) without warning...


X.txt:

file 'merge.avi'
inpoint 87.05
outpoint 87.05


ffmpeg -y -f concat -safe 0 -i "X.txt" -c copy "temp.avi"
ffmpeg version git-2020-01-10-3d894db Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20191125
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 38.100 / 56. 38.100
  libavcodec     58. 65.103 / 58. 65.103
  libavformat    58. 35.101 / 58. 35.101
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 70.101 /  7. 70.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, concat, from 'X.txt':
  Duration: 00:00:00.00, bitrate: N/A
    Stream #0:0: Video: h264 (High 4:4:4 Intra) (H264 / 0x34363248), gbrp(tv, gbr/unknown/unknown, progressive), 256x144, 60 fps, 30 tbr, 60 tbn, 60 tbc
Output #0, avi, to 'temp.avi':
  Metadata:
    ISFT            : Lavf58.35.101
    Stream #0:0: Video: h264 (High 4:4:4 Intra) (H264 / 0x34363248), gbrp(tv, gbr/unknown/unknown, progressive), 256x144, q=2-31, 60 fps, 30 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=-1.0 Lsize=       6kB time=00:00:00.00 bitrate=N/A speed=   0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown



ffmpeg -ss 87.05 -to 87.05 -i "merge.avi" -an -c copy "to.avi"
ffmpeg version git-2020-01-10-3d894db Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20191125
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 38.100 / 56. 38.100
  libavcodec     58. 65.103 / 58. 65.103
  libavformat    58. 35.101 / 58. 35.101
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 70.101 /  7. 70.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
-to value smaller than -ss; aborting.



The inpoint/-ss, outpoint/-to values must be carefully chosen.




Off-Topic

When using concat demuxer, explicitly specifying duration is usually necessary.

And is it yet possible to instruct FFmpeg to report the number of frames of each segment?

Last edited 5 years ago by gdgsdg123 (previous) (diff)

comment:6 by Carl Eugen Hoyos, 5 years ago

Resolution: worksformeinvalid
Type: enhancementdefect
Note: See TracTickets for help on using tickets.