VSE and ffmpeg: Banding and color shift #111703

Open
opened 2023-08-30 17:25:54 +02:00 by Domingo Riesco · 6 comments

System Information
Operating system: Linux-6.1.38.12.realtime1-4-rt-lts-x86_64-with-glibc2.38 64 Bits, X11 UI
Graphics card: AMD Radeon R9 M370X (verde, LLVM 15.0.7, DRM 3.49, 6.1.38.12.realtime1-4-rt-lts)

Blender Version
version: 3.6.0, branch: makepkg (modified), commit date: 2023-06-27 08:08, hash: c7fc78b81ecb

Short description of error
Blender's viewport and renders to PNG present a different image to the original video file, introducing 'banding' (aka. pixel regions) and a slight color shift.

Strange enough, the same results when transcoding the video to PNG directly, using the following command: ffmpeg -i C0441.MP4 -vf fps=1 C0441.png

However, the video file is shown correctly by ffplay! Other softwares, some of them explicitly ffmpeg based, also show the video correctly. Please compare banding in the samples below (sorry for the amount of pictures and mentions to softwares). This is the 1st frame of a clip I made intentionally in conditions that produce heavy banding.

CORRECT

kdenlive-linux.png
Kdenlive export to PNG, ffmpeg v6 (Linux)

premiere-osx.png
Shotcut export to PNG, ffmpeg v6 (Linux)

premiere-osx.png
Adobe Premiere export to PNG (OSX)

resolve-osx.png
Davinci Resolve export to PNG (OSX)

ffplay_ffmpeg4.3-osx_screenshot.png
ffplay screenshot, ffmpeg v4.3 (OSX)

ffplay_ffmpeg6-linux_screenshot_linux.png
ffplay screenshot, ffmpeg v6 (Linux)

INCORRECT

ffmpeg4.3-osx.png
ffmpeg cli 4.3 to png (OSX)

ffmpeg6-linux.png
ffmpeg cli 6 to png (Linux)

blender_viewport_ffmpeg6-screenshot_linux.png
Blender export to PNG, ffmpeg6 (OSX)

blender_ffmpeg4.3-osx.png
Blender export to PNG, ffmpeg4.3 (OSX)

As you can see, gradients on the background are much more patchy in the second group.

Original h.264 video file (6sec, 40MB).

C0441.MP4

This is footage from a Sony A7s2 camera. But I just tried with AVCHD files from an old Panny and the same happens. In brighter footage a color shift can be appreciated on simple sight.

I'm very puzzled with this and wonder what an explanation would be. I hope others can confirm the effect.

Exact steps for others to reproduce the error

  1. Download the video file and run it in ffplay. If you press space and then the back-arrow ffplay will stick to the 1st frame.
  2. Import the file to blender and compare the banding of the first frame to the one shown in ffplay.
**System Information** Operating system: Linux-6.1.38.12.realtime1-4-rt-lts-x86_64-with-glibc2.38 64 Bits, X11 UI Graphics card: AMD Radeon R9 M370X (verde, LLVM 15.0.7, DRM 3.49, 6.1.38.12.realtime1-4-rt-lts) **Blender Version** version: 3.6.0, branch: makepkg (modified), commit date: 2023-06-27 08:08, hash: `c7fc78b81ecb` **Short description of error** Blender's viewport and renders to PNG present a different image to the original video file, introducing 'banding' (aka. pixel regions) and a slight color shift. Strange enough, the same results when transcoding the video to PNG directly, using the following command: ffmpeg -i C0441.MP4 -vf fps=1 C0441.png However, the video file is shown correctly by ffplay! Other softwares, some of them explicitly ffmpeg based, also show the video correctly. Please compare banding in the samples below (sorry for the amount of pictures and mentions to softwares). This is the 1st frame of a clip I made intentionally in conditions that produce heavy banding. **CORRECT** ![kdenlive-linux.png](/attachments/282da93c-e006-4b8b-9faf-08581060d9de) _Kdenlive export to PNG, ffmpeg v6 (Linux)_ ![premiere-osx.png](/attachments/27729b8f-3473-4727-b655-72ab9b41c1ec) _Shotcut export to PNG, ffmpeg v6 (Linux)_ ![premiere-osx.png](/attachments/7da3f7d0-ffcc-42f4-8a9c-3e7dee332490) _Adobe Premiere export to PNG (OSX)_ ![resolve-osx.png](/attachments/52016856-9718-4aa1-a9d3-df60a19a8be9) _Davinci Resolve export to PNG (OSX)_ ![ffplay_ffmpeg4.3-osx_screenshot.png](/attachments/aa9c92dd-0ccf-4d33-8109-249b4409966b) _ffplay screenshot, ffmpeg v4.3 (OSX)_ ![ffplay_ffmpeg6-linux_screenshot_linux.png](/attachments/24651522-7511-4615-a947-95bca92aa0b3) _ffplay screenshot, ffmpeg v6 (Linux)_ **INCORRECT** ![ffmpeg4.3-osx.png](/attachments/b8b0cdf6-ac6b-4424-b4d2-cee7499760da) _ffmpeg cli 4.3 to png (OSX)_ ![ffmpeg6-linux.png](/attachments/1261ea33-2f09-4714-af27-f85ef47d1d71) _ffmpeg cli 6 to png (Linux)_ ![blender_viewport_ffmpeg6-screenshot_linux.png](/attachments/ce1e699b-f038-4d57-9af0-673ecb7d57de) _Blender export to PNG, ffmpeg6 (OSX)_ ![blender_ffmpeg4.3-osx.png](/attachments/06363406-edff-4b70-8d4e-9ff20a38111e) _Blender export to PNG, ffmpeg4.3 (OSX)_ As you can see, gradients on the background are much more patchy in the second group. Original h.264 video file (6sec, 40MB). <video src="/attachments/316cd50a-4adc-4ae8-8ba7-08945a79183a" title="C0441.MP4" controls></video> [C0441.MP4](/attachments/316cd50a-4adc-4ae8-8ba7-08945a79183a) This is footage from a Sony A7s2 camera. But I just tried with AVCHD files from an old Panny and the same happens. In brighter footage a color shift can be appreciated on simple sight. I'm very puzzled with this and wonder what an explanation would be. I hope others can confirm the effect. **Exact steps for others to reproduce the error** 1. Download the video file and run it in ffplay. If you press space and then the back-arrow ffplay will stick to the 1st frame. 2. Import the file to blender and compare the banding of the first frame to the one shown in ffplay.
Domingo Riesco added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-08-30 17:25:55 +02:00

It's interesting, that ffplay results in different output than ffmpeg CLI conversion. I would expect to see same result from Blender as in ffmpeg cli, which happens here. However it seems, that there is some color conversion missing. Will confirm to do more digging.

I would suspect, that ffplay would do color conversion with some library, but will check it's code. Also I should check other reports whether I see similar metadata in these files.

It's interesting, that ffplay results in different output than ffmpeg CLI conversion. I would expect to see same result from Blender as in ffmpeg cli, which happens here. However it seems, that there is some color conversion missing. Will confirm to do more digging. I would suspect, that ffplay would do color conversion with some library, but will check it's code. Also I should check other reports whether I see similar metadata in these files.
Author

Richard,
This is how ffplay shows the first frame of an mp4 here.
parade1.png

This is a PNG conversion via ffmpeg (without added options or flags).
parade2.png

The mp4 format of the source is yuv420p (sony XAVC). I couldn't find the right options to create the png from a yuv colorspace, ffmpeg documentation is quite confusing for me, but blender's viewport shows the same mistaken histogram when the mp4 is imported into the sequencer. DNXHD exports seem correct and consistent to the original footage. The color shift of DNXHD blender exports is in relation to the viewport presentation and PNG exports, not in relation to the original mp4 file which seems the same as the DNXHD exports.

MP4 (or ffmpegPNG) on viewport
mp4orPNG_viewport.png

MP4 on ffplay
mp4_ffplay.png

(Those waveforms were captured with obs-color-monitor, fullscreening on a secondary monitor. )

Richard, This is how ffplay shows the first frame of an mp4 here. ![parade1.png](/attachments/90f5acc5-fd13-49a2-a9c9-ec4e4443b83e) This is a PNG conversion via ffmpeg (without added options or flags). ![parade2.png](/attachments/d12a9367-1046-433d-8106-1737dca9f1da) The mp4 format of the source is yuv420p (sony XAVC). I couldn't find the right options to create the png from a yuv colorspace, ffmpeg documentation is quite confusing for me, but blender's viewport shows the same mistaken histogram when the mp4 is imported into the sequencer. DNXHD exports seem correct and consistent to the original footage. The color shift of DNXHD blender exports is in relation to the viewport presentation and PNG exports, not in relation to the original mp4 file which seems the same as the DNXHD exports. MP4 (or ffmpegPNG) on viewport ![mp4orPNG_viewport.png](/attachments/c9e9586a-d0e4-4613-817b-e475498c5c09) MP4 on ffplay ![mp4_ffplay.png](/attachments/adc2f815-e119-4f2d-9095-14ff6438fea4) (Those waveforms were captured with obs-color-monitor, fullscreening on a secondary monitor. )

Maybe it's related to one of these reports:
#60947: FFMpeg color offset
#61708: Encoding to MPEG-4(divx) in constant quality mode ignores Output quality settings

Maybe it's related to one of these reports: #60947: FFMpeg color offset #61708: Encoding to MPEG-4(divx) in constant quality mode ignores Output quality settings

#60947 is about color shift when rendering to video format. It specifically says, that rendering PNG is OK.

If I do difference of original video and PNG it returns 0 for all colors in all pixels, so if there is issue, it is on decoding side.

I have noticed, that ffmpeg output looks actually different to blender output. I have tried to force input colorspace and primaries to bt.709, which didn't change output. Specifies this to codec as well, got no change.

The issue here could be, that iec61966-2-4 extends gamut beyond sRGB range and somehow this gets lossy in 8bit space, but I think it's unlikely.

In any case I am not sure if I can help here. This topic goes quite a bit over my head and I could possibly fix this only if you could identify the issue. I can check some debug logs from ffplay, perhaps it will reveal some conversion it is doing. But AFAIK ffplay does quite a bit of processing on GPU, maybe even decoding, so it may use float buffers to do color conversions. Technically it may be still bug in ffmpeg, will see if I can force ffplay to fail.

#60947 is about color shift when rendering to video format. It specifically says, that rendering PNG is OK. If I do difference of original video and PNG it returns 0 for all colors in all pixels, so if there is issue, it is on decoding side. I have noticed, that ffmpeg output looks actually different to blender output. I have tried to force input colorspace and primaries to bt.709, which didn't change output. Specifies this to codec as well, got no change. The issue here could be, that iec61966-2-4 extends gamut beyond sRGB range and somehow this gets lossy in 8bit space, but I think it's unlikely. In any case I am not sure if I can help here. This topic goes quite a bit over my head and I could possibly fix this only if you could identify the issue. I can check some debug logs from ffplay, perhaps it will reveal some conversion it is doing. But AFAIK ffplay does quite a bit of processing on GPU, maybe even decoding, so it may use float buffers to do color conversions. Technically it may be still bug in ffmpeg, will see if I can force ffplay to fail.
Richard Antalik added
Type
Known Issue
and removed
Type
Report
labels 2023-10-16 23:01:20 +02:00

I encounter the same issue.
Imported MP4 is more saturated and appear color banding. Seems to be FFMpeg problem

I encounter the same issue. Imported MP4 is more saturated and appear color banding. Seems to be FFMpeg problem
[https://projects.blender.org/blender/blender/issues/52697](url)
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
4 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#111703
No description provided.