ffmpeg: multithreaded conversion from RGBA into encoding format #116008

Merged
Aras Pranckevicius merged 1 commits from aras_p/blender:ffmpeg_threaded_conv into main 2023-12-15 12:36:10 +01:00

Whenever movie frame encoding needs to be in non-RGBA format (pretty much always, e.g. H.264 uses YUV etc.), the ffmpeg code has been using sws_scale() since 2007. But that one is completely single threaded.

It can be multi-threaded by passing "threads" option to SwsContext (in a cumbersome way), combined with sws_scale_frame API. Which however requires frame data buffers to be allocated via AVBuffer machinery.

Rendering a 300-frame part of Sprite Fright Edit (target H.264 Medium):

  • Windows Ryzen 5950X: 16.1 -> 12.0 seconds (generate_video_frame part 4.7 -> 0.7 sec).
  • Mac M1 Max: 13.1 -> 12.5 sec. Speedup is smaller, but comparatively, entirely other part of movie rendering (audio resampling inside audaspace) is way more expensive compared to the windows machine.
Whenever movie frame encoding needs to be in non-RGBA format (pretty much always, e.g. H.264 uses YUV etc.), the ffmpeg code has been using `sws_scale()` since 2007. But that one is completely single threaded. It can be multi-threaded by passing "threads" option to `SwsContext` (in a cumbersome way), combined with `sws_scale_frame` API. Which however requires frame data buffers to be allocated via `AVBuffer` machinery. Rendering a 300-frame part of Sprite Fright Edit (target H.264 Medium): - Windows Ryzen 5950X: 16.1 -> 12.0 seconds (`generate_video_frame` part 4.7 -> 0.7 sec). - Mac M1 Max: 13.1 -> 12.5 sec. Speedup is smaller, but comparatively, entirely other part of movie rendering (audio resampling inside audaspace) is way more expensive compared to the windows machine.
Aras Pranckevicius added 1 commit 2023-12-10 19:42:47 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
feddb39d72
ffmpeg: multithreaded conversion from RGBA into encoding format
Whenever movie frame encoding needs to be in non-RGBA format (pretty
much always, e.g. H.264 uses YUV etc.), the ffmpeg code has been
sws_scale() since 2007. But that one is completely single threaded.

It can be multi-threaded by passing "threads" option to SwsContext
(in a cumbersome way), and using `sws_scale_frame` API instead. Which
however requires frame data buffers to be allocated via AVBuffer
machinery.

Rendering a 300-frame part of Sprite Fright Edit (target H.264 Medium),
on Windows Ryzen 5950X: 16.1 -> 12.0 seconds (generate_video_frame
part 4.7 -> 0.7 sec).
Author
Member

@blender-bot build

@blender-bot build
Aras Pranckevicius changed title from WIP: ffmpeg: multithreaded conversion from RGBA into encoding format to ffmpeg: multithreaded conversion from RGBA into encoding format 2023-12-11 05:52:28 +01:00
Aras Pranckevicius added this to the Video Sequencer project 2023-12-11 05:52:37 +01:00
Aras Pranckevicius requested review from Richard Antalik 2023-12-11 05:52:45 +01:00
Aras Pranckevicius requested review from Sergey Sharybin 2023-12-11 05:52:54 +01:00
Richard Antalik approved these changes 2023-12-15 08:57:04 +01:00
Richard Antalik left a comment
Member

I did not realize, there is multithreaded version of sws_scale. I would assume, that this may have even greater impact when used for decoding in anim_movie.cc

I did not realize, there is multithreaded version of `sws_scale`. I would assume, that this may have even greater impact when used for decoding in `anim_movie.cc`
Author
Member

I would assume, that this may have even greater impact when used for decoding in anim_movie.cc

I can look into that next.

> I would assume, that this may have even greater impact when used for decoding in `anim_movie.cc` I can look into that next.
Aras Pranckevicius merged commit 422dd9404f into main 2023-12-15 12:36:10 +01:00
Aras Pranckevicius deleted branch ffmpeg_threaded_conv 2023-12-15 12:36:12 +01:00
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 Assignees
2 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#116008
No description provided.