Opened 8 years ago

Closed 7 years ago

#5458 closed defect (fixed)

Race condition in H.264 decoder causes corrupt output with more than one thread

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

Description

Summary of the bug:

The file located here has non-deterministic and corrupt output when using more than 1 thread to decode. This occurs with FFmpeg git master. It seems to only happen with frame threading.

How to reproduce:

ffmpeg -threads N -i nondeterministic.mp4 -f md5 -

where N is greater than 1.

Example output of three runs with threads=1:

MD5=0dabc8164d94a75c685252bbcdd17e90
MD5=0dabc8164d94a75c685252bbcdd17e90
MD5=0dabc8164d94a75c685252bbcdd17e90

Example output of three runs with threads=32:

MD5=4ba1eb94c5dd616a3a9ec23b4e7795d2
MD5=9fa806851c71df1fe7a32a123288b80d
MD5=35ae4fc9806cd5cc26042efa4e407692

Visual corruption can be seen.

For good measure, he is full output of ffmpeg -threads 1 -i nondeterministic.mp4 -an -f null -:

daemon404@bbvm:~/dev/f/ffmpeg$ ./ffmpeg -threads 1 -i nondeterministic.mp4 -an -f md5 -
ffmpeg version N-79565-g656b07b Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.1 (Debian 5.3.1-14) 20160409
  configuration:
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 37.100 / 57. 37.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'nondeterministic.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    creation_time   : 2016-03-11 22:42:03
  Duration: 00:10:06.36, start: 0.000000, bitrate: 3678 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1440x1080 [SAR 1:1 DAR 4:3], 3518 kb/s, 30.30 fps, 30.30 tbr, 30303 tbn (default)
    Metadata:
      creation_time   : 2016-03-11 22:42:03
      handler_name    : VideoHandler
      encoder         : AVC Coding
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 157 kb/s (default)
    Metadata:
      creation_time   : 2016-03-11 22:42:03
      handler_name    : SoundHandler
[md5 @ 0x3f3ae40] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, md5, to 'pipe:':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    encoder         : Lavf57.34.103
    Stream #0:0(und): Video: rawvideo (I420 / 0x30323449), yuv420p, 1440x1080 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30.30 fps, 30.30 tbn (default)
    Metadata:
      creation_time   : 2016-03-11 22:42:03
      handler_name    : VideoHandler
      encoder         : Lavc57.37.100 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
frame=18346 fps=107 q=-0.0 Lsize=       0kB time=00:10:06.34 bitrate=   0.0kbits/s speed=3.55x
video:41794481kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Attachments (5)

nd-8t-run0.txt.gz (950.5 KB ) - added by Clément Bœsch 8 years ago.
nd-8t-run1.txt.gz (950.5 KB ) - added by Clément Bœsch 8 years ago.
nd-8t-run2.txt.gz (950.4 KB ) - added by Clément Bœsch 8 years ago.
nd-8t-run3.txt.gz (950.4 KB ) - added by Clément Bœsch 8 years ago.
nondeterministic_cut.h264 (127.4 KB ) - added by Carl Eugen Hoyos 8 years ago.

Change History (8)

by Clément Bœsch, 8 years ago

Attachment: nd-8t-run0.txt.gz added

by Clément Bœsch, 8 years ago

Attachment: nd-8t-run1.txt.gz added

by Clément Bœsch, 8 years ago

Attachment: nd-8t-run2.txt.gz added

by Clément Bœsch, 8 years ago

Attachment: nd-8t-run3.txt.gz added

comment:1 by Clément Bœsch, 8 years ago

Attached a few runs showing up what specific frames are problematic.

comment:2 by Carl Eugen Hoyos, 8 years ago

JM19 indicates that the video stream is damaged.

$ ffmpeg -threads 8 -i nondeterministic_cut.h264 -f framecrc -
ffmpeg version N-79584-g7b7c338 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 38.100 / 57. 38.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, h264, from 'nondeterministic_cut.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1440x1080 [SAR 1:1 DAR 4:3], 25 fps, 30 tbr, 1200k tbn
[framecrc @ 0x3dff680] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
#software: Lavf57.34.103
#tb 0: 1/30
#media_type 0: video
#codec_id 0: rawvideo
#dimensions 0: 1440x1080
#sar 0: 1/1
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf57.34.103
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1440x1080 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30 fps, 30 tbn
    Metadata:
      encoder         : Lavc57.38.100 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
0,          0,          0,        1,  2332800, 0x009dacb8
0,          1,          1,        1,  2332800, 0xb1e50764
0,          2,          2,        1,  2332800, 0xe29481e0
0,          3,          3,        1,  2332800, 0x0b1b4de4
0,          4,          4,        1,  2332800, 0x726a644c
0,          5,          5,        1,  2332800, 0x7a09c4a5
0,          6,          6,        1,  2332800, 0x2e9059ea
0,          7,          7,        1,  2332800, 0x52071fdc
0,          8,          8,        1,  2332800, 0x4fa00417
0,          9,          9,        1,  2332800, 0x6037fb4d
0,         10,         10,        1,  2332800, 0x887ffae2
0,         11,         11,        1,  2332800, 0x887ffae2
0,         12,         12,        1,  2332800, 0x3e6e0cb8
0,         13,         13,        1,  2332800, 0x3e6e0cb8
0,         14,         14,        1,  2332800, 0x3e6e0cb8
0,         15,         15,        1,  2332800, 0x3e6e0cb8
0,         16,         16,        1,  2332800, 0x3e6e0cb8
0,         17,         17,        1,  2332800, 0x3e6e0cb8
0,         18,         18,        1,  2332800, 0x3e6e0cb8
0,         19,         19,        1,  2332800, 0x3e6e0cb8
0,         20,         20,        1,  2332800, 0x3e6e0cb8
0,         21,         21,        1,  2332800, 0x3e6e0cb8
0,         22,         22,        1,  2332800, 0x3e6e0cb8
0,         23,         23,        1,  2332800, 0x3e6e0cb8
0,         24,         24,        1,  2332800, 0x3e6e0cb8
0,         25,         25,        1,  2332800, 0x3e6e0cb8
0,         26,         26,        1,  2332800, 0x3e6e0cb8
0,         27,         27,        1,  2332800, 0x3e6e0cb8
0,         28,         28,        1,  2332800, 0x3e6e0cb8
0,         29,         29,        1,  2332800, 0x824bb91b
frame=   30 fps=0.0 q=-0.0 Lsize=       2kB time=00:00:01.00 bitrate=  14.9kbits/s speed=23.8x
video:68344kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
$ ffmpeg -threads 8 -i nondeterministic_cut.h264 -f framecrc -
ffmpeg version N-79584-g7b7c338 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 38.100 / 57. 38.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, h264, from 'nondeterministic_cut.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1440x1080 [SAR 1:1 DAR 4:3], 25 fps, 30 tbr, 1200k tbn
[framecrc @ 0x3976680] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
#software: Lavf57.34.103
#tb 0: 1/30
#media_type 0: video
#codec_id 0: rawvideo
#dimensions 0: 1440x1080
#sar 0: 1/1
Output #0, framecrc, to 'pipe:':
  Metadata:
    encoder         : Lavf57.34.103
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1440x1080 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30 fps, 30 tbn
    Metadata:
      encoder         : Lavc57.38.100 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
0,          0,          0,        1,  2332800, 0x009dacb8
0,          1,          1,        1,  2332800, 0xb1e50764
0,          2,          2,        1,  2332800, 0xe29481e0
0,          3,          3,        1,  2332800, 0x0b1b4de4
0,          4,          4,        1,  2332800, 0x726a644c
0,          5,          5,        1,  2332800, 0x7a09c4a5
0,          6,          6,        1,  2332800, 0x2e9059ea
0,          7,          7,        1,  2332800, 0x52071fdc
0,          8,          8,        1,  2332800, 0x4fa00417
0,          9,          9,        1,  2332800, 0x6037fb4d
0,         10,         10,        1,  2332800, 0x887ffae2
0,         11,         11,        1,  2332800, 0x887ffae2
0,         12,         12,        1,  2332800, 0xc8ed909d
0,         13,         13,        1,  2332800, 0xc8ed909d
0,         14,         14,        1,  2332800, 0xc8ed909d
0,         15,         15,        1,  2332800, 0xc8ed909d
0,         16,         16,        1,  2332800, 0xc8ed909d
0,         17,         17,        1,  2332800, 0xc8ed909d
0,         18,         18,        1,  2332800, 0xc8ed909d
0,         19,         19,        1,  2332800, 0xc8ed909d
0,         20,         20,        1,  2332800, 0xc8ed909d
0,         21,         21,        1,  2332800, 0xc8ed909d
0,         22,         22,        1,  2332800, 0xc8ed909d
0,         23,         23,        1,  2332800, 0xc8ed909d
0,         24,         24,        1,  2332800, 0xc8ed909d
0,         25,         25,        1,  2332800, 0xc8ed909d
0,         26,         26,        1,  2332800, 0xc8ed909d
0,         27,         27,        1,  2332800, 0xc8ed909d
0,         28,         28,        1,  2332800, 0xc8ed909d
0,         29,         29,        1,  2332800, 0x824bb91b
frame=   30 fps=0.0 q=-0.0 Lsize=       2kB time=00:00:01.00 bitrate=  14.9kbits/s speed=22.8x
video:68344kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

by Carl Eugen Hoyos, 8 years ago

Attachment: nondeterministic_cut.h264 added

comment:3 by Carl Eugen Hoyos, 7 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.