georgmartius / vid.stab

Video stabilization library
http://public.hronopik.de/vid.stab/
Other
842 stars 108 forks source link

Fix underflows causing white pixels when processing full range formats #51

Closed TouchMonkey closed 6 years ago

TouchMonkey commented 6 years ago

Feeding a full-range pixel format (e.g. YUVJ*) to vid.stab without converting to standard 16-255 YUV can cause bright pixels in dark areas due to underflow causing a slightly negative value to becomes a very large value when cast to uint8.

Adding these checks allows processing of modern camera files, GoPro etc, without requiring FFMPEG to insert a pre- and post-scale filter that converts the Y ranges from 0-255 to 16-255 and back again, losing definition in the process. Most users won't even be aware this is happening because FFMPEG does it without prompting.

This also makes it less likely to end up with washed-out black levels when encoding the output of YUVJ input files to YUV. The auto-scaler filters loses track of the color range and space when converting to standard YUV.

To actually test this in FFMPEG you need to have a version with a patched vf_vidstabdetect filter, vf_vidstabtransform filter, and vidstabutils. I have a branch with the required changes at https://github.com/TouchMonkey/FFmpeg/tree/vidstab_full_range.