Skip to content
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

Add media duration to lpms_get_codec_info for GetCodecInfo #407

Merged
merged 27 commits into from
Jul 11, 2024

Conversation

eliteprox
Copy link
Contributor

Adds the duration to lpms_get_codec_info for audio only and audio/video files.

This is needed for the audio to text pipeline

Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Added 2 comments.

Other than that, @j0sh could you also look at the PR (since I believe you have the best knowledge about the lpms project)?

cmd/test/get_fps_dur.go Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
ffmpeg/ffmpeg.go Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
@eliteprox eliteprox requested a review from j0sh July 9, 2024 13:35
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/ffmpeg.go Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
cmd := `
cp "$1/../data/bunny.mp4" test.mp4
cp "$1/../data/duplicate-audio-dts.ts" test.ts
ffmpeg -loglevel warning -i test.mp4 -vn -c:a flac test.flac
Copy link
Collaborator

@j0sh j0sh Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, it would be nice to also add checks for expected fps/duration values from ffprobe - helps ensure that our own calculations are correct

also just checking, which one of these triggers the no-duration case that requires manual calculations? (that should also surface via ffprobe, eg a duration of "N/A")

Copy link
Contributor Author

@eliteprox eliteprox Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be with webm and mp3 files. ffprobe -show_streams test.webm | grep 'duration=' gives N/A for duration. I've added webm to the test, it is working with the latest changes.

Copy link
Collaborator

@j0sh j0sh Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look and the duration is there for the top-level container (ic->duration) for both webm and mp3 files. You can also see this in the top-level ffprobe output, or ffprobe -show_format. Stream duration is indeed empty (which is the equivalent with ffprobe -show_streams) but we aren't using that here.

If we need to introduce a code path to manually calculate the duration then I would prefer to find a test case which can exercise that.

Also please add the ffprobe outputs to the test case as well, because this validates the assumptions we are testing against, and allows us to spot areas where we diverge from ffmpeg's own behavior. For example:

ffmpeg -loglevel warning -i test.mp4 -c:v libvpx -c:a vorbis -strict -2 -t 1 test.webm
ffprobe -loglevel warning -show_format test.webm | grep duration=1.047000
ffprobe -loglevel warning -show_streams -select_streams v test.webm | grep r_frame_rate=24/1

this example is shortened to 1 second; it doesn't really need to be very long for the purpose of this test case and speeds up test execution since its encoding video which is expensive

BTW the durations you have in these test cases seem very round - do you care about the fractional part of the second at all? If not, then maybe make it an integer type instead of floating point. Otherwise you'll need to cast to double when calculating the duration, eg out->dur = (double)ic->duration / AV_TIME_BASE;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the ffprobe commands, shortened all the videos to 2 seconds. The int64 change is working well so I removed calculate_stream_duration. I am happy with rounding numbers for now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with rounding numbers for now

Double checking (no pun intended) ... anything less than 1 (eg, 0.99) will be rounded down to 0, 1.99 becomes 1, etc. That seems pretty significant (eg, how do you distinguish between "very short" and "zero duration") but if is still OK for your purposes, then 👍

Otherwise, I believe we can still match the values calculated by ffprobe - our equivalent would be out->dur = ic->duration * av_q2d(AV_TIME_BASE_Q) ... mathematically the same as the old code, but I don't know if the computed precision would differ (and it would only come into play for very large durations, anyhow)

@eliteprox eliteprox requested a review from j0sh July 10, 2024 16:57
ffmpeg/extras.c Outdated Show resolved Hide resolved
cmd := `
cp "$1/../data/bunny.mp4" test.mp4
cp "$1/../data/duplicate-audio-dts.ts" test.ts
ffmpeg -loglevel warning -i test.mp4 -vn -c:a flac test.flac
Copy link
Collaborator

@j0sh j0sh Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look and the duration is there for the top-level container (ic->duration) for both webm and mp3 files. You can also see this in the top-level ffprobe output, or ffprobe -show_format. Stream duration is indeed empty (which is the equivalent with ffprobe -show_streams) but we aren't using that here.

If we need to introduce a code path to manually calculate the duration then I would prefer to find a test case which can exercise that.

Also please add the ffprobe outputs to the test case as well, because this validates the assumptions we are testing against, and allows us to spot areas where we diverge from ffmpeg's own behavior. For example:

ffmpeg -loglevel warning -i test.mp4 -c:v libvpx -c:a vorbis -strict -2 -t 1 test.webm
ffprobe -loglevel warning -show_format test.webm | grep duration=1.047000
ffprobe -loglevel warning -show_streams -select_streams v test.webm | grep r_frame_rate=24/1

this example is shortened to 1 second; it doesn't really need to be very long for the purpose of this test case and speeds up test execution since its encoding video which is expensive

BTW the durations you have in these test cases seem very round - do you care about the fractional part of the second at all? If not, then maybe make it an integer type instead of floating point. Otherwise you'll need to cast to double when calculating the duration, eg out->dur = (double)ic->duration / AV_TIME_BASE;

ffmpeg/extras.c Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
ffmpeg/ffmpeg_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@j0sh j0sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚢

please squash when merging

@j0sh j0sh merged commit 2273258 into livepeer:ai-video Jul 11, 2024
@rickstaa
Copy link
Member

@eliteprox very clean pull request 🚀. @j0sh thanks for helping to review this 🙏🏻.

rickstaa pushed a commit that referenced this pull request Jul 25, 2024
rickstaa pushed a commit that referenced this pull request Jul 25, 2024
rickstaa pushed a commit that referenced this pull request Jul 25, 2024
rickstaa pushed a commit that referenced this pull request Jul 26, 2024
rickstaa pushed a commit that referenced this pull request Jul 31, 2024
j0sh pushed a commit that referenced this pull request Jul 31, 2024
j0sh pushed a commit that referenced this pull request Jul 31, 2024
j0sh pushed a commit that referenced this pull request Jul 31, 2024
j0sh pushed a commit that referenced this pull request Jul 31, 2024
j0sh pushed a commit that referenced this pull request Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants