-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
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.
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)?
…ove test files, change Dur to DurSecs
ffmpeg/ffmpeg_test.go
Outdated
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 |
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.
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")
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.
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.
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 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
;
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.
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
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 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)
ffmpeg/ffmpeg_test.go
Outdated
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 |
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 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
;
Co-authored-by: Josh Allmann <[email protected]>
Co-authored-by: Josh Allmann <[email protected]>
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.
LGTM! 🚢
please squash when merging
@eliteprox very clean pull request 🚀. @j0sh thanks for helping to review this 🙏🏻. |
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
* add fps and duration to GetCodecInfo
Adds the duration to
lpms_get_codec_info
for audio only and audio/video files.This is needed for the audio to text pipeline