VSE: Cleanup: Remove storage of last FFMPEG frame read as ImBuf in sequences. #114395

Merged
Bastien Montagne merged 1 commits from mont29/blender:tmp-vse-anim-remove-cur-ibuf into main 2023-11-03 11:18:30 +01:00

The anim data of a sequence would store the last frame read from
FFMPEG as an image buffer, increasing its refcounting and preventing it
to be freed until the whole anim data itself gets freed.

In current code, there is no reason to keep a reference to this image
buffer in the anim data, so removing it. This may also give a few
percent improvement on the memory usage of the VSE in some cases.

Found while investigating #114342.

The `anim` data of a sequence would store the last frame read from FFMPEG as an image buffer, increasing its refcounting and preventing it to be freed until the whole `anim` data itself gets freed. In current code, there is no reason to keep a reference to this image buffer in the `anim` data, so removing it. This may also give a few percent improvement on the memory usage of the VSE in some cases. Found while investigating #114342.
Bastien Montagne requested review from Sergey Sharybin 2023-11-02 10:49:43 +01:00
Bastien Montagne requested review from Richard Antalik 2023-11-02 10:49:43 +01:00
Author
Owner

@blender-bot build

@blender-bot build
Sergey Sharybin approved these changes 2023-11-02 11:39:24 +01:00

Just a note, that this change is not VSE specific, but applies to the imbuf module which is used by bunch of areas. I like to prefix title of such commits with "FFmpeg:".

I think at some point there was path in code, where cur_frame_final was returned early to avoid re-processing same AVFrame. I did a quick test with 1 FPS movie converted to 10 FPS, and indeed same AVFrame was processed each time into ImBuf. Question is, whether it is good idea to keep this buffer around and do early return. This could save some performance and memory when using for example 30fps movie in 60fps scene. This would apply mostly to VSE since it does support time remapping. Other editors may use scene time stretching feature, but not sure if that would yield the same effect and it probably isn't used often.

Drawback of this would be bit increased code complexity - pointer to previous frame would have to be stored and compared to final_frame in ffmpeg_fetchibuf(). Perhaps nicer could be wrapping cur_frame_final, so it is aware of what AVFrame it belongs to.

That said, early return has not been there for some time, so I think the cur_frame_final as it is now could be removed. A form of caching could be implemented again in a way that is more obvious and does not pollute anim structure with data not related to core functionality.

Just a note, that this change is not VSE specific, but applies to the imbuf module which is used by bunch of areas. I like to prefix title of such commits with "FFmpeg:". I think at some point there was path in code, where `cur_frame_final` was returned early to avoid re-processing same `AVFrame`. I did a quick test with 1 FPS movie converted to 10 FPS, and indeed same `AVFrame` was processed each time into `ImBuf`. Question is, whether it is good idea to keep this buffer around and do early return. This could save some performance and memory when using for example 30fps movie in 60fps scene. This would apply mostly to VSE since it does support time remapping. Other editors may use scene time stretching feature, but not sure if that would yield the same effect and it probably isn't used often. Drawback of this would be bit increased code complexity - pointer to previous frame would have to be stored and compared to `final_frame` in `ffmpeg_fetchibuf()`. Perhaps nicer could be wrapping `cur_frame_final`, so it is aware of what `AVFrame` it belongs to. That said, early return has not been there for some time, so I think the `cur_frame_final` as it is now could be removed. A form of caching could be implemented again in a way that is more obvious and does not pollute `anim` structure with data not related to core functionality.
Richard Antalik approved these changes 2023-11-02 18:25:26 +01:00
Bastien Montagne force-pushed tmp-vse-anim-remove-cur-ibuf from 45270513cb to b1d2198aad 2023-11-03 11:08:24 +01:00 Compare
Bastien Montagne merged commit d1e732a114 into main 2023-11-03 11:18:30 +01:00
Bastien Montagne deleted branch tmp-vse-anim-remove-cur-ibuf 2023-11-03 11:18:32 +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 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#114395
No description provided.