-
Notifications
You must be signed in to change notification settings - Fork 1
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
LU-3510 Adding duration support for webm #61
Changes from 4 commits
acb66c9
c4a4ca1
fd05775
2ca6dd4
0e5fe70
060f966
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,13 @@ const VERBOSE = false; | |
*/ | ||
const RGBA_PIXEL_SIZE = 4; | ||
|
||
// Convert a duration string in the format HH:MM:SS to seconds | ||
// Example: 00:01:30 -> 90 | ||
function convertDurationToSeconds(duration) { | ||
const [hours, minutes, seconds] = duration.split(':').map(parseFloat); | ||
return hours * 3600 + minutes * 60 + seconds; | ||
} | ||
|
||
const createDecoder = ({ | ||
demuxer, | ||
streamIndex, | ||
|
@@ -242,7 +249,14 @@ export class BeamcoderExtractor extends BaseExtractor implements Extractor { | |
* This is the duration of the first video stream in the file expressed in seconds. | ||
*/ | ||
get duration(): number { | ||
return this.ptsToTime(this.#demuxer.streams[this.#streamIndex].duration); | ||
const stream = this.#demuxer.streams[this.#streamIndex]; | ||
if (stream.duration !== null) { | ||
return this.ptsToTime(stream.duration); | ||
} | ||
if (stream?.metadata?.DURATION) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's reliable. it is just a dictionary https://stackoverflow.com/a/27208276 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, we can call duration on the parent object which seems to return the correct value. I'm going to use that instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exactly , beamcoder executes code from stack overflow and it expands avformat context |
||
return convertDurationToSeconds(stream.metadata.DURATION); | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,7 +60,7 @@ describe('FrameFusion', () => { | |||||
await extractor.dispose(); | ||||||
}); | ||||||
|
||||||
it('can get duration', async() => { | ||||||
it('can get duration from mp4', async() => { | ||||||
// Arrange | ||||||
const extractor = await BeamcoderExtractor.create({ | ||||||
inputFileOrUrl: 'https://storage.googleapis.com/lumen5-prod-images/countTo60.mp4', | ||||||
|
@@ -73,6 +73,19 @@ describe('FrameFusion', () => { | |||||
await extractor.dispose(); | ||||||
}); | ||||||
|
||||||
it.only('can get duration from webm', async() => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Arrange | ||||||
const extractor = await BeamcoderExtractor.create({ | ||||||
inputFileOrUrl: 'https://storage.googleapis.com/lumen5-prod-video/anita-6uTzyZtNRKztypC.webm', | ||||||
}); | ||||||
|
||||||
// Act and Assert | ||||||
expect(extractor.duration).to.equal(115); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @animanathome can we use test data which we inspect in this repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you mean with that @stepancar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work for you locally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @animanathome I mean, can we put that video to this repo directly so it would be easy to call ffprobe |
||||||
|
||||||
// Cleanup | ||||||
await extractor.dispose(); | ||||||
}); | ||||||
|
||||||
it('can get duration when audio stream is longer than video stream', async() => { | ||||||
// Arrange | ||||||
const extractor = await BeamcoderExtractor.create({ | ||||||
|
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.
Hm, when I was playing with libav, I noticed that duration is negative sometimes. are we sure it's not the case here?
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 duration is "null" in this case.