Opened 12 years ago

Last modified 12 years ago

#2319 new defect

Using concat demuxer with truncated mp4 (mpeg2video,pcm_s16be) leads to infinite loop

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

Description

Summary of the bug:
If the concat demuxer is used in conjunction with a mp4 file containing mpeg2 and pcm, ffmpeg gets stuck after the first video is decoded and never terminates. The problem only occurs, if the mp4 file is truncated and mylist.txt contains more than one entry. (Here one video file is used twice to demonstrate the problem.)

How to reproduce:

ffmpeg -f concat -i mylist.txt out.mp4

Content of mylist.txt

file camera-raw.mp4
file camera-raw.mp4

Video data:
camera-raw.mp4

ffmpeg output

ffmpeg version 1.1.3 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar  2 2013 14:00:59 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --prefix=/home/ls/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-sram --cpu=core2 --enable-hwaccel=h264_vaapi --enable-hwaccel=mpeg2_vaapi --enable-hwaccel=mpeg4_vaapi --enable-libfaac --disable-ffserver --enable-libfreetype --enable-x11grab --enable-avresample --enable-libass --enable-libvpx --enable-libvorbis
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 86.100 / 54. 86.100
  libavformat    54. 59.106 / 54. 59.106
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 32.100 /  3. 32.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[concat @ 0x1cc0780] Estimating duration from bitrate, this may be inaccurate
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, concat, from 'mylist.txt':
  Duration: N/A, start: 0.000000, bitrate: 36537 kb/s
    Stream #0:0: Video: mpeg2video (Main) (mp4v / 0x7634706D), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 35001 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc
    Stream #0:1: Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, stereo, s16, 1536 kb/s
File 'out.mp4' already exists. Overwrite ? [y/N] using SAR=1/1
[libx264 @ 0x1ccb400] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
[libx264 @ 0x1ccb400] profile High, level 4.0
[libx264 @ 0x1ccb400] 264 - core 129 r0+2 e403db4 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf54.59.106
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 12800 tbn, 25 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video -> libx264)
  Stream #0:1 -> #0:1 (pcm_s16be -> libfaac)
Press [q] to stop, [?] for help
[mpeg2video @ 0x1cfade0] warning: first frame is no keyframe
frame=   33 fps=0.0 q=0.0 size=       0kB time=00:00:01.34 bitrate=   0.3kbits/s    
frame=   47 fps= 36 q=0.0 size=       0kB time=00:00:01.83 bitrate=   0.2kbits/s    
frame=   54 fps= 27 q=28.0 size=     123kB time=00:00:02.30 bitrate= 435.9kbits/s    
frame=   59 fps= 23 q=28.0 size=     213kB time=00:00:02.30 bitrate= 757.0kbits/s    
frame=   65 fps= 21 q=28.0 size=     311kB time=00:00:02.79 bitrate= 912.1kbits/s    
frame=   70 fps= 19 q=28.0 size=     383kB time=00:00:02.79 bitrate=1123.5kbits/s    
frame=   76 fps= 18 q=28.0 size=     469kB time=00:00:03.26 bitrate=1176.8kbits/s    
frame=   82 fps= 17 q=28.0 size=     545kB time=00:00:03.26 bitrate=1367.8kbits/s    
frame=   88 fps= 16 q=28.0 size=     620kB time=00:00:03.75 bitrate=1353.8kbits/s    
frame=   93 fps= 16 q=28.0 size=     694kB time=00:00:03.75 bitrate=1513.3kbits/s    
frame=   98 fps= 15 q=28.0 size=     754kB time=00:00:04.22 bitrate=1462.6kbits/s    
frame=  103 fps= 15 q=28.0 size=     819kB time=00:00:04.22 bitrate=1589.0kbits/s    
frame=  110 fps= 15 q=28.0 size=     898kB time=00:00:04.71 bitrate=1559.5kbits/s    
frame=  116 fps= 14 q=28.0 size=     980kB time=00:00:04.71 bitrate=1702.0kbits/s    
frame=  121 fps= 14 q=28.0 size=    1034kB time=00:00:05.18 bitrate=1634.6kbits/s    
frame=  128 fps= 14 q=28.0 size=    1113kB time=00:00:05.18 bitrate=1759.3kbits/s    
frame=  134 fps= 14 q=28.0 size=    1186kB time=00:00:05.67 bitrate=1712.0kbits/s    
frame=  139 fps= 14 q=28.0 size=    1293kB time=00:00:05.67 bitrate=1866.7kbits/s    
frame=  143 fps= 13 q=28.0 size=    1372kB time=00:00:05.69 bitrate=1973.0kbits/s    
frame=  148 fps= 13 q=28.0 size=    1486kB time=00:00:06.14 bitrate=1981.2kbits/s    
frame=  155 fps= 13 q=28.0 size=    1628kB time=00:00:06.14 bitrate=2171.0kbits/s    
frame=  159 fps= 13 q=28.0 size=    1724kB time=00:00:06.63 bitrate=2128.3kbits/s    
frame=  165 fps= 12 q=28.0 size=    1866kB time=00:00:06.63 bitrate=2303.8kbits/s    
frame=  170 fps= 12 q=28.0 size=    1972kB time=00:00:07.10 bitrate=2273.7kbits/s    
frame=  175 fps= 12 q=28.0 size=    2075kB time=00:00:07.10 bitrate=2393.1kbits/s    
frame=  181 fps= 12 q=28.0 size=    2253kB time=00:00:07.59 bitrate=2430.7kbits/s    
frame=  186 fps= 12 q=28.0 size=    2371kB time=00:00:07.59 bitrate=2557.9kbits/s    
frame=  191 fps= 12 q=28.0 size=    2478kB time=00:00:07.61 bitrate=2665.4kbits/s    
frame=  196 fps= 12 q=28.0 size=    2600kB time=00:00:08.06 bitrate=2641.2kbits/s    
frame=  201 fps= 12 q=28.0 size=    2714kB time=00:00:08.06 bitrate=2757.1kbits/s    
frame=  206 fps= 11 q=28.0 size=    2810kB time=00:00:08.55 bitrate=2691.3kbits/s    
frame=  210 fps= 11 q=28.0 size=    2911kB time=00:00:08.55 bitrate=2787.2kbits/s    
frame=  217 fps= 11 q=28.0 size=    3052kB time=00:00:09.02 bitrate=2770.6kbits/s    
frame=  221 fps= 11 q=28.0 size=    3127kB time=00:00:09.02 bitrate=2838.5kbits/s    
frame=  227 fps= 11 q=28.0 size=    3230kB time=00:00:09.04 bitrate=2925.4kbits/s    
frame=  233 fps= 11 q=28.0 size=    3351kB time=00:00:09.51 bitrate=2885.3kbits/s    
frame=  238 fps= 11 q=28.0 size=    3448kB time=00:00:09.51 bitrate=2968.8kbits/s    
frame=  244 fps= 11 q=28.0 size=    3574kB time=00:00:09.98 bitrate=2932.4kbits/s    
frame=  250 fps= 11 q=28.0 size=    3704kB time=00:00:09.98 bitrate=3039.5kbits/s    
frame=  255 fps= 11 q=28.0 size=    3824kB time=00:00:10.47 bitrate=2991.0kbits/s    
frame=  260 fps= 11 q=28.0 size=    3929kB time=00:00:10.47 bitrate=3072.9kbits/s    
frame=  266 fps= 11 q=28.0 size=    4036kB time=00:00:10.94 bitrate=3020.9kbits/s    
frame=  272 fps= 11 q=28.0 size=    4162kB time=00:00:10.94 bitrate=3115.3kbits/s    
frame=  277 fps= 11 q=28.0 size=    4261kB time=00:00:11.43 bitrate=3052.4kbits/s    
frame=  282 fps= 11 q=28.0 size=    4350kB time=00:00:11.43 bitrate=3116.5kbits/s    
frame=  287 fps= 11 q=28.0 size=    4462kB time=00:00:11.45 bitrate=3190.9kbits/s    
frame=  294 fps= 11 q=28.0 size=    4580kB time=00:00:11.90 bitrate=3152.1kbits/s    
frame=  299 fps= 11 q=28.0 size=    4677kB time=00:00:11.92 bitrate=3212.6kbits/s    
frame=  305 fps= 11 q=28.0 size=    4789kB time=00:00:12.39 bitrate=3165.5kbits/s    
frame=  310 fps= 11 q=28.0 size=    4876kB time=00:00:12.39 bitrate=3222.7kbits/s    
frame=  316 fps= 11 q=28.0 size=    4994kB time=00:00:12.86 bitrate=3180.3kbits/s    
frame=  321 fps= 11 q=28.0 size=    5076kB time=00:00:12.86 bitrate=3232.5kbits/s    
frame=  325 fps= 11 q=28.0 size=    5157kB time=00:00:13.35 bitrate=3163.2kbits/s    
frame=  331 fps= 11 q=28.0 size=    5280kB time=00:00:13.35 bitrate=3238.7kbits/s    
frame=  337 fps= 11 q=28.0 size=    5391kB time=00:00:13.82 bitrate=3194.5kbits/s    
frame=  342 fps= 11 q=28.0 size=    5475kB time=00:00:13.82 bitrate=3244.4kbits/s    
frame=  347 fps= 11 q=28.0 size=    5589kB time=00:00:13.84 bitrate=3306.8kbits/s    
frame=  354 fps= 11 q=28.0 size=    5716kB time=00:00:14.31 bitrate=3271.2kbits/s    
frame=  358 fps= 11 q=28.0 size=    5801kB time=00:00:14.31 bitrate=3319.7kbits/s    
frame=  364 fps= 11 q=28.0 size=    5878kB time=00:00:14.78 bitrate=3257.2kbits/s    
frame=  368 fps= 11 q=28.0 size=    5965kB time=00:00:14.78 bitrate=3305.1kbits/s    
frame=  374 fps= 11 q=28.0 size=    6040kB time=00:00:15.27 bitrate=3239.5kbits/s    
frame=  379 fps= 11 q=28.0 size=    6163kB time=00:00:15.27 bitrate=3305.5kbits/s    
frame=  383 fps= 10 q=28.0 size=    6231kB time=00:00:15.29 bitrate=3337.0kbits/s    
frame=  391 fps= 11 q=28.0 size=    6354kB time=00:00:15.74 bitrate=3306.4kbits/s    
frame=  395 fps= 10 q=28.0 size=    6430kB time=00:00:15.89 bitrate=3314.1kbits/s    
frame=  402 fps= 11 q=28.0 size=    6570kB time=00:00:16.23 bitrate=3315.3kbits/s    
frame=  407 fps= 10 q=28.0 size=    6687kB time=00:00:16.23 bitrate=3374.0kbits/s    
frame=  414 fps= 10 q=28.0 size=    6809kB time=00:00:16.70 bitrate=3339.2kbits/s    
frame=  419 fps= 10 q=28.0 size=    6901kB time=00:00:16.72 bitrate=3379.9kbits/s    
frame=  427 fps= 11 q=28.0 size=    7127kB time=00:00:17.19 bitrate=3395.4kbits/s    
frame=  433 fps= 11 q=28.0 size=    7229kB time=00:00:17.66 bitrate=3352.5kbits/s    
frame=  438 fps= 10 q=28.0 size=    7352kB time=00:00:17.66 bitrate=3409.6kbits/s    
frame=  443 fps= 10 q=28.0 size=    7430kB time=00:00:17.66 bitrate=3445.7kbits/s    
frame=  448 fps= 10 q=28.0 size=    7548kB time=00:00:18.15 bitrate=3406.0kbits/s    
frame=  455 fps= 10 q=28.0 size=    7703kB time=00:00:18.15 bitrate=3475.8kbits/s    
frame=  460 fps= 10 q=28.0 size=    7810kB time=00:00:18.62 bitrate=3435.5kbits/s    
frame=  466 fps= 10 q=28.0 size=    7942kB time=00:00:18.62 bitrate=3493.4kbits/s    
frame=  470 fps= 10 q=28.0 size=    8014kB time=00:00:19.11 bitrate=3434.5kbits/s    
frame=  475 fps= 10 q=28.0 size=    8115kB time=00:00:19.11 bitrate=3477.9kbits/s    
frame=  481 fps= 10 q=28.0 size=    8217kB time=00:00:19.58 bitrate=3437.4kbits/s    
frame=  487 fps= 10 q=28.0 size=    8334kB time=00:00:19.58 bitrate=3485.9kbits/s    
frame=  493 fps= 10 q=28.0 size=    8443kB time=00:00:20.07 bitrate=3445.4kbits/s    
frame=  498 fps= 10 q=28.0 size=    8524kB time=00:00:20.07 bitrate=3478.4kbits/s    
frame=  503 fps= 10 q=28.0 size=    8595kB time=00:00:20.41 bitrate=3448.9kbits/s    
frame=  509 fps= 10 q=28.0 size=    8684kB time=00:00:20.54 bitrate=3462.8kbits/s    
frame=  515 fps= 10 q=28.0 size=    8758kB time=00:00:20.75 bitrate=3456.2kbits/s    
frame=  523 fps= 10 q=28.0 size=    8844kB time=00:00:21.03 bitrate=3444.5kbits/s    
frame=  530 fps= 10 q=28.0 size=    8914kB time=00:00:21.50 bitrate=3395.8kbits/s    
frame=  536 fps= 10 q=28.0 size=    8977kB time=00:00:21.50 bitrate=3419.9kbits/s    
frame=  544 fps= 10 q=28.0 size=    9054kB time=00:00:21.99 bitrate=3372.2kbits/s    
frame=  550 fps= 10 q=28.0 size=    9117kB time=00:00:21.99 bitrate=3395.7kbits/s    
frame=  557 fps= 11 q=28.0 size=    9201kB time=00:00:22.46 bitrate=3355.2kbits/s    
frame=  563 fps= 11 q=28.0 size=    9262kB time=00:00:22.48 bitrate=3374.3kbits/s    
frame=  569 fps= 11 q=28.0 size=    9330kB time=00:00:22.95 bitrate=3329.8kbits/s    
Truncating packet of size 124464 to 34592
[mpeg2video @ 0x1cfade0] ac-tex damaged at 63 16
[mpeg2video @ 0x1cfade0] Warning MVs not available
[mpeg2video @ 0x1cfade0] concealing 6240 DC, 6240 AC, 6240 MV errors in B frame

Change History (2)

comment:1 by Cigaes, 12 years ago

Analyzed by developer: set
Component: FFmpegavformat
Keywords: concat added
Reproduced by developer: set
Version: 1.1.3git-master

This is the expected behaviour (but changing it can be considered). The problem is that the headers of your file declare a duration different from the actual duration of the data present in the file. The concat demuxer relies on the duration declared by the file.

More precisely, your file declares a duration of ~820 seconds, but contains only ~23 seconds.

At the end of the first file, ffmpeg is not stuck, it is just encoding 820-23 = 797 seconds of still image. This happens because you chose to output to MP4, and libavformat does not support variable frame rate in this format. Wait long enough and it will start encoding the next file. Output to Matroska (lavf supports VFR in Matroska) and it will not happen; instead, you will get a big gap in the timestamps.

If you do not want the gap / long still image, you need to document the correct duration. Either use a proper tool for cutting the file, so that the duration is correctly set in the headers, or use the duration directive in the concat script to override the value in the file.

comment:2 by ls, 12 years ago

Thank you for the fast and helpful response. Now, ffmpeg's behavior makes sense to me.

The reason I was assuming ffmpeg was stuck in an infinite loop, was that ffmpeg does not react to sigint when encoding the last frame repeatedly. Sending it multipe times or sigquit leads to unwritten headers, since it terminated without writing them.

Since truncated files are a bit problematic because of their incorrect headers it could also be an option to just print a warning when decoding the file has finished earlier than the header indicated. This would help the user to understand whats going on in this situation.

Note: See TracTickets for help on using tickets.