Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#4000 closed defect (invalid)

mpeg4: Magenta color shift in first GOP

Reported by: ErikCJohansson Owned by:
Priority: normal Component: avcodec
Version: unspecified Keywords: asp
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

I am encoding a specific repeated DPX still frame to mpeg4 in a MOV container. The first frame, frame 0, looks ok. Frames 1-11 have a slight magenta color shift. Frame 12 onwards looks good again. It appears as though the encoder does a poor job of the first GOP compared to subsequent GOPs.

The problem seems to be triggered by the attached frame, other input images work ok.

ffmpeg started on 2014-10-03 at 08:21:02
Report written to "ffmpeg-20141003-082102.log"
Command line:
./ffmpeg -v 9 -loglevel 99 -i "/mnt/pickles/media/images1/dpx/still_sequence/legal%03d.dpx" -vcodec mpeg4 -frames 30 -report ../first_gop_mangenta.mov
ffmpeg version N-66581-g105654e Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct  3 2014 08:07:25 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-3)
  configuration: 
  libavutil      54.  9.100 / 54.  9.100
  libavcodec     56.  2.101 / 56.  2.101
  libavformat    56.  7.102 / 56.  7.102
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.102 /  5.  1.102
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input file with argument '/mnt/pickles/media/images1/dpx/still_sequence/legal%03d.dpx'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'mpeg4'.
Reading option '-frames' ... matched as option 'frames' (set the number of frames to record) with argument '30'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '../first_gop_mangenta.mov' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Applying option loglevel (set logging level) with argument 99.
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file /mnt/pickles/media/images1/dpx/still_sequence/legal%03d.dpx.
Successfully parsed a group of options.
Opening an input file: /mnt/pickles/media/images1/dpx/still_sequence/legal%03d.dpx.
[AVIOContext @ 0x2532960] Statistics: 8296448 bytes read, 0 seeks
[image2 @ 0x253b4c0] Probe buffer size limit of 5000000 bytes reached
Input #0, image2, from '/mnt/pickles/media/images1/dpx/still_sequence/legal%03d.dpx':
  Duration: 00:00:12.00, start: 0.000000, bitrate: N/A
    Stream #0:0, 1, 1/25: Video: dpx, gbrp10le, 1920x1080, 125/2997, 23.98 tbr, 25 tbn, 23.98 tbc
Successfully opened the file.
Parsing a group of options: output file ../first_gop_mangenta.mov.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument mpeg4.
Applying option frames (set the number of frames to record) with argument 30.
Successfully parsed a group of options.
Opening an output file: ../first_gop_mangenta.mov.
Successfully opened the file.
detected 2 logical cores
[graph 0 input from stream 0:0 @ 0x2532700] Setting 'video_size' to value '1920x1080'
[graph 0 input from stream 0:0 @ 0x2532700] Setting 'pix_fmt' to value '86'
[graph 0 input from stream 0:0 @ 0x2532700] Setting 'time_base' to value '1/25'
[graph 0 input from stream 0:0 @ 0x2532700] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x2532700] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x2532700] Setting 'frame_rate' to value '2997/125'
[graph 0 input from stream 0:0 @ 0x2532700] w:1920 h:1080 pixfmt:gbrp10le tb:1/25 fr:2997/125 sar:0/1 sws_param:flags=2
[format @ 0x2532ca0] compat: called with args=[yuv420p]
[format @ 0x2532ca0] Setting 'pix_fmts' to value 'yuv420p'
[auto-inserted scaler 0 @ 0x2523040] Setting 'flags' to value '0x4'
[auto-inserted scaler 0 @ 0x2523040] w:iw h:ih flags:'0x4' interl:0
[format @ 0x2532ca0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed_null_0' and the filter 'format'
[AVFilterGraph @ 0x25327e0] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
[auto-inserted scaler 0 @ 0x2523040] w:1920 h:1080 fmt:gbrp10le sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0x4
[mpeg4 @ 0x253e360] intra_quant_bias = 0 inter_quant_bias = -64
Output #0, mov, to '../first_gop_mangenta.mov':
  Metadata:
    encoder         : Lavf56.7.102
    Stream #0:0, 0, 1/11988: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 1920x1080, 125/2997, q=2-31, 200 kb/s, 23.98 fps, 11988 tbn, 23.98 tbc
    Metadata:
      encoder         : Lavc56.2.101 mpeg4
Stream mapping:
  Stream #0:0 -> #0:0 (dpx (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[AVIOContext @ 0x3ffbbe0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e62de0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffccc0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e638a0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffcbe0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b10320] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffd020] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b10360] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e631a0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b0fc80] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffc880] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b10600] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b106e0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e63420] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b0fd20] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffc8a0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e63580] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffc520] Statistics: 8296448 bytes read, 0 seeks
frame=   19 fps=0.0 q=2.3 size=     146kB time=00:00:00.79 bitrate=1504.5kbits/s    
[AVIOContext @ 0x3e634c0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffcde0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffc7c0] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e63820] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffc840] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e63140] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e63000] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b10380] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x2b10460] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3ffc960] Statistics: 8296448 bytes read, 0 seeks
[AVIOContext @ 0x3e62fe0] Statistics: 8296448 bytes read, 0 seeks
No more output streams to write to, finishing.
frame=   30 fps=0.0 q=4.6 Lsize=     220kB time=00:00:01.25 bitrate=1438.6kbits/s    
video:219kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.427581%
Input file #0 (/mnt/pickles/media/images1/dpx/still_sequence/legal%03d.dpx):
  Input stream #0:0 (video): 30 packets read (248893440 bytes); 30 frames decoded; 
  Total: 30 packets (248893440 bytes) demuxed
Output file #0 (../first_gop_mangenta.mov):
  Output stream #0:0 (video): 30 frames encoded; 30 packets muxed (224051 bytes); 
  Total: 30 packets (224051 bytes) muxed
30 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x253ad20] Statistics: 36 seeks, 61 writeouts

Attachments (7)

legal000.dpx.bz2 (293.8 KB) - added by ErikCJohansson 5 years ago.
frame0.tif (2.1 MB) - added by cehoyos 5 years ago.
frame1.tif (2.1 MB) - added by cehoyos 5 years ago.
source frame histogram.png (20.8 KB) - added by ErikCJohansson 5 years ago.
frame 0 histogram.png (24.7 KB) - added by ErikCJohansson 5 years ago.
frame 1 histogram.png (23.8 KB) - added by ErikCJohansson 5 years ago.
libswscale histogram.png (23.1 KB) - added by ErikCJohansson 5 years ago.

Change History (16)

Changed 5 years ago by ErikCJohansson

Changed 5 years ago by cehoyos

Changed 5 years ago by cehoyos

comment:1 follow-up: Changed 5 years ago by cehoyos

I have attached frame 0 and frame 1.
How can I reproduce that frame 1 has a magenta colour shift?

comment:2 in reply to: ↑ 1 ; follow-ups: Changed 5 years ago by ErikCJohansson

How can I reproduce that frame 1 has a magenta colour shift?

Depending on your display you can see the shift in the ramps when flipping between the frames. Looking at the histograms, you can see the shift in the higher range, but seems ok in the lower range. I will attach histogram plots of the source image as well as your two samples.

Thanks

Changed 5 years ago by ErikCJohansson

Changed 5 years ago by ErikCJohansson

Changed 5 years ago by ErikCJohansson

comment:3 in reply to: ↑ 2 ; follow-up: Changed 5 years ago by cehoyos

Replying to ErikCJohansson:

Looking at the histograms, you can see the shift in the higher range, but seems ok in the lower range. I will attach histogram plots of the source image as well as your two samples.

How can I see in the histogram plots that frame 1 has a higher magenta colour shift than frame 0?

comment:4 in reply to: ↑ 2 Changed 5 years ago by cehoyos

Replying to ErikCJohansson:

I will attach histogram plots of the source image

How did you produce this histogram? Did you use libswscale (FFmpeg) for the colour space conversion?

comment:5 in reply to: ↑ 3 ; follow-up: Changed 5 years ago by ErikCJohansson

How can I see in the histogram plots that frame 1 has a higher magenta colour shift than frame 0?

The histogram each consists of three curves, one for each of R, G and B. They are color coded as you would expect. In the histogram of the source frame and frame 0, the peak around 900 has three separate peaks - one for each of the plotted colors. In the histogram for frame 1 the blue and red curves have been shifted to the right.

How did you produce this histogram? Did you use libswscale (FFmpeg) for the colour space conversion?

I used Baselight (www.filmlight.ltd.uk), libswscale not involved.

comment:6 in reply to: ↑ 5 Changed 5 years ago by cehoyos

Replying to ErikCJohansson:

How did you produce this histogram? Did you use libswscale (FFmpeg) for the colour space conversion?

I used Baselight (www.filmlight.ltd.uk), libswscale not involved.

This is less useful imo since you used libswscale in your original command line.
Either use a yuv420p source image (and provide the histrogram for this image) or provide the histogram for the output of libswscale.

comment:7 Changed 5 years ago by ErikCJohansson

If I understand correctly, I've extracted the output of the libswscale conversion as per below. Will attach the histogram which has a distinct magenta shift, it's a bit rough around the edges since it uses a naive reconstruction from 420 to 444. Now I'm intrigued how the codec can perform so well on frames 0,12-

ffmpeg started on 2014-10-03 at 11:11:41
Report written to "ffmpeg-20141003-111141.log"
Command line:
./ffmpeg -i /mnt/pickles/media/images1/dpx/legal0.dpx -vcodec rawvideo -pix_fmt yuv420p -report ../testyuv420p.yuv
ffmpeg version N-66581-g105654e Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct  3 2014 08:07:25 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-3)
  configuration: 
  libavutil      54.  9.100 / 54.  9.100
  libavcodec     56.  2.101 / 56.  2.101
  libavformat    56.  7.102 / 56.  7.102
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.102 /  5.  1.102
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
Splitting the commandline.
Reading option '-i' ... matched as input file with argument '/mnt/pickles/media/images1/dpx/legal0.dpx'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'rawvideo'.
Reading option '-pix_fmt' ... matched as option 'pix_fmt' (set pixel format) with argument 'yuv420p'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '../testyuv420p.yuv' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file /mnt/pickles/media/images1/dpx/legal0.dpx.
Successfully parsed a group of options.
Opening an input file: /mnt/pickles/media/images1/dpx/legal0.dpx.
[dpx_pipe @ 0x327b4e0] Format dpx_pipe probed with size=2048 and score=51
[dpx_pipe @ 0x327b4e0] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0
[dpx_pipe @ 0x327b4e0] Probe buffer size limit of 5000000 bytes reached
[dpx_pipe @ 0x327b4e0] Stream #0: not enough frames to estimate rate; consider increasing probesize
[dpx_pipe @ 0x327b4e0] After avformat_find_stream_info() pos: 8296448 bytes read:8296448 seeks:0 frames:1
Input #0, dpx_pipe, from '/mnt/pickles/media/images1/dpx/legal0.dpx':
  Duration: N/A, bitrate: N/A
    Stream #0:0, 1, 1/25: Video: dpx, gbrp10le, 1920x1080, 23.98 tbr, 25 tbn, 23.98 tbc
Successfully opened the file.
Parsing a group of options: output file ../testyuv420p.yuv.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument rawvideo.
Applying option pix_fmt (set pixel format) with argument yuv420p.
Successfully parsed a group of options.
Opening an output file: ../testyuv420p.yuv.
Successfully opened the file.
detected 2 logical cores
[graph 0 input from stream 0:0 @ 0x327aec0] Setting 'video_size' to value '1920x1080'
[graph 0 input from stream 0:0 @ 0x327aec0] Setting 'pix_fmt' to value '86'
[graph 0 input from stream 0:0 @ 0x327aec0] Setting 'time_base' to value '1/25'
[graph 0 input from stream 0:0 @ 0x327aec0] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x327aec0] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x327aec0] Setting 'frame_rate' to value '2997/125'
[graph 0 input from stream 0:0 @ 0x327aec0] w:1920 h:1080 pixfmt:gbrp10le tb:1/25 fr:2997/125 sar:0/1 sws_param:flags=2
[format @ 0x327e440] compat: called with args=[yuv420p]
[format @ 0x327e440] Setting 'pix_fmts' to value 'yuv420p'
[auto-inserted scaler 0 @ 0x327efc0] Setting 'flags' to value '0x4'
[auto-inserted scaler 0 @ 0x327efc0] w:iw h:ih flags:'0x4' interl:0
[format @ 0x327e440] auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed_null_0' and the filter 'format'
[AVFilterGraph @ 0x326a5c0] query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
[auto-inserted scaler 0 @ 0x327efc0] w:1920 h:1080 fmt:gbrp10le sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0x4
Output #0, rawvideo, to '../testyuv420p.yuv':
  Metadata:
    encoder         : Lavf56.7.102
    Stream #0:0, 0, 125/2997: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc
    Metadata:
      encoder         : Lavc56.2.101 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (dpx (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[output stream 0:0 @ 0x326a3c0] EOF on sink link output stream 0:0:default.
No more output streams to write to, finishing.
frame=    1 fps=0.0 q=0.0 Lsize=    3038kB time=00:00:00.04 bitrate=596605.0kbits/s    
video:3038kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
Input file #0 (/mnt/pickles/media/images1/dpx/legal0.dpx):
  Input stream #0:0 (video): 1 packets read (8296448 bytes); 1 frames decoded; 
  Total: 1 packets (8296448 bytes) demuxed
Output file #0 (../testyuv420p.yuv):
  Output stream #0:0 (video): 1 frames encoded; 1 packets muxed (3110400 bytes); 
  Total: 1 packets (3110400 bytes) muxed
1 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x327e260] Statistics: 0 seeks, 95 writeouts
[AVIOContext @ 0x327a720] Statistics: 8296448 bytes read, 0 seeks

Changed 5 years ago by ErikCJohansson

comment:8 Changed 5 years ago by michael

  • Reproduced by developer set
  • Resolution set to invalid
  • Status changed from new to closed

MPEG* is lossy compression, the magenta is the result of that in this case.
you can use a higher bitrate like with -b 10M -rc_init_cplx 1000 or force a lower quantizer to avoid this. There are also probably a few other options. It affects just the first frames because the rate control code lacks information at the begin and thus makes different decissions

comment:9 Changed 5 years ago by cehoyos

  • Component changed from undetermined to avcodec
  • Keywords asp added
Note: See TracTickets for help on using tickets.