Video import/export via FFmpeg: Poor-quality color conversion causes banding #52697

Closed
opened 2017-09-10 04:40:12 +02:00 by Martin Herkt · 9 comments

System Information
openSUSE Tumbleweed

Blender Version
Git, 11a9434c2d

Blender’s video import/export through FFmpeg suffers from swscale’s poor-quality color conversion. Anything involving YUV and RGB will result in ugly banding artifacts due to large error. The only way to mitigate this within FFmpeg is by inserting the zscale filter before the format conversion, and choosing an appropriate dithering algorithm with it. However, this relies on a separate library (libzimg) that is neither compiled into FFmpeg by default nor packaged by many Linux distributions.

Since most output formats only support YUV color spaces, something needs to be done about that as well. For conversion from RGB to YUV, however, it is required to explicitly set at least the colormatrix for zscale (an explicit setting would be a good thing in general). I’m not even sure how Blender handles this right now. FFmpeg might default to Rec. 601, which would be quite bad and result in outright wrong colors during playback if the stream isn’t tagged appropriately but triggers resolution-based heuristics in playback software.

Blender could of course also use libzimg internally to do the conversion for FFmpeg. Maybe that’s easier to support. I’m not sure if there are additional formats available that way, but maybe it could directly convert to something useful to Blender (e. g. high-precision float RGB) to reduce the error.

**System Information** openSUSE Tumbleweed **Blender Version** Git, 11a9434c2de Blender’s video import/export through FFmpeg suffers from swscale’s poor-quality color conversion. Anything involving YUV and RGB will result in ugly banding artifacts due to large error. The only way to mitigate this within FFmpeg is by inserting the zscale filter before the format conversion, and choosing an appropriate dithering algorithm with it. However, this relies on a separate library (libzimg) that is neither compiled into FFmpeg by default nor packaged by many Linux distributions. Since most output formats only support YUV color spaces, something needs to be done about that as well. For conversion from RGB to YUV, however, it is required to explicitly set at least the colormatrix for zscale (an explicit setting would be a good thing in general). I’m not even sure how Blender handles this right now. FFmpeg might default to Rec. 601, which would be quite bad and result in outright wrong colors during playback if the stream isn’t tagged appropriately but triggers resolution-based heuristics in playback software. Blender could of course also use libzimg internally to do the conversion for FFmpeg. Maybe that’s easier to support. I’m not sure if there are additional formats available that way, but maybe it could directly convert to something useful to Blender (e. g. high-precision float RGB) to reduce the error.
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @lachs0r-1

Added subscriber: @lachs0r-1
Author

Just confirmed that FFmpeg defaults to Rec. 601. Bad. This needs a selection on import (defaulting to “Auto”, which should apply the same resolution-based heuristics as video players for untagged files, i.e. use 709 with HD resolutions) and export (should autoselect based on render resolution and also mark the colorspace appropriately in the resulting file—no idea what the API is for that on lavf’s side).

Just confirmed that FFmpeg defaults to Rec. 601. Bad. This needs a selection on import (defaulting to “Auto”, which should apply the same resolution-based heuristics as video players for untagged files, i.e. use 709 with HD resolutions) and export (should autoselect based on render resolution and also mark the colorspace appropriately in the resulting file—no idea what the API is for that on lavf’s side).

Added subscriber: @SteffenD

Added subscriber: @SteffenD
Author

FYI: For now I’m preprocessing the input by converting to 24-bit RGB before importing into Blender, but that clearly isn’t enough most of the time. Even 8-bit (per channel) YUV can only be used with heavy dithering, and e. g. 10-bit input (which is getting increasingly common) loses way too much precision. Given FFmpeg’s rather awkward pixfmt support (owing to swscale legacy), it seems like using libzimg directly is the best option.

Makes me wish mpv’s OpenGL renderer were its own library, could do arbitrary conversions (not just to RGB) and supported offscreen rendering. Maybe in some distant future (the topic has been brought up in the devel channel a few times)…

FYI: For now I’m preprocessing the input by converting to 24-bit RGB before importing into Blender, but that clearly isn’t enough most of the time. Even 8-bit (per channel) YUV can only be used with heavy dithering, and e. g. 10-bit input (which is getting increasingly common) loses way too much precision. Given FFmpeg’s rather awkward pixfmt support (owing to swscale legacy), it seems like using libzimg directly is the best option. Makes me wish mpv’s OpenGL renderer were its own library, could do arbitrary conversions (not just to RGB) and supported offscreen rendering. Maybe in some distant future (the topic has been brought up in the devel channel a few times)…

Added subscriber: @Sergey

Added subscriber: @Sergey

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sergey Sharybin self-assigned this 2017-09-13 13:42:52 +02:00

Thanks for the report, but it doesn't sound as a bug at all, more like a feature request or an enhancement request which we do not accept in the bug tracker. There are lots of areas in Blender which can behave better, but with are behaving fully according to the design and hence not considered a bug.

Such requests for improvements are better be addressed to bf-funboard mailing list, or (what is even better ;) as a patches here :)

Thanks for the report, but it doesn't sound as a bug at all, more like a feature request or an enhancement request which we do not accept in the bug tracker. There are lots of areas in Blender which can behave better, but with are behaving fully according to the design and hence not considered a bug. Such requests for improvements are better be addressed to bf-funboard mailing list, or (what is even better ;) as a patches here :)
Author

Alright. My bad. Wasn’t aware. I’ll see if I can come up with a patch or two to address the issues, though, because this is pretty important to me.

Thanks.

Alright. My bad. Wasn’t aware. I’ll see if I can come up with a patch or two to address the issues, though, because this is pretty important to me. Thanks.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#52697
No description provided.