Opened 12 years ago

Closed 12 years ago

#1705 closed defect (invalid)

Wrong pixel format for overlay

Reported by: jwjwjw Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: overlay
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

The overlay filter uses an intermediate yuv420p pixel format regardless of the input format, format of the overlay, and intended output format. This can be demonstrated by using an RGBA overlay graphic in a small-ish font with a saturated colour on top of an RGB24 input file which is output also using RGB24. The resulting file shows the telltale signs of 4:2:0 chrominance loss despite using RGB in all stages of the chain.

Both commands below produce the same output:

ffmpeg -i background.png -i overlay.png -filter_complex "overlay=0:0" -pix_fmt rgb24 output.png

ffmpeg -i background.png -vf "movie=overlay.png [movie]; [in] [movie] overlay=0:0 [out]" -pix_fmt rgb24 output.png

How to reproduce:

ffmpeg -i background.png -vf "movie=overlay.png [movie]; [in] [movie] overlay=0:0 [out]" -pix_fmt rgb24 output.png
ffmpeg version N-43973-g028b6d2b Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug 31 2012 06:26:09 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-libdc1394 --prefix=/usr --extra-cflags='-Wall -g ' --enable-shared --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-avfilter --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-libvpx --extra-libs=-lgcrypt --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
  libavutil      51. 70.100 / 51. 70.100
  libavcodec     54. 54.100 / 54. 54.100
  libavformat    54. 25.104 / 54. 25.104
  libavdevice    54.  2.100 / 54.  2.100
  libavfilter     3. 14.100 /  3. 14.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[AVIOContext @ 0x1ad77c0] Statistics: 4205 bytes read, 0 seeks
Input #0, image2, from 'background.png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0:0, 1, 1/25: Video: png, rgb24, 640x360, 25 tbr, 25 tbn, 25 tbc
[AVIOContext @ 0x1acca60] Statistics: 5980 bytes read, 0 seeks
[Parsed_movie_0 @ 0x1acfe00] seek_point:0 format_name:(null) file_name:overlay.png stream_index:-1
[buffer @ 0x1acccc0] Setting entry with key 'video_size' to value '640x360'
[buffer @ 0x1acccc0] Setting entry with key 'pix_fmt' to value '28'
[buffer @ 0x1acccc0] Setting entry with key 'time_base' to value '1/25'
[buffer @ 0x1acccc0] Setting entry with key 'pixel_aspect' to value '0/1'
[buffer @ 0x1acccc0] Setting entry with key 'sws_param' to value 'flags=2'
[buffer @ 0x1acccc0] Setting entry with key 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0x1accec0] w:640 h:360 pixfmt:rgba tb:1/25 fr:25/1 sar:0/1 sws_param:flags=2
[Parsed_overlay_1 @ 0x1accf80] auto-inserting filter 'auto-inserted scaler 0' between the filter 'graph 0 input from stream 0:0' and the filter 'Parsed_overlay_1'
[Parsed_overlay_1 @ 0x1accf80] auto-inserting filter 'auto-inserted scaler 1' between the filter 'Parsed_movie_0' and the filter 'Parsed_overlay_1'
[format @ 0x1ad78c0] auto-inserting filter 'auto-inserted scaler 2' between the filter 'Parsed_overlay_1' and the filter 'format'
[auto-inserted scaler 0 @ 0x1ad6b40] w:640 h:360 fmt:rgba sar:0/1 -> w:640 h:360 fmt:yuv420p sar:0/1 flags:0x4
[auto-inserted scaler 1 @ 0x1ad97c0] w:640 h:360 fmt:rgba sar:1/1 -> w:640 h:360 fmt:yuva420p sar:1/1 flags:0x4
[Parsed_overlay_1 @ 0x1accf80] main w:640 h:360 fmt:yuv420p overlay x:0 y:0 w:640 h:360 fmt:yuva420p
[Parsed_overlay_1 @ 0x1accf80] main_tb:1/25 overlay_tb:1/25 -> tb:1/25 exact:1
[auto-inserted scaler 2 @ 0x1ad8620] w:640 h:360 fmt:yuv420p sar:0/1 -> w:640 h:360 fmt:rgb24 sar:0/1 flags:0x4
Output #0, image2, to 'output.png':
  Metadata:
    encoder         : Lavf54.25.104
    Stream #0:0, 0, 1/90000: Video: png, rgb24, 640x360, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png -> png)
Press [q] to stop, [?] for help
[output stream 0:0 @ 0x1ad6fc0] 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=       0kB time=00:00:00.04 bitrate=   0.0kbits/s    

video:2kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000000%

Attachments (3)

background.png (750 bytes ) - added by jwjwjw 12 years ago.
overlay.png (5.8 KB ) - added by jwjwjw 12 years ago.
output.png (2.3 KB ) - added by jwjwjw 12 years ago.

Download all attachments as: .zip

Change History (4)

by jwjwjw, 12 years ago

Attachment: background.png added

by jwjwjw, 12 years ago

Attachment: overlay.png added

by jwjwjw, 12 years ago

Attachment: output.png added

comment:1 by Carl Eugen Hoyos, 12 years ago

Component: undeterminedavfilter
Keywords: overlay added
Resolution: invalid
Status: newclosed
Version: unspecifiedgit-master

(Did you RTFM?)
There is an option for the overlay filter called "rgb" that I believe does exactly what you want.

Please reopen the ticket if I misunderstood.

Note: See TracTickets for help on using tickets.