Fix #107493: Auto rotate videos fix #115661

Open
ErikHK wants to merge 7 commits from ErikHK/blender:auto_rotate_video into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

This fixes the bug where Blender doesn't take video rotation into account when importing videos. iPhone videos recorded in portrait mode for example will be in the wrong rotation when imported into Blender. I've only covered the cases where rotation is equal to -90, 180 or -180 degrees, there might be other variations from other cameras, like 270, or 90 degrees. If someone has example videos like these, please upload them!
Also the 180 and -180 degree cases can be improved, now they're done through an x flip followed by a y flip.

Other similar bug reports: #108478 and #98480

This fixes the bug where Blender doesn't take video rotation into account when importing videos. iPhone videos recorded in portrait mode for example will be in the wrong rotation when imported into Blender. I've only covered the cases where rotation is equal to -90, 180 or -180 degrees, there might be other variations from other cameras, like 270, or 90 degrees. If someone has example videos like these, please upload them! Also the 180 and -180 degree cases can be improved, now they're done through an x flip followed by a y flip. Other similar bug reports: #108478 and #98480
ErikHK added 4 commits 2023-12-01 12:34:27 +01:00
ErikHK added 1 commit 2023-12-01 12:44:30 +01:00
ErikHK added 1 commit 2023-12-01 12:51:00 +01:00
Iliya Katushenock added the
Module
VFX & Video
label 2023-12-01 12:51:27 +01:00
Falk David requested review from Sergey Sharybin 2023-12-01 12:54:24 +01:00
Iliya Katushenock added this to the Core Libraries project 2023-12-01 15:01:10 +01:00
Iliya Katushenock modified the project from Core Libraries to Core 2023-12-01 15:01:16 +01:00
Sergey Sharybin requested changes 2023-12-01 15:27:22 +01:00
Sergey Sharybin left a comment
Owner

Thanks for the PR.

There are some in-lined comments with points which needs to be addressed.

Outside of the inlined comments the note is that functions in the processing functions in imbuf should be handling both byte and float buffer. Similar to IMB_flipx (but do not assume 4 channel for float, use ibuf->channels instead).

Thanks for the PR. There are some in-lined comments with points which needs to be addressed. Outside of the inlined comments the note is that functions in the processing functions in imbuf should be handling both byte and float buffer. Similar to `IMB_flipx` (but do not assume 4 channel for float, use ibuf->channels instead).
@ -878,0 +886,4 @@
if (displaymatrix == nullptr)
return;
double theta = 0;

const double theta = av_display_rotation_get((int32_t *)displaymatrix);

`const double theta = av_display_rotation_get((int32_t *)displaymatrix);`
ErikHK marked this conversation as resolved
@ -111,0 +112,4 @@
void IMB_rotate90(ImBuf *ibuf)
{
ImBuf *tbuf;
int x, y;

Reduce the scope of variables. So instead of defining them in the beginning of the function define close to where you use htem. Examples:

  • ImBuf *tbuf = IMB_allocImBuf(ibuf->y, ibuf->x, 32, IB_rect);
  • for (int y = tbuf->y - 1; y >= 0; y--) {
Reduce the scope of variables. So instead of defining them in the beginning of the function define close to where you use htem. Examples: - `ImBuf *tbuf = IMB_allocImBuf(ibuf->y, ibuf->x, 32, IB_rect);` - `for (int y = tbuf->y - 1; y >= 0; y--) {`
ErikHK marked this conversation as resolved
@ -111,0 +118,4 @@
ibufrect = (uint *)ibuf->byte_buffer.data;
if (ibuf == 0)

nullptr instead of 0.

`nullptr` instead of `0`.
ErikHK marked this conversation as resolved
@ -111,0 +123,4 @@
if (ibufrect == 0)
return;
tbuf = IMB_allocImBuf(ibuf->y, ibuf->x, 32, IB_rect);

You can duplicate just the data, and use that as a const-source , and write the rotated result directly to the ibuf->byte_buffer. This way you wouldn't need the extra memcpy after the loop.

You can duplicate just the data, and use that as a const-source , and write the rotated result directly to the `ibuf->byte_buffer`. This way you wouldn't need the extra `memcpy` after the loop.
Author
First-time contributor

Thanks for the tip! I think I solved it in the way you suggested, but since I'm not great at memory handling and stuff in C it would be nice if you could take a look at it :)

Thanks for the tip! I think I solved it in the way you suggested, but since I'm not great at memory handling and stuff in C it would be nice if you could take a look at it :)
ErikHK added 1 commit 2023-12-02 15:55:30 +01:00
Author
First-time contributor

Thanks for the PR.

There are some in-lined comments with points which needs to be addressed.

Outside of the inlined comments the note is that functions in the processing functions in imbuf should be handling both byte and float buffer. Similar to IMB_flipx (but do not assume 4 channel for float, use ibuf->channels instead).

I don't really know how to fix that since I don't know when images have float values and/instead of byte values. Do you know any way to try this out?

> Thanks for the PR. > > There are some in-lined comments with points which needs to be addressed. > > Outside of the inlined comments the note is that functions in the processing functions in imbuf should be handling both byte and float buffer. Similar to `IMB_flipx` (but do not assume 4 channel for float, use ibuf->channels instead). I don't really know how to fix that since I don't know when images have float values and/instead of byte values. Do you know any way to try this out?

I don't really know how to fix that since I don't know when images have float values and/instead of byte values. Do you know any way to try this out?

Potentially ImBuf could have none of buffers, only only one of the byte or float buffer, or even both.

I think the simplest way to trigger the float buffer code path for the development purposes of this patch would be to:

  IMB_float_from_rect();
  imb_freerectImBuf();

  IMB_rotate90();  

  IMB_rect_from_float();
  imb_freerectfloatImBuf();

We could also expose the rotation as an operator to the image editor, which will implement functionallity like "Rotate 90 degrees CW", "Rotate 90 degreed CCW", and then you'll have a visual confirmation that the algorithm works quite easily, and you'll be able to easily control which data is coming it. But in a way, this is outside of the scope of this PR.

> I don't really know how to fix that since I don't know when images have float values and/instead of byte values. Do you know any way to try this out? Potentially ImBuf could have none of buffers, only only one of the byte or float buffer, or even both. I think the simplest way to trigger the float buffer code path for the development purposes of this patch would be to: ``` IMB_float_from_rect(); imb_freerectImBuf(); IMB_rotate90(); IMB_rect_from_float(); imb_freerectfloatImBuf(); ```` We could also expose the rotation as an operator to the image editor, which will implement functionallity like "Rotate 90 degrees CW", "Rotate 90 degreed CCW", and then you'll have a visual confirmation that the algorithm works quite easily, and you'll be able to easily control which data is coming it. But in a way, this is outside of the scope of this PR.
This pull request has changes conflicting with the target branch.
  • source/blender/imbuf/IMB_imbuf.h

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u auto_rotate_video:ErikHK-auto_rotate_video
git checkout ErikHK-auto_rotate_video
Sign in to join this conversation.
No reviewers
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
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#115661
No description provided.