Skip to content

Use edited_duration in C API #437

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions mp4parse_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,24 @@ pub unsafe extern "C" fn mp4parse_get_track_info(
None => return Mp4parseStatus::Invalid,
};

match track.duration {
Some(duration) => info.duration = duration.0,
None => {
// Duration unknown; stagefright returns 0 for this.
info.duration = 0
// Use edited duration if available
info.duration = if let Some(edited_duration) = track.edited_duration {
if let Some(context_timescale) = context.timescale {
match rational_scale(edited_duration.0, context_timescale.0, timescale.0) {
Some(converted) => converted,
None => {
// Fall back to media duration
track.duration.map_or(0, |d| d.0)
}
}
} else {
track.duration.map_or(0, |d| d.0)
}
} else if let Some(duration) = track.duration {
duration.0
} else {
// Duration unknown; stagefright returns 0 for this.
0
}
} else {
return Mp4parseStatus::Invalid;
Expand Down