-
Notifications
You must be signed in to change notification settings - Fork 67
[NOT_READY] Ensure OTIO video triming is duration accurate (for re-encoding to avoid keyframe rounding issue). #1394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
| "-ss", str(sec_start), | ||
| "-t", str(sec_duration), | ||
| "-i", video_path, | ||
| "-c", "copy", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakubjezek001 @iLLiCiTiT @philippe-ynput @antirotor
I'm torn by this change. Using the -c copy stream option when trimming the video get us codec accurate sub-videos BUT with potential duration mismatch due to keyframes (see PR description).
While removing this as I do here, force a re-encoding, giving frame-accurate sub-videos but through different codecs than source (ffmpeg default is x264) which might not be what we want here.
I could go with a more sophisticated approach is and detect codec from source than attempt to re-encode in same codec but not all codec variations are natively supported by FFmpeg and we could still end-up with subtle variations (color, gamma, bitrate...) compare to copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the codec copy is important.
I could go with a more sophisticated approach is and detect codec from source than attempt to re-encode in same codec but not all codec variations are natively supported by FFmpeg and we could still end-up with subtle variations (color, gamma, bitrate...) compare to copy.
There is get_ffmpeg_codec_args to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The accuracy of the cut is probably more important than the image quality, assuming the re-encoding will not totally destroy the image quality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just gave it more testing this afternoon this is not good enough.
I have to set copy stream option to ensure frame accurate (but not duration accurate) stuff.
When I re-encode blindly from input I got misinterplated interlaced-frames.
The only correct way I have to to "trim" properly the video right now is to extract the video as image sequence than re-encode the portion required in order to leave no room for video codec subtilities. But this is obviously way slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why dont we just simply convert the trimmed cut of the video to intermediate PNG image sequence? It would secure that we are on frame accurate and also would preserve the most of the video.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely we simply wouldn't keep the video native encoding/codec metadata.
This could end up looking different on some player.
Changelog Description
resolve: ynput/ayon-hiero#77
When trimming video from OTIO timeline, we use ffmpeg with
-c copysettings.This means copy the streams (audio + video) without re-encoding, which is very performant but only allows to cut at video keyframes.
The issue with this approach is that the resulting trimmed video duration is not safely guaranteed:
Additional info
Paragraphs of text giving context of additional technical information or code examples.
Testing notes: