Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#7750 closed defect (invalid)

Using -f segment to produce avi files produces 'corrupted' avi files.

Reported by: mhkohne Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
This command line
ffmpeg -loglevel info -i Cosmos.mp4 -f segment -segment_time 30 test%03d.avi

Should transcode the input file into a series of approximately 30 second output files.

The first output file is in fact 30 seconds (snippet from ffprobe output on that file):

Duration: 00:00:30.33, start: 0.000000, bitrate: 948 kb/s

The second is a full minute:

Duration: 00:01:00.25, start: 0.000000, bitrate: 587 kb/s

The third is a minute and a half:

Duration: 00:01:30.38, start: 0.000000, bitrate: 508 kb/s

I'm doing playback on Windows with VLC (Windows media player produces the same results)
When the first file is played (ffplay) back, it's fine.
When test001.avi is played, you see a single frame that holds static for 30 seconds while the audio plays, then the video plays as normal.
When test002.avi is played, you see a single frame that holds static for 30 seconds while the audio playes, then you get 30 seconds of silence, then the 30 seconds of video plays normally.

A little debugging work shows that the problem stems from the dts values coming into the avi muxer.
When not using the segment muxer, it appears that the dts values almost always start at 0.
When using the segment muxer, the first dts value of the new segment is NOT zero, it's 30 seconds.

Examination of the avienc.c:write_skip_frames function shows that is comparing the dts value to the packet count in order to decide when to insert empty frames.
In the case of the second segment (where the dts value starts at some value > 0, but packet_count is zero), this function ends up inserting enough empty frames to get the packet count to catch up to the dts.

I'm not really sure why the audio doesn't get similarly delayed.

How to reproduce:
(Use the mpeg4 file from https://archive.org/details/CosmosLaundromatFirstCycle as the input file.)

ffmpeg -loglevel info -i Cosmos.mp4 -f segment -segment_time 30 test%03d.avi

ffmpeg version N-93214-g7e4d3db Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-11)
  configuration: --prefix=/data/SHR4634/ffmpeg/build --extra-cflags=-I/data/SHR4634/ffmpeg/build/include --extra-ldflags=-L/data/SHR4634/ffmpeg/build/lib --extra-libs='-lm -ldl -lpthread -lrt' --enable-gpl --enable-nonfree --disable-libfdk_aac --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libfreetype --enable-libspeex --enable-libtheora --cpu=i686 --enable-runtime-cpudetect
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 47.102 / 58. 47.102
  libavformat    58. 26.101 / 58. 26.101
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Cosmos.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    track           : 0
    artist          : Blender Foundation
    album           :
    comment         : On a desolate island, suicidal sheep Franck meets his fate in a quirky salesman, who offers him the gift of a lifetime. Little does he know that he can only handle so much lifetime.
                    :
                    : (CC) Blender Foundation | www.cosmoslaundromat.org
    date            : 2015
    genre           :
    title           : Cosmos Laundromat: First Cycle
    encoder         : Lavf56.40.100
  Duration: 00:12:10.62, start: 0.000000, bitrate: 2409 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x804 [SAR 1:1 DAR 160:67], 2278 kb/s, 24 fps, 24 tbr, 90k tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[segment @ 0xb4d6140] Opening 'test000.avi' for writing
Output #0, segment, to 'test%03d.avi':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    track           : 0
    artist          : Blender Foundation
    album           :
    comment         : On a desolate island, suicidal sheep Franck meets his fate in a quirky salesman, who offers him the gift of a lifetime. Little does he know that he can only handle so much lifetime.
                    :
                    : (CC) Blender Foundation | www.cosmoslaundromat.org
    date            : 2015
    genre           :
    title           : Cosmos Laundromat: First Cycle
    encoder         : Lavf58.26.101
    Stream #0:0(und): Video: mpeg4, yuv420p, 1920x804 [SAR 1:1 DAR 160:67], q=2-31, 200 kb/s, 24 fps, 24 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.47.102 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.47.102 libmp3lame
frame=  129 fps=0.0 q=2.0 size=N/A time=00:00:05.59 bitrate=N/A speed=11.2x   
frame=  263 fps=262 q=31.0 size=N/A time=00:00:11.18 bitrate=N/A speed=11.2x   
frame=  381 fps=253 q=31.0 size=N/A time=00:00:16.09 bitrate=N/A speed=10.7x   
frame=  486 fps=242 q=31.0 size=N/A time=00:00:20.45 bitrate=N/A speed=10.2x   
frame=  588 fps=235 q=31.0 size=N/A time=00:00:24.71 bitrate=N/A speed=9.86x   
frame=  691 fps=230 q=31.0 size=N/A time=00:00:28.96 bitrate=N/A speed=9.64x   
[segment @ 0xb4d6140] Opening 'test001.avi' for writing
frame=  793 fps=226 q=31.0 size=N/A time=00:00:33.25 bitrate=N/A speed=9.48x   
frame=  898 fps=224 q=31.0 size=N/A time=00:00:37.61 bitrate=N/A speed=9.38x   
frame= 1003 fps=222 q=31.0 size=N/A time=00:00:42.00 bitrate=N/A speed=9.31x   
frame= 1116 fps=222 q=31.0 size=N/A time=00:00:46.70 bitrate=N/A speed=9.31x   
frame= 1212 fps=220 q=31.0 size=N/A time=00:00:50.70 bitrate=N/A speed=9.18x   
frame= 1317 fps=219 q=31.0 size=N/A time=00:00:55.06 bitrate=N/A speed=9.14x   
frame= 1420 fps=218 q=31.0 size=N/A time=00:00:59.35 bitrate=N/A speed= 9.1x   
[segment @ 0xb4d6140] Opening 'test002.avi' for writing
frame= 1509 fps=215 q=31.0 size=N/A time=00:01:03.08 bitrate=N/A speed=8.98x   
frame= 1599 fps=212 q=31.0 size=N/A time=00:01:06.82 bitrate=N/A speed=8.87x   
frame= 1694 fps=211 q=31.0 size=N/A time=00:01:10.79 bitrate=N/A speed=8.81x   
frame= 1796 fps=210 q=31.0 size=N/A time=00:01:15.02 bitrate=N/A speed=8.79x   
frame= 1903 fps=211 q=31.0 size=N/A time=00:01:19.51 bitrate=N/A speed= 8.8x   
frame= 2012 fps=211 q=31.0 size=N/A time=00:01:24.03 bitrate=N/A speed=8.81x   
frame= 2110 fps=210 q=31.0 size=N/A time=00:01:28.11 bitrate=N/A speed=8.77x   
[segment @ 0xb4d6140] Opening 'test003.avi' for writing
frame= 2199 fps=209 q=31.0 size=N/A time=00:01:31.84 bitrate=N/A speed=8.71x   
frame= 2292 fps=207 q=31.0 size=N/A time=00:01:35.71 bitrate=N/A speed=8.66x   
frame= 2386 fps=207 q=31.0 size=N/A time=00:01:39.63 bitrate=N/A speed=8.63x   
frame= 2479 fps=206 q=31.0 size=N/A time=00:01:43.49 bitrate=N/A speed=8.59x   
frame= 2574 fps=205 q=31.0 size=N/A time=00:01:47.44 bitrate=N/A speed=8.56x   
frame= 2665 fps=204 q=31.0 size=N/A time=00:01:51.25 bitrate=N/A speed=8.52x   
frame= 2757 fps=203 q=31.0 size=N/A time=00:01:55.06 bitrate=N/A speed=8.49x   
frame= 2845 fps=202 q=31.0 size=N/A time=00:01:58.75 bitrate=N/A speed=8.44x   
[segment @ 0xb4d6140] Opening 'test004.avi' for writing
frame= 2932 fps=201 q=31.0 size=N/A time=00:02:02.35 bitrate=N/A speed= 8.4x   
frame= 3019 fps=200 q=31.0 size=N/A time=00:02:05.96 bitrate=N/A speed=8.36x   
frame= 3107 fps=200 q=31.0 size=N/A time=00:02:09.67 bitrate=N/A speed=8.33x   
frame= 3204 fps=199 q=31.0 size=N/A time=00:02:13.69 bitrate=N/A speed=8.32x   
frame= 3307 fps=200 q=31.0 size=N/A time=00:02:18.03 bitrate=N/A speed=8.33x   
frame= 3408 fps=200 q=31.0 size=N/A time=00:02:22.21 bitrate=N/A speed=8.33x   
frame= 3507 fps=200 q=24.8 size=N/A time=00:02:26.36 bitrate=N/A speed=8.33x   
[segment @ 0xb4d6140] Opening 'test005.avi' for writing
frame= 3606 fps=200 q=31.0 size=N/A time=00:02:30.46 bitrate=N/A speed=8.32x   
frame= 3707 fps=200 q=31.0 size=N/A time=00:02:34.69 bitrate=N/A speed=8.33x   
frame= 3805 fps=199 q=31.0 size=N/A time=00:02:38.74 bitrate=N/A speed=8.32x   
frame= 3899 fps=199 q=31.0 size=N/A time=00:02:42.69 bitrate=N/A speed=8.31x   
frame= 3991 fps=199 q=31.0 size=N/A time=00:02:46.50 bitrate=N/A speed=8.29x   
frame= 4094 fps=199 q=31.0 size=N/A time=00:02:50.81 bitrate=N/A speed= 8.3x   
frame= 4198 fps=199 q=31.0 size=N/A time=00:02:55.12 bitrate=N/A speed=8.31x   
frame= 4301 fps=199 q=24.8 size=N/A time=00:02:59.40 bitrate=N/A speed=8.31x   
[segment @ 0xb4d6140] Opening 'test006.avi' for writing
frame= 4400 fps=199 q=31.0 size=N/A time=00:03:03.53 bitrate=N/A speed=8.31x   
frame= 4500 fps=199 q=31.0 size=N/A time=00:03:07.68 bitrate=N/A speed=8.31x   
frame= 4600 fps=199 q=31.0 size=N/A time=00:03:11.86 bitrate=N/A speed=8.31x   
frame= 4697 fps=199 q=24.8 size=N/A time=00:03:15.91 bitrate=N/A speed=8.31x   
frame= 4803 fps=199 q=31.0 size=N/A time=00:03:20.33 bitrate=N/A speed=8.32x   
frame= 4900 fps=199 q=31.0 size=N/A time=00:03:24.38 bitrate=N/A speed=8.31x   
frame= 5005 fps=199 q=31.0 size=N/A time=00:03:28.74 bitrate=N/A speed=8.32x   
[segment @ 0xb4d6140] Opening 'test007.avi' for writing
frame= 5108 fps=200 q=31.0 size=N/A time=00:03:33.05 bitrate=N/A speed=8.33x   
frame= 5201 fps=199 q=31.0 size=N/A time=00:03:36.92 bitrate=N/A speed=8.31x   
frame= 5299 fps=199 q=24.8 size=N/A time=00:03:40.99 bitrate=N/A speed=8.31x   
frame= 5394 fps=199 q=31.0 size=N/A time=00:03:44.96 bitrate=N/A speed= 8.3x   
frame= 5492 fps=199 q=31.0 size=N/A time=00:03:49.04 bitrate=N/A speed= 8.3x   
frame= 5580 fps=199 q=31.0 size=N/A time=00:03:52.69 bitrate=N/A speed=8.28x   
frame= 5679 fps=199 q=31.0 size=N/A time=00:03:56.82 bitrate=N/A speed=8.28x   
[segment @ 0xb4d6140] Opening 'test008.avi' for writing
frame= 5777 fps=199 q=24.8 size=N/A time=00:04:00.90 bitrate=N/A speed=8.28x   
frame= 5877 fps=199 q=31.0 size=N/A time=00:04:05.08 bitrate=N/A speed=8.28x   
frame= 5976 fps=198 q=31.0 size=N/A time=00:04:09.20 bitrate=N/A speed=8.28x   
frame= 6071 fps=198 q=31.0 size=N/A time=00:04:13.17 bitrate=N/A speed=8.27x   
frame= 6163 fps=198 q=31.0 size=N/A time=00:04:16.99 bitrate=N/A speed=8.26x   
frame= 6258 fps=198 q=31.0 size=N/A time=00:04:20.96 bitrate=N/A speed=8.26x   
frame= 6356 fps=198 q=31.0 size=N/A time=00:04:25.03 bitrate=N/A speed=8.25x   
frame= 6450 fps=198 q=31.0 size=N/A time=00:04:28.93 bitrate=N/A speed=8.25x   
[segment @ 0xb4d6140] Opening 'test009.avi' for writing
frame= 6555 fps=198 q=31.0 size=N/A time=00:04:33.34 bitrate=N/A speed=8.25x   
frame= 6664 fps=198 q=31.0 size=N/A time=00:04:37.86 bitrate=N/A speed=8.27x   
frame= 6772 fps=198 q=31.0 size=N/A time=00:04:42.40 bitrate=N/A speed=8.28x   
frame= 6881 fps=199 q=31.0 size=N/A time=00:04:46.92 bitrate=N/A speed=8.29x   
frame= 6991 fps=199 q=31.0 size=N/A time=00:04:51.50 bitrate=N/A speed= 8.3x   
frame= 7091 fps=199 q=31.0 size=N/A time=00:04:55.65 bitrate=N/A speed= 8.3x   
frame= 7185 fps=199 q=31.0 size=N/A time=00:04:59.57 bitrate=N/A speed=8.29x   
[segment @ 0xb4d6140] Opening 'test010.avi' for writing
frame= 7276 fps=199 q=31.0 size=N/A time=00:05:03.36 bitrate=N/A speed=8.28x   
frame= 7374 fps=199 q=31.0 size=N/A time=00:05:07.46 bitrate=N/A speed=8.28x   
frame= 7470 fps=198 q=31.0 size=N/A time=00:05:11.45 bitrate=N/A speed=8.28x   
frame= 7570 fps=198 q=24.8 size=N/A time=00:05:15.63 bitrate=N/A speed=8.28x   
frame= 7665 fps=198 q=31.0 size=N/A time=00:05:19.58 bitrate=N/A speed=8.27x   
frame= 7767 fps=198 q=31.0 size=N/A time=00:05:23.81 bitrate=N/A speed=8.27x   
frame= 7853 fps=198 q=31.0 size=N/A time=00:05:27.41 bitrate=N/A speed=8.26x   
[segment @ 0xb4d6140] Opening 'test011.avi' for writing
frame= 7950 fps=198 q=31.0 size=N/A time=00:05:31.46 bitrate=N/A speed=8.26x   
frame= 8052 fps=198 q=31.0 size=N/A time=00:05:35.72 bitrate=N/A speed=8.26x   
frame= 8153 fps=198 q=31.0 size=N/A time=00:05:39.90 bitrate=N/A speed=8.26x   
frame= 8254 fps=198 q=31.0 size=N/A time=00:05:44.11 bitrate=N/A speed=8.26x   
frame= 8357 fps=198 q=31.0 size=N/A time=00:05:48.39 bitrate=N/A speed=8.26x   
frame= 8448 fps=198 q=31.0 size=N/A time=00:05:52.20 bitrate=N/A speed=8.26x   
frame= 8545 fps=198 q=31.0 size=N/A time=00:05:56.23 bitrate=N/A speed=8.25x   
frame= 8641 fps=198 q=31.0 size=N/A time=00:06:00.22 bitrate=N/A speed=8.25x   
[segment @ 0xb4d6140] Opening 'test012.avi' for writing
frame= 8734 fps=198 q=31.0 size=N/A time=00:06:04.14 bitrate=N/A speed=8.25x   
frame= 8825 fps=198 q=31.0 size=N/A time=00:06:07.90 bitrate=N/A speed=8.24x   
frame= 8917 fps=197 q=31.0 size=N/A time=00:06:11.74 bitrate=N/A speed=8.23x   
frame= 9022 fps=198 q=31.0 size=N/A time=00:06:16.11 bitrate=N/A speed=8.24x   
frame= 9131 fps=198 q=31.0 size=N/A time=00:06:20.65 bitrate=N/A speed=8.24x   
frame= 9223 fps=198 q=31.0 size=N/A time=00:06:24.49 bitrate=N/A speed=8.24x   
frame= 9318 fps=198 q=31.0 size=N/A time=00:06:28.46 bitrate=N/A speed=8.23x   
[segment @ 0xb4d6140] Opening 'test013.avi' for writing
frame= 9412 fps=197 q=31.0 size=N/A time=00:06:32.35 bitrate=N/A speed=8.23x   
frame= 9507 fps=197 q=31.0 size=N/A time=00:06:36.32 bitrate=N/A speed=8.23x   
frame= 9612 fps=197 q=31.0 size=N/A time=00:06:40.71 bitrate=N/A speed=8.23x   
frame= 9718 fps=198 q=31.0 size=N/A time=00:06:45.10 bitrate=N/A speed=8.24x   
frame= 9820 fps=198 q=31.0 size=N/A time=00:06:49.36 bitrate=N/A speed=8.24x   
frame= 9923 fps=198 q=31.0 size=N/A time=00:06:53.67 bitrate=N/A speed=8.24x   
frame=10015 fps=198 q=31.0 size=N/A time=00:06:57.46 bitrate=N/A speed=8.24x   
[segment @ 0xb4d6140] Opening 'test014.avi' for writing
frame=10107 fps=197 q=31.0 size=N/A time=00:07:01.32 bitrate=N/A speed=8.23x   
frame=10200 fps=197 q=31.0 size=N/A time=00:07:05.19 bitrate=N/A speed=8.23x   
frame=10294 fps=197 q=31.0 size=N/A time=00:07:09.13 bitrate=N/A speed=8.22x   
frame=10390 fps=197 q=31.0 size=N/A time=00:07:13.11 bitrate=N/A speed=8.22x   
frame=10482 fps=197 q=31.0 size=N/A time=00:07:16.95 bitrate=N/A speed=8.21x   
frame=10581 fps=197 q=31.0 size=N/A time=00:07:21.10 bitrate=N/A speed=8.22x   
frame=10680 fps=197 q=31.0 size=N/A time=00:07:25.23 bitrate=N/A speed=8.22x   
frame=10779 fps=197 q=31.0 size=N/A time=00:07:29.33 bitrate=N/A speed=8.22x   
[segment @ 0xb4d6140] Opening 'test015.avi' for writing
frame=10866 fps=197 q=31.0 size=N/A time=00:07:32.96 bitrate=N/A speed=8.21x   
frame=10955 fps=197 q=31.0 size=N/A time=00:07:36.67 bitrate=N/A speed= 8.2x   
frame=11045 fps=197 q=24.8 size=N/A time=00:07:40.43 bitrate=N/A speed=8.19x   
frame=11129 fps=196 q=31.0 size=N/A time=00:07:43.90 bitrate=N/A speed=8.18x   
frame=11226 fps=196 q=31.0 size=N/A time=00:07:47.95 bitrate=N/A speed=8.18x   
frame=11321 fps=196 q=31.0 size=N/A time=00:07:51.92 bitrate=N/A speed=8.18x   
frame=11401 fps=196 q=31.0 size=N/A time=00:07:55.24 bitrate=N/A speed=8.16x   
frame=11483 fps=196 q=31.0 size=N/A time=00:07:58.66 bitrate=N/A speed=8.15x   
[segment @ 0xb4d6140] Opening 'test016.avi' for writing
frame=11570 fps=195 q=31.0 size=N/A time=00:08:02.29 bitrate=N/A speed=8.14x   
frame=11649 fps=195 q=31.0 size=N/A time=00:08:05.56 bitrate=N/A speed=8.13x   
frame=11727 fps=195 q=31.0 size=N/A time=00:08:08.82 bitrate=N/A speed=8.12x   
frame=11811 fps=195 q=31.0 size=N/A time=00:08:12.32 bitrate=N/A speed=8.11x   
frame=11894 fps=194 q=24.8 size=N/A time=00:08:15.80 bitrate=N/A speed= 8.1x   
frame=11968 fps=194 q=24.8 size=N/A time=00:08:18.88 bitrate=N/A speed=8.08x   
frame=12038 fps=193 q=31.0 size=N/A time=00:08:21.78 bitrate=N/A speed=8.06x   
frame=12121 fps=193 q=31.0 size=N/A time=00:08:25.23 bitrate=N/A speed=8.05x   
frame=12207 fps=193 q=31.0 size=N/A time=00:08:28.83 bitrate=N/A speed=8.05x   
[segment @ 0xb4d6140] Opening 'test017.avi' for writing
frame=12280 fps=193 q=24.8 size=N/A time=00:08:31.89 bitrate=N/A speed=8.03x   
frame=12351 fps=192 q=31.0 size=N/A time=00:08:34.82 bitrate=N/A speed=8.01x   
frame=12434 fps=192 q=31.0 size=N/A time=00:08:38.29 bitrate=N/A speed=   8x   
frame=12530 fps=192 q=31.0 size=N/A time=00:08:42.31 bitrate=N/A speed=8.01x   
frame=12635 fps=192 q=24.8 size=N/A time=00:08:46.68 bitrate=N/A speed=8.01x   
frame=12718 fps=192 q=31.0 size=N/A time=00:08:50.10 bitrate=N/A speed=   8x   
frame=12796 fps=192 q=31.0 size=N/A time=00:08:53.36 bitrate=N/A speed=7.99x   
frame=12869 fps=191 q=31.0 size=N/A time=00:08:56.42 bitrate=N/A speed=7.98x   
frame=12959 fps=191 q=31.0 size=N/A time=00:09:00.16 bitrate=N/A speed=7.97x   
[segment @ 0xb4d6140] Opening 'test018.avi' for writing
frame=13050 fps=191 q=24.8 size=N/A time=00:09:03.94 bitrate=N/A speed=7.97x   
frame=13144 fps=191 q=31.0 size=N/A time=00:09:07.86 bitrate=N/A speed=7.97x   
frame=13242 fps=191 q=24.8 size=N/A time=00:09:11.96 bitrate=N/A speed=7.97x   
frame=13316 fps=191 q=24.8 size=N/A time=00:09:15.04 bitrate=N/A speed=7.96x   
frame=13400 fps=191 q=31.0 size=N/A time=00:09:18.52 bitrate=N/A speed=7.95x   
frame=13489 fps=191 q=31.0 size=N/A time=00:09:22.25 bitrate=N/A speed=7.94x   
frame=13585 fps=191 q=31.0 size=N/A time=00:09:26.23 bitrate=N/A speed=7.94x   
frame=13679 fps=191 q=31.0 size=N/A time=00:09:30.17 bitrate=N/A speed=7.94x   
[segment @ 0xb4d6140] Opening 'test019.avi' for writing
frame=13771 fps=191 q=31.0 size=N/A time=00:09:33.98 bitrate=N/A speed=7.94x   
frame=13862 fps=190 q=31.0 size=N/A time=00:09:37.77 bitrate=N/A speed=7.94x   
frame=13956 fps=190 q=24.8 size=N/A time=00:09:41.69 bitrate=N/A speed=7.94x   
frame=14054 fps=190 q=31.0 size=N/A time=00:09:45.79 bitrate=N/A speed=7.94x   
frame=14156 fps=191 q=31.0 size=N/A time=00:09:50.05 bitrate=N/A speed=7.94x   
frame=14259 fps=191 q=31.0 size=N/A time=00:09:54.31 bitrate=N/A speed=7.95x   
frame=14361 fps=191 q=31.0 size=N/A time=00:09:58.59 bitrate=N/A speed=7.95x   
[segment @ 0xb4d6140] Opening 'test020.avi' for writing
frame=14460 fps=191 q=31.0 size=N/A time=00:10:02.72 bitrate=N/A speed=7.95x   
frame=14574 fps=191 q=31.0 size=N/A time=00:10:07.45 bitrate=N/A speed=7.96x   
frame=14688 fps=191 q=31.0 size=N/A time=00:10:12.20 bitrate=N/A speed=7.97x   
frame=14800 fps=191 q=31.0 size=N/A time=00:10:16.88 bitrate=N/A speed=7.98x   
frame=14914 fps=192 q=31.0 size=N/A time=00:10:21.60 bitrate=N/A speed=7.99x   
frame=15027 fps=192 q=31.0 size=N/A time=00:10:26.33 bitrate=N/A speed=   8x   
[segment @ 0xb4d6140] Opening 'test021.avi' for writing
frame=15140 fps=192 q=31.0 size=N/A time=00:10:31.04 bitrate=N/A speed=8.01x   
frame=15253 fps=192 q=31.0 size=N/A time=00:10:35.74 bitrate=N/A speed=8.02x   
frame=15367 fps=193 q=31.0 size=N/A time=00:10:40.49 bitrate=N/A speed=8.03x   
frame=15481 fps=193 q=31.0 size=N/A time=00:10:45.25 bitrate=N/A speed=8.04x   
frame=15596 fps=193 q=31.0 size=N/A time=00:10:50.05 bitrate=N/A speed=8.05x   
frame=15714 fps=193 q=31.0 size=N/A time=00:10:54.96 bitrate=N/A speed=8.06x   
frame=15830 fps=194 q=31.0 size=N/A time=00:10:59.80 bitrate=N/A speed=8.07x   
[segment @ 0xb4d6140] Opening 'test022.avi' for writing
frame=15949 fps=194 q=31.0 size=N/A time=00:11:04.73 bitrate=N/A speed=8.08x   
frame=16066 fps=194 q=31.0 size=N/A time=00:11:09.62 bitrate=N/A speed=8.09x   
frame=16182 fps=194 q=31.0 size=N/A time=00:11:14.48 bitrate=N/A speed= 8.1x   
frame=16294 fps=194 q=31.0 size=N/A time=00:11:19.13 bitrate=N/A speed= 8.1x   
frame=16402 fps=195 q=31.0 size=N/A time=00:11:23.62 bitrate=N/A speed=8.11x   
frame=16500 fps=195 q=31.0 size=N/A time=00:11:27.72 bitrate=N/A speed=8.11x   
[segment @ 0xb4d6140] Opening 'test023.avi' for writing
frame=16591 fps=194 q=31.0 size=N/A time=00:11:31.48 bitrate=N/A speed=8.11x   
frame=16684 fps=194 q=31.0 size=N/A time=00:11:35.37 bitrate=N/A speed= 8.1x   
frame=16777 fps=194 q=31.0 size=N/A time=00:11:39.21 bitrate=N/A speed= 8.1x   
frame=16868 fps=194 q=31.0 size=N/A time=00:11:43.05 bitrate=N/A speed= 8.1x   
frame=16962 fps=194 q=31.0 size=N/A time=00:11:46.95 bitrate=N/A speed= 8.1x   
frame=17056 fps=194 q=31.0 size=N/A time=00:11:50.87 bitrate=N/A speed=8.09x   
frame=17157 fps=194 q=24.8 size=N/A time=00:11:55.04 bitrate=N/A speed= 8.1x   
frame=17280 fps=195 q=31.0 size=N/A time=00:12:00.22 bitrate=N/A speed=8.11x   
[segment @ 0xb4d6140] Opening 'test024.avi' for writing
frame=17419 fps=195 q=31.0 size=N/A time=00:12:05.99 bitrate=N/A speed=8.13x   
frame=17532 fps=195 q=31.0 Lsize=N/A time=00:12:10.61 bitrate=N/A speed=8.14x   
video:129955kB audio:11416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Change History (3)

comment:1 Changed 7 months ago by mhkohne

I have insufficient time to work through the proper 29 item patch submission checklist, so I present here the patch I'm using locally, in the hopes that it will help someone.
Do with it anything you like.
It fixes the problem for me by making the AVI skip frame handling work relative to the first DTS seen, rather than relative to zero. I don't actually know enough about ffmpeg to know whether that's the right approach in the general case.

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index ac0f04c..c204e5a 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -84,6 +84,7 @@ typedef struct AVIStream {

int sample_requested;

int64_t last_dts;

+ int64_t first_dts;

AVIIndex indexes;

@@ -278,6 +279,8 @@ static int avi_write_header(AVFormatContext *s)

s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
if (!s->streams[n]->priv_data)

return AVERROR(ENOMEM);

+ AVIStream *avist = s->streams[n]->priv_data;
+ avist->first_dts = AV_NOPTS_VALUE;

}

/* header list */

@@ -736,14 +739,23 @@ static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)

{

AVIStream *avist = s->streams[stream_index]->priv_data;
AVCodecParameters *par = s->streams[stream_index]->codecpar;

+ int64_t reldts = dts; relative to first_dts
+
+ if ((dts != AV_NOPTS_VALUE) && (avist->first_dts == AV_NOPTS_VALUE))
+ avist->first_dts = dts;
+
+ if (dts != AV_NOPTS_VALUE)
+ reldts = dts - avist->first_dts;
+

ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index);
while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&

  • dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {

+ reldts > avist->packet_count &&
+ par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {

AVPacket empty_packet;

  • if (dts - avist->packet_count > 60000) {
  • av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", dts - avist->packet_count);

+ if (reldts - avist->packet_count > 60000) {
+ av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", reldts - avist->packet_count);

return AVERROR(EINVAL);

}

comment:2 Changed 7 months ago by Gyan

  • Resolution set to invalid
  • Status changed from new to closed

For segmenting to AVIs, you should reset timestamps.

ffmpeg -loglevel info -i Cosmos.mp4 -f segment -segment_time 30 -reset_timestamps 1 test%03d.avi

Additionally, one has to ensure that generated keyframes are aligned with the start of each segment. The segment muxer, by default, only creates a segment when it encounters a KF after the segment time has elapsed. As it happens, your test input is 24 fps and default GOP size for the default AVI video encoder (mpeg4) is 12 frames (0.5s, in this case), so by happenstance, you won't have a problem in that regard. But in general, add -force_key_frames "expr: gte(t,n_forced*30)" to ensure a KF is present every 30 seconds.

comment:3 Changed 7 months ago by mhkohne

Thank you. I do have proper keyframe handling in the real use of segment - this was just a minimal example.

Note: See TracTickets for help on using tickets.