Opened 4 years ago

Last modified 4 years ago

#3406 new defect

H.264 threaded decode error

Reported by: Cigaes Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: h264
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

There are some samples that decode correctly with threads turned off or only a few threads, but fail to decode with mode threads.

For example:

$ ./ffmpeg_g -threads 4 -i /tmp/sf.h264 -f framecrc -c png -
ffmpeg version N-60805-gc8f3c3a Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 21 2014 20:26:22 with gcc 4.8 (Debian 4.8.2-15)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libopus --enable-libass --enable-libfreetype --enable-opengl --assert-level=2
  libavutil      52. 65.100 / 52. 65.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  1.103 /  4.  1.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, h264, from '/tmp/sf.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 50 tbc
#software: Lavf55.33.100
#tb 0: 1/25
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Video: png, rgb24, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
0,          0,          0,        1,    14600, 0x4d4b3314
0,          1,          1,        1,    20624, 0x9d04c3da
0,          2,          2,        1,    20373, 0x3224514e
0,          3,          3,        1,    16474, 0x5a53824a
0,          4,          4,        1,    20997, 0xe2ac63ec
0,          5,          5,        1,    21466, 0x3a5edae1
0,          6,          6,        1,    15290, 0x9fb36a83
0,          7,          7,        1,    19601, 0x8af6664a
0,          8,          8,        1,    20217, 0x96032e30
0,          9,          9,        1,    16655, 0x6e0a0985
0,         10,         10,        1,    18492, 0x12b572b4
0,         11,         11,        1,    18118, 0x6b1994d6
frame=   12 fps=0.0 q=0.0 Lsize=       1kB time=00:00:00.48 bitrate=  12.2kbits/s    
video:218kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead -99.671165%
$ ./ffmpeg_g -threads 5 -i /tmp/sf.h264 -f framecrc -c png -
ffmpeg version N-60805-gc8f3c3a Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 21 2014 20:26:22 with gcc 4.8 (Debian 4.8.2-15)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libopus --enable-libass --enable-libfreetype --enable-opengl --assert-level=2
  libavutil      52. 65.100 / 52. 65.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  1.103 /  4.  1.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, h264, from '/tmp/sf.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 50 tbc
#software: Lavf55.33.100
#tb 0: 1/25
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Video: png, rgb24, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
Error while decoding stream #0:0: Invalid data found when processing input
[h264 @ 0xa81240] reference picture missing during reorder
    Last message repeated 1 times
[h264 @ 0xa81240] Missing reference picture, default is 65548
    Last message repeated 1 times
[h264 @ 0xad9200] reference picture missing during reorder
[h264 @ 0xad9200] Missing reference picture, default is 65556
0,          0,          0,        1,    14600, 0x4d4b3314
0,          1,          1,        1,    20624, 0x9d04c3da
0,          3,          3,        1,    20373, 0x3224514e
0,          4,          4,        1,    16474, 0x5a53824a
0,          5,          5,        1,    21099, 0x61cb8a88
0,          6,          6,        1,    21466, 0x7d3727ad
0,          8,          8,        1,    15370, 0x4b0bcbbd
0,          9,          9,        1,    19775, 0xed275f1c
0,         10,         10,        1,    16851, 0x0725c06b
0,         11,         11,        1,    16717, 0xd445fc7c
frame=   10 fps=0.0 q=0.0 Lsize=       1kB time=00:00:00.48 bitrate=  10.3kbits/s    
video:179kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead -99.663483%

The -c png is necessary to reproduce the problem in this particular case, but threading issues are sensitive to timing. Helgrind spews a load of errors too:

==10123== Helgrind, a thread error detector
==10123== Copyright (C) 2007-2012, and GNU GPL'd, by OpenWorks LLP et al.
==10123== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==10123== Command: ./ffmpeg_g -threads 5 -i /tmp/sf.h264 -f framecrc -c png -
==10123== 
ffmpeg version N-60805-gc8f3c3a Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 21 2014 20:26:22 with gcc 4.8 (Debian 4.8.2-15)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libopus --enable-libass --enable-libfreetype --enable-opengl --assert-level=2
  libavutil      52. 65.100 / 52. 65.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  1.103 /  4.  1.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, h264, from '/tmp/sf.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 50 tbc
#software: Lavf55.33.100
#tb 0: 1/25
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Video: png, rgb24, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
==10123== ---Thread-Announcement------------------------------------------
==10123== 
==10123== Thread #11 was created
==10123==    at 0x7BC40BE: clone (clone.S:76)
==10123==    by 0x78C5FF4: do_clone.constprop.4 (createthread.c:74)
==10123==    by 0x78C7473: pthread_create@@GLIBC_2.2.5 (createthread.c:244)
==10123==    by 0x4C2D8F0: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x58A417F: ff_frame_thread_encoder_init (frame_thread_encoder.c:204)
==10123==    by 0x5B7B5D1: avcodec_open2 (utils.c:1305)
==10123==    by 0x4210EA: transcode_init (ffmpeg.c:2658)
==10123==    by 0x406F8E: main (ffmpeg.c:3413)
==10123== 
==10123== ---Thread-Announcement------------------------------------------
==10123== 
==10123== Thread #1 is the program's root thread
==10123== 
==10123== ----------------------------------------------------------------
==10123== 
==10123== Lock at 0x103824B0 was first observed
==10123==    at 0x4C2E96A: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x58A4082: ff_frame_thread_encoder_init (frame_thread_encoder.c:176)
==10123==    by 0x5B7B5D1: avcodec_open2 (utils.c:1305)
==10123==    by 0x4210EA: transcode_init (ffmpeg.c:2658)
==10123==    by 0x406F8E: main (ffmpeg.c:3413)
==10123== 
==10123== Possible data race during write of size 8 at 0x103814B8 by thread #11
==10123== Locks held: 1, at address 0x103824B0
==10123==    at 0x58A3E54: worker (frame_thread_encoder.c:105)
==10123==    by 0x4C2DA86: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x78C6E0D: start_thread (pthread_create.c:311)
==10123==    by 0x7BC40FC: clone (clone.S:113)
==10123== 
==10123== This conflicts with a previous read of size 8 by thread #1
==10123== Locks held: none
==10123==    at 0x58A4487: ff_thread_video_encode_frame (frame_thread_encoder.c:275)
==10123==    by 0x41DCCB: reap_filters (ffmpeg.c:997)
==10123==    by 0x407BFD: main (ffmpeg.c:3399)
==10123== 
==10123== Address 0x103814B8 is 152 bytes inside a block of size 4856 alloc'd
==10123==    at 0x4C2BA30: memalign (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x4C2BB57: posix_memalign (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x6E4A7AC: av_malloc (mem.c:94)
==10123==    by 0x6E4A96D: av_mallocz (mem.c:244)
==10123==    by 0x58A403F: ff_frame_thread_encoder_init (frame_thread_encoder.c:165)
==10123==    by 0x5B7B5D1: avcodec_open2 (utils.c:1305)
==10123==    by 0x4210EA: transcode_init (ffmpeg.c:2658)
==10123==    by 0x406F8E: main (ffmpeg.c:3413)
==10123== 
0,          0,          0,        1,    14600, 0x4d4b3314
0,          1,          1,        1,    20624, 0x9d04c3da4 bitrate=  19.0kbits/s    
0,          2,          2,        1,    20373, 0x3224514e8 bitrate=  15.3kbits/s    
0,          3,          3,        1,    16474, 0x5a53824a2 bitrate=  14.1kbits/s    
0,          4,          4,        1,    20997, 0xe2ac63ec6 bitrate=  13.4kbits/s    
0,          5,          5,        1,    21466, 0x3a5edae10 bitrate=  13.1kbits/s    
0,          6,          6,        1,    15290, 0x9fb36a832:-22.-77 bitrate=N/A    
0,          7,          7,        1,    19601, 0x8af6664a
0,          8,          8,        1,    20217, 0x96032e30
0,          9,          9,        1,    16655, 0x6e0a0985
0,         10,         10,        1,    18492, 0x12b572b4
0,         11,         11,        1,    18118, 0x6b1994d6
frame=   12 fps=0.7 q=0.0 Lsize=       1kB time=00:00:00.48 bitrate=  12.2kbits/s    
video:218kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead -99.671165%
==10123== ----------------------------------------------------------------
==10123== 
==10123== Lock at 0x1038AD20 was first observed
==10123==    at 0x4C2E96A: pthread_mutex_init (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x5B75323: default_lockmgr_cb (utils.c:81)
==10123==    by 0x5B7AD9D: ff_lock_avcodec (utils.c:3299)
==10123==    by 0x5B7B07C: avcodec_open2 (utils.c:1193)
==10123==    by 0x54647A3: avformat_find_stream_info (utils.c:2993)
==10123==    by 0x412DE0: open_input_file (ffmpeg_opt.c:860)
==10123==    by 0x4177C0: ffmpeg_parse_options (ffmpeg_opt.c:2597)
==10123==    by 0x406F20: main (ffmpeg.c:3600)
==10123== 
==10123== Possible data race during write of size 4 at 0x10385924 by thread #1
==10123== Locks held: 1, at address 0x1038AD20
==10123==    at 0x5AD50FD: ff_frame_thread_free (pthread_frame.c:565)
==10123==    by 0x5754DBA: avcodec_close (utils.c:2602)
==10123==    by 0x407618: main (ffmpeg.c:3491)
==10123== 
==10123== Address 0x10385924 is 68 bytes inside a block of size 72 alloc'd
==10123==    at 0x4C2BA30: memalign (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x4C2BB57: posix_memalign (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==10123==    by 0x6E4A7AC: av_malloc (mem.c:94)
==10123==    by 0x6E4A96D: av_mallocz (mem.c:244)
==10123==    by 0x5AD53E5: ff_frame_thread_init (pthread_frame.c:641)
==10123==    by 0x5B7B5FF: avcodec_open2 (utils.c:1313)
==10123==    by 0x4214D7: transcode_init (ffmpeg.c:2144)
==10123==    by 0x406F8E: main (ffmpeg.c:3413)
==10123== 
==10123== 
==10123== For counts of detected and suppressed errors, rerun with: -v
==10123== Use --history-level=approx or =none to gain increased speed, at
==10123== the cost of reduced accuracy of conflicting-access information
==10123== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2274 from 350)

Attachments (1)

sf.h264 (9.4 KB) - added by Cigaes 4 years ago.

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by Cigaes

comment:1 Changed 4 years ago by cehoyos

I can only reproduce the helgrind output, not the different framecrc output for different thread counts. Is the problem reproducible for you with ./configure && make?

comment:2 Changed 4 years ago by Cigaes

I just checked: with just ./configure I do not get the issue, but it happens with --enable-shared. Thanks for testing.

comment:3 Changed 4 years ago by cehoyos

I tested with ./configure --enable-shared && make but I am still unable to reproduce a different number of output frames between -threads 4 and -threads 5.
Does it make a difference if you run either decoding or encoding with a different number of threads (1)?

comment:4 Changed 4 years ago by Cigaes

It does indeed make a difference:

./ffmpeg_g -threads 5 -i /tmp/sf.h264 -f framecrc -threads 7 -c png -
./ffmpeg_g -threads 5 -i /tmp/sf.h264 -f framecrc -threads 8 -c png -

give respectively:

ffmpeg version N-60813-g44b22bb Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 22 2014 09:46:05 with gcc 4.8 (Debian 4.8.2-15)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libopus --enable-libass --enable-libfreetype --enable-opengl --assert-level=2
  libavutil      52. 65.100 / 52. 65.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  1.103 /  4.  1.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, h264, from '/tmp/sf.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 50 tbc
#software: Lavf55.33.100
#tb 0: 1/25
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Video: png, rgb24, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
0,          0,          0,        1,    14600, 0x4d4b3314
0,          1,          1,        1,    20624, 0x9d04c3da
0,          2,          2,        1,    20373, 0x3224514e
0,          3,          3,        1,    16474, 0x5a53824a
0,          4,          4,        1,    20997, 0xe2ac63ec
0,          5,          5,        1,    21466, 0x3a5edae1
0,          6,          6,        1,    15290, 0x9fb36a83
0,          7,          7,        1,    19601, 0x8af6664a
0,          8,          8,        1,    20217, 0x96032e30
0,          9,          9,        1,    16655, 0x6e0a0985
0,         10,         10,        1,    18492, 0x12b572b4
0,         11,         11,        1,    18118, 0x6b1994d6
frame=   12 fps=0.0 q=0.0 Lsize=       1kB time=00:00:00.48 bitrate=  12.2kbits/s    
video:218kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead -99.671165%
ffmpeg version N-60813-g44b22bb Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 22 2014 09:46:05 with gcc 4.8 (Debian 4.8.2-15)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libopus --enable-libass --enable-libfreetype --enable-opengl --assert-level=2
  libavutil      52. 65.100 / 52. 65.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  1.103 /  4.  1.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, h264, from '/tmp/sf.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv444p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1200k tbn, 50 tbc
#software: Lavf55.33.100
#tb 0: 1/25
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Video: png, rgb24, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> png)
Press [q] to stop, [?] for help
Error while decoding stream #0:0: Invalid data found when processing input
[h264 @ 0x2310680] reference picture missing during reorder
    Last message repeated 1 times
[h264 @ 0x2310680] Missing reference picture, default is 65548
    Last message repeated 1 times
[h264 @ 0x23554c0] reference picture missing during reorder
[h264 @ 0x23554c0] Missing reference picture, default is 65556
0,          0,          0,        1,    14600, 0x4d4b3314
0,          1,          1,        1,    20624, 0x9d04c3da
0,          3,          3,        1,    20373, 0x3224514e
0,          4,          4,        1,    16474, 0x5a53824a
0,          5,          5,        1,    21099, 0x61cb8a88
0,          6,          6,        1,    21466, 0x7d3727ad
0,          8,          8,        1,    15370, 0x4b0bcbbd
0,          9,          9,        1,    19775, 0xed275f1c
0,         10,         10,        1,    16851, 0x0725c06b
0,         11,         11,        1,    16717, 0xd445fc7c
frame=   10 fps=0.0 q=0.0 Lsize=       1kB time=00:00:00.48 bitrate=  10.3kbits/s    
video:179kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead -99.663483%

comment:5 Changed 4 years ago by cehoyos

  • Keywords h264 added

Is this still reproducible?

Note: See TracTickets for help on using tickets.