Audio length inconsistency after frame rate change #94149

Closed
opened 2021-12-16 12:30:53 +01:00 by Georg K · 20 comments

System Information
Operating system: Linux-5.14.18-1-MANJARO-x86_64-with-glibc2.33 64 Bits
Graphics card: AMD VERDE (DRM 2.50.0, 5.14.18-1-MANJARO, LLVM 13.0.0) AMD 4.5 (Core Profile) Mesa 21.2.5

Blender Version
Broken: version: 3.1.0 Alpha, branch: master, commit date: 2021-12-14 21:50, hash: 644eb68524
Worked: 2.93.0

Short description of error
Importing an audio file into the video sequencer with the frame rate set to 25 results in an audio strip that ends at e.g. frame 6012. But after switching the frame rate to 24 and then back to 25, the audio strip ends at frame 6013.

Exact steps for others to reproduce the error

  • Start blender with video editing default
  • set frame rate to 25, switch sequencer to display frames instead of seconds
  • use add sound to add an mp3 file (at least 4 mins long)
  • check the location of the last frame of the audio strip
  • switch frame rate to 24 and back to 25
  • check the location of the last frame of the audio strip again - it is different than before.

Blender 2021-12-17 18-44-22.mp4

**System Information** Operating system: Linux-5.14.18-1-MANJARO-x86_64-with-glibc2.33 64 Bits Graphics card: AMD VERDE (DRM 2.50.0, 5.14.18-1-MANJARO, LLVM 13.0.0) AMD 4.5 (Core Profile) Mesa 21.2.5 **Blender Version** Broken: version: 3.1.0 Alpha, branch: master, commit date: 2021-12-14 21:50, hash: `644eb68524` Worked: 2.93.0 **Short description of error** Importing an audio file into the video sequencer with the frame rate set to 25 results in an audio strip that ends at e.g. frame 6012. But after switching the frame rate to 24 and then back to 25, the audio strip ends at frame 6013. **Exact steps for others to reproduce the error** - Start blender with video editing default - set frame rate to 25, switch sequencer to display frames instead of seconds - use add sound to add an mp3 file (at least 4 mins long) - check the location of the last frame of the audio strip - switch frame rate to 24 and back to 25 - check the location of the last frame of the audio strip again - it is different than before. [Blender 2021-12-17 18-44-22.mp4](https://archive.blender.org/developer/F12757730/Blender_2021-12-17_18-44-22.mp4)
Author

Added subscriber: @georgK

Added subscriber: @georgK
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Hi, thanks for the report. Can confirm. Note that problem does not appear with every audio file.

I can share audio file here but little unsure about policy. Added a video (see the task description) to show the exact issue

Also this is a regression. Works fine here on 2.93

(Original audio file is of 2677 sec)

Hi, thanks for the report. Can confirm. Note that problem does not appear with every audio file. I can share audio file here but little unsure about policy. Added a video (see the task description) to show the exact issue Also this is a regression. Works fine here on 2.93 (Original audio file is of 2677 sec)

Added subscriber: @iss

Added subscriber: @iss

This is same issue as #84027. There have been ongoing discussion, but I think I can commit fix for it. In meanwhile I will merge this report.

This is same issue as #84027. There have been ongoing discussion, but I think I can commit fix for it. In meanwhile I will merge this report.

Closed as duplicate of #84027

Closed as duplicate of #84027
Member

Hi @iss , may be you are right but this is not the case for 2.93. And the other issue (#84027) even appear on previous versions.

Underlying issue might be same but please check the report again. This appears to be a regression :)

Hi @iss , may be you are right but this is not the case for 2.93. And the other issue (#84027) even appear on previous versions. Underlying issue might be same but please check the report again. This appears to be a regression :)

Changed status from 'Duplicate' to: 'Needs User Info'

Changed status from 'Duplicate' to: 'Needs User Info'

Ah sorry, missed that point, but In that case I am not able to reproduce this issue. Is length of sound key here? I would definitely appreciate sample sound file or more exact steps.

Technically fixing #84027 would resolve this but issue here may be that sound was imported with incorrect length to begin with. Can you check which length is correct and which is not?

Ah sorry, missed that point, but In that case I am not able to reproduce this issue. Is length of sound key here? I would definitely appreciate sample sound file or more exact steps. Technically fixing #84027 would resolve this but issue here may be that sound was imported with incorrect length to begin with. Can you check which length is correct and which is not?
Member

issue here may be that sound was imported with incorrect length to begin with

Yes, original length of audio file is 2677. Importing with 25 fps shows 2676.

I can reproduce with steps provided by Georg. Or you can refer the video as well. (Let me know if anything is not clear.)

Audio file:
Beyond_Dreams_mastered.mp3

> issue here may be that sound was imported with incorrect length to begin with Yes, original length of audio file is 2677. Importing with 25 fps shows 2676. I can reproduce with steps provided by Georg. Or you can refer the video as well. (Let me know if anything is not clear.) Audio file: [Beyond_Dreams_mastered.mp3](https://archive.blender.org/developer/F12759845/Beyond_Dreams_mastered.mp3)
Author

I assumed that the audio has to be longer than 4 mins since the difference was only one frame with a 4 min audio file and there was no issue with a 3:48 file (http://dig.ccmixter.org/files/airtone/64427), but that has been disproved by the file from Pratik.

The 4mins audio file is proprietary, but I found another one with CC rights that is 4749 frames long at import but 4750 frames after switching the scene from 24 fps to 25 fps and back:
http://dig.ccmixter.org/files/Milky_Blue/63912

I assumed that the audio has to be longer than 4 mins since the difference was only one frame with a 4 min audio file and there was no issue with a 3:48 file (http://dig.ccmixter.org/files/airtone/64427), but that has been disproved by the file from Pratik. The 4mins audio file is proprietary, but I found another one with CC rights that is 4749 frames long at import but 4750 frames after switching the scene from 24 fps to 25 fps and back: http://dig.ccmixter.org/files/Milky_Blue/63912

Added subscriber: @ZedDB

Added subscriber: @ZedDB

Thanks for samples, I can reproduce now. I haven't realized, that difference is only 1 frame. From video it looked much larger. This will likely be due to inconsistency in length caclculation when strip is added vs when FPS does change.

To make things more confusing, ffprobe reports length of 03:17.89, while audacity 03:18.06. Audaspace reports length matching ffprobe, so will go with that. 4749 is result of rounding to integer which may not be technically correct way to do this. Refresh on framechange uses next higher integer instead. I remember talking about this with @ZedDB, I think this was changed recently and not sure if this will be documented why, but will look for reasoning and sonsolidate this in any case.

Thanks for samples, I can reproduce now. I haven't realized, that difference is only 1 frame. From video it looked much larger. This will likely be due to inconsistency in length caclculation when strip is added vs when FPS does change. To make things more confusing, ffprobe reports length of 03:17.89, while audacity 03:18.06. Audaspace reports length matching ffprobe, so will go with that. 4749 is result of rounding to integer which may not be technically correct way to do this. Refresh on framechange uses next higher integer instead. I remember talking about this with @ZedDB, I think this was changed recently and not sure if this will be documented why, but will look for reasoning and sonsolidate this in any case.

Changed status from 'Needs User Info' to: 'Confirmed'

Changed status from 'Needs User Info' to: 'Confirmed'

@iss I think that the "refresh on framechange" might be an oversight on my part.
I tried to unify how audio track length was calculated but I must have missed that one.

IIRC, I changed the rounding to always floor the frame count (cast to int).
This is because I tried a dozen of different video files and most of them seemed to line up (length wise) with the video when flooring the frame length.
From my tests it seemed like the previous logic of rounding up was because blender would previously not encode the last frame of audio properly before I did some fixes to remedy that.
So I'm guessing that the "round up" logic was there to make sure that videos/audio exported by Blender were the correct frame duration.
However this was just side stepping the root issue of blender not encoding the last frame of audio properly.

In addition to that, when we floor, we don't have any frames containing data for only half a frame or so.
Which subjectively to me, is logical because we work with whole frames in the VSE. (However the ability to shift the audio kinda pokes holes in this logic, so meh).

@iss I think that the "refresh on framechange" might be an oversight on my part. I tried to unify how audio track length was calculated but I must have missed that one. IIRC, I changed the rounding to always floor the frame count (cast to int). This is because I tried a dozen of different video files and most of them seemed to line up (length wise) with the video when flooring the frame length. From my tests it seemed like the previous logic of rounding up was because blender would previously not encode the last frame of audio properly before I did some fixes to remedy that. So I'm guessing that the "round up" logic was there to make sure that videos/audio exported by Blender were the correct frame duration. However this was just side stepping the root issue of blender not encoding the last frame of audio properly. In addition to that, when we floor, we don't have any frames containing data for only half a frame or so. Which subjectively to me, is logical because we work with whole frames in the VSE. (However the ability to shift the audio kinda pokes holes in this logic, so meh).

Thanks for info, I was thinking that it may be better to round up if for example movie files were split and this would cause gaps in audio causing pops and clicks. But I think this would happen anyway though so not sure really.

I think either way may be acceptable, but it should be consolidated.

Thanks for info, I was thinking that it may be better to round up if for example movie files were split and this would cause gaps in audio causing pops and clicks. But I think this would happen anyway though so not sure really. I think either way may be acceptable, but it should be consolidated.

Usually the video frame length and the audio buffer chunk size doesn't match up, so if you split a video file you will be in the middle of a audio chunk.

The same is true when creating a video file and writing the last audio portion of it.
Usually what happens is that the video data will end while in the middle of an audio chunk.
test1.png
If the actual raw audio and video duration is exactly the same, then the last audio chunk will be padded with silence (the real audio and video data ends at the blue line).
test2.png

If you split a video into chunks, then you will have the same issue.
test3.png
The split will be in the middle of an audio chunk. So to make them line up, you will have to floor the frame duration of the audio when importing.
Otherwise you will either lose audio (if you didn't encode the overlapping audio chunk when splitting) or you end up with shift as the audio will last for too long if rounded up.
test4.png

Then for the next video section you will have to encode the same audio chunk again that we cut off as the first chunk and encode an audio offset so that the chunk is properly aligned with the start frame.
test5.png
The audio start offset will be the duration from the start of the audio chunk to the start video frame:
test6.png

If you do this, then I think we should be able to split video files and they should still line up when importing them into blender again.

Usually the video frame length and the audio buffer chunk size doesn't match up, so if you split a video file you will be in the middle of a audio chunk. The same is true when creating a video file and writing the last audio portion of it. Usually what happens is that the video data will end while in the middle of an audio chunk. ![test1.png](https://archive.blender.org/developer/F12791345/test1.png) If the actual raw audio and video duration is exactly the same, then the last audio chunk will be padded with silence (the real audio and video data ends at the blue line). ![test2.png](https://archive.blender.org/developer/F12791350/test2.png) If you split a video into chunks, then you will have the same issue. ![test3.png](https://archive.blender.org/developer/F12791358/test3.png) The split will be in the middle of an audio chunk. So to make them line up, you will have to floor the frame duration of the audio when importing. Otherwise you will either lose audio (if you didn't encode the overlapping audio chunk when splitting) or you end up with shift as the audio will last for too long if rounded up. ![test4.png](https://archive.blender.org/developer/F12791363/test4.png) Then for the next video section you will have to encode the same audio chunk again that we cut off as the first chunk and encode an audio offset so that the chunk is properly aligned with the start frame. ![test5.png](https://archive.blender.org/developer/F12791367/test5.png) The audio start offset will be the duration from the start of the audio chunk to the start video frame: ![test6.png](https://archive.blender.org/developer/F12791375/test6.png) If you do this, then I think we should be able to split video files and they should still line up when importing them into blender again.

This issue was referenced by 83094d9a0d

This issue was referenced by 83094d9a0d43a95fa0ac2ec79234e54bb1c88675

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Richard Antalik self-assigned this 2022-01-26 00:00:28 +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
5 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#94149
No description provided.