Opened 8 years ago

Closed 8 years ago

#5397 closed defect (fixed)

Incorrect curves filter work

Reported by: Ilya87 Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: curves
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Summary of the bug: curves video filter provides much darker picture than it should be
How to reproduce:

% ffplay "curves.mkv" -vf curves=r='0.037516/0':g='0.040103/0':b='0.059508/0'

Result - FFmpeg colours are much darker than in Gimp.

ffmpeg version N-79087-gefa98cd
built on x86_64 Arch Linux

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Attachments (11)

ffmpeg_dark.png (331.4 KB ) - added by Ilya87 8 years ago.
ffmpeg version
gimp_as_should_be.png (329.1 KB ) - added by Ilya87 8 years ago.
GIMP version
curves.mkv (437.8 KB ) - added by Ilya87 8 years ago.
Video file to test
curves-gimp-2pts-31.png (26.5 KB ) - added by Clément Bœsch 8 years ago.
Curves Gimp with 2 points (31;0) and (255;255)
curves-ps-2pts-31.png (42.3 KB ) - added by Clément Bœsch 8 years ago.
Curves PS with 2 points (31;0) and (255;255)
curves-gimp-3pts-31.png (26.6 KB ) - added by Clément Bœsch 8 years ago.
Curves Gimp with 3 points (0;0), (31;0) and (255;255)
curves-ps-3pts-31.png (34.1 KB ) - added by Clément Bœsch 8 years ago.
Curves PS with 3 points (0;0), (31;0) and (255;255)
3pts-nz-ffmpeg.png (17.1 KB ) - added by Clément Bœsch 8 years ago.
3 points, not starting at zero, FFmpeg
3pts-nz-gimp.png (24.4 KB ) - added by Clément Bœsch 8 years ago.
3 points, not starting at zero, Gimp
3pts-nz-photoshop.2.png (16.7 KB ) - added by Clément Bœsch 8 years ago.
3 points, not starting at zero, FPhotoshop
3pts-nz-photoshop.png (16.7 KB ) - added by Clément Bœsch 8 years ago.
3 points, not starting at zero, Photoshop

Download all attachments as: .zip

Change History (22)

by Ilya87, 8 years ago

Attachment: ffmpeg_dark.png added

ffmpeg version

by Ilya87, 8 years ago

Attachment: gimp_as_should_be.png added

GIMP version

by Ilya87, 8 years ago

Attachment: curves.mkv added

Video file to test

comment:1 by Ilya87, 8 years ago

Hello, does anyone read this bug report?

comment:2 by Carl Eugen Hoyos, 8 years ago

At least a command line together with complete, uncut console output is missing. Please only use FFplay to report issues if the issue is not reproducible with FFmpeg (the application).

comment:3 by Ilya87, 8 years ago

Ok. Result is the same:

ffmpeg -i "curves.mkv" -pix_fmt yuv420p -vf curves=r='0.037516/0':g='0.040103/0':b='0.059508/0' -c:v libx264 -preset ultrafast -qp 0 output.mkv

ffmpeg version N-79273-gd433623 Copyright (c) 2000-2016 the FFmpeg developers

built with gcc 5.3.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static --enable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-shared --enable-version3 --enable-x11grab
libavutil 55. 20.100 / 55. 20.100
libavcodec 57. 34.100 / 57. 34.100
libavformat 57. 31.100 / 57. 31.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 41.100 / 6. 41.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100

Input #0, matroska,webm, from 'curves.mkv':

Metadata:

ENCODER : Lavf57.28.102

Duration: 00:00:03.42, start: 0.000000, bitrate: 1049 kb/s

Chapter #0:0: start 0.000000, end 2.000000
Metadata:

title : Chapter 01

Stream #0:0(jpn): Video: h264 (High), yuv420p, 720x384 [SAR 1:1 DAR 15:8], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:

title : Encoded by zdzdz
DURATION : 00:00:03.419000000

File 'output.mkv' already exists. Overwrite ? [y/N] y
[libx264 @ 0x5640bff4bb60] using SAR=1/1
[libx264 @ 0x5640bff4bb60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x5640bff4bb60] profile High 4:4:4 Predictive, level 3.0, 4:2:0 8-bit
[libx264 @ 0x5640bff4bb60] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=23 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'output.mkv':

Metadata:

encoder : Lavf57.31.100
Chapter #0:0: start 0.000000, end 2.000000
Metadata:

title : Chapter 01

Stream #0:0(jpn): Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 720x384 [SAR 1:1 DAR 15:8], q=-1--1, 23.98 fps, 1k tbn, 23.98 tbc (default)
Metadata:

title : Encoded by zdzdz
DURATION : 00:00:03.419000000
encoder : Lavc57.34.100 libx264

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))

Press [q] to stop, ? for help
frame= 82 fps=0.0 q=-1.0 Lsize= 4257kB time=00:00:03.42 bitrate=10196.7kbits/s speed= 16x
video:4255kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.035616%
[libx264 @ 0x5640bff4bb60] frame I:1 Avg QP: 0.00 size:154166
[libx264 @ 0x5640bff4bb60] frame P:81 Avg QP: 0.00 size: 51887
[libx264 @ 0x5640bff4bb60] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x5640bff4bb60] mb P I16..4: 5.3% 0.0% 0.0% P16..4: 82.9% 0.0% 0.0% 0.0% 0.0% skip:11.8%
[libx264 @ 0x5640bff4bb60] coded y,uvDC,uvAC intra: 79.5% 73.8% 73.6% inter: 71.3% 75.1% 73.9%
[libx264 @ 0x5640bff4bb60] i16 v,h,dc,p: 59% 38% 2% 1%
[libx264 @ 0x5640bff4bb60] i8c dc,h,v,p: 30% 34% 36% 0%
[libx264 @ 0x5640bff4bb60] kb/s:10191.59

comment:4 by Ilya87, 8 years ago

Last edited 8 years ago by Ilya87 (previous) (diff)

comment:5 by Ilya87, 8 years ago

Last edited 8 years ago by Ilya87 (previous) (diff)

comment:6 by Ilya87, 8 years ago

Ping

comment:7 by Elon Musk, 8 years ago

Consider adding bounty if you want to have better pong.

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

Analyzed by developer: set
Reproduced by developer: set
Status: newopen

A patch can be found at http://ffmpeg.org/pipermail/ffmpeg-devel/2016-July/196740.html

Note that the curves in Gimp and Photoshop doesn't behave the same at all.

After the patch is applied, in order to get a close behavior to what you expect, you will have to use something like -vf curves=r='0.037516/0 1/1':g='0.040103/0 1/1':b='0.059508/0 1/1'. If you define points in (0;0) (-vf curves=r='0/0 0.037516/0 1/1':g='0/0 0.040103/0 1/1':b='0/0 0.059508/0 1/1'), the curves will be much curvy at the origin and you will get your unexpected darker output. This doesn't happen in Gimp but is closer to what you observe in Photoshop. I will attach screenshot of Gimp and PS to show this.

Edit: see in particular curves-ps-3pts-31.png vs curves-gimp-3pts-31.png. To mimic Gimp behaviour, you will have to use 2 points instead of 3, see curves-ps-2pts-31.png vs curves-gimp-2pts-31.png

Last edited 8 years ago by Clément Bœsch (previous) (diff)

by Clément Bœsch, 8 years ago

Attachment: curves-gimp-2pts-31.png added

Curves Gimp with 2 points (31;0) and (255;255)

by Clément Bœsch, 8 years ago

Attachment: curves-ps-2pts-31.png added

Curves PS with 2 points (31;0) and (255;255)

by Clément Bœsch, 8 years ago

Attachment: curves-gimp-3pts-31.png added

Curves Gimp with 3 points (0;0), (31;0) and (255;255)

by Clément Bœsch, 8 years ago

Attachment: curves-ps-3pts-31.png added

Curves PS with 3 points (0;0), (31;0) and (255;255)

comment:9 by Ilya87, 8 years ago

And what if I define not only 2 points (start point 0.037516/0 and 1/1) on channel, but more? For example,

-vf curves=r='0.037516/0 0.127516/0.4 1/1'

Will it work in Gimp-style?

in reply to:  9 comment:10 by Clément Bœsch, 8 years ago

Replying to Ilya87:

And what if I define not only 2 points (start point 0.037516/0 and 1/1) on channel, but more? For example,

-vf curves=r='0.037516/0 0.127516/0.4 1/1'

Will it work in Gimp-style?

Unfortunately no. It matches Photoshop behavior. I'm attaching 3 new images so you can compare the 3 tools. But basically, you can assume FFmpeg always matches Photoshop.

Also, you can try this branch: https://github.com/ubitux/FFmpeg/compare/curves (note to future reader: if this branch doesn't exist anymore, it's probably merged upstream).

Commit 2/2 of this branch adds a "plot" option you can use to get the curves used by FFmpeg. Quoting the example from the documentation:

ffmpeg -f lavfi -i color -vf curves=cross_process:plot=/tmp/curves.plt -frames:v 1 -f null -
gnuplot -p /tmp/curves.plt

by Clément Bœsch, 8 years ago

Attachment: 3pts-nz-ffmpeg.png added

3 points, not starting at zero, FFmpeg

by Clément Bœsch, 8 years ago

Attachment: 3pts-nz-gimp.png added

3 points, not starting at zero, Gimp

by Clément Bœsch, 8 years ago

Attachment: 3pts-nz-photoshop.2.png added

3 points, not starting at zero, FPhotoshop

by Clément Bœsch, 8 years ago

Attachment: 3pts-nz-photoshop.png added

3 points, not starting at zero, Photoshop

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

Resolution: fixed
Status: openclosed

Fixed in 5c14018fc4f6ae9fcce7eaf8dd2d66cb6fbfc7bc

Plot option added in 4a8f5f1fd83dfa92e02901e543d79124c4e551dc

(Bonus 16-bit support in e30cdac14b55ef290e26e055a88055ba9cde2f46)

Thanks for the report.

Note: See TracTickets for help on using tickets.