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

LU-3510 Adding duration support for webm #61

Merged
merged 6 commits into from
Oct 28, 2024
Merged

Conversation

animanathome
Copy link
Contributor

The stream's duration can be null. In those cases, the duration may be described as part of the stream's metadata. We found that in our webm's generated by D-ID. In this PR, we add to return the stream's metadata's duration if available.

{
  "type": "Stream",
  "index": 0,
  "id": 0,
  "time_base": [
    1,
    1000
  ],
  "start_time": 0,
  "duration": null,
  "sample_aspect_ratio": [
    1,
    1
  ],
  "metadata": {
    "alpha_mode": "1",
    "ENCODER": "Lavc60.3.100 libvpx-vp9",
    "DURATION": "00:01:55.000000000"
  },
  "avg_frame_rate": [
    25,
    1
  ],
  "event_flags": {
    "METADATA_UPDATED": false
  },
  "r_frame_rate": [
    25,
    1
  ],
  "codecpar": {
    "type": "CodecParameters",
    "codec_type": "video",
    "codec_id": 167,
    "name": "vp9",
    "format": "yuv420p",
    "profile": "Profile 0",
    "width": 1080,
    "height": 1080,
    "field_order": "progressive",
    "color_range": "tv"
  }
}

@animanathome animanathome changed the title Adding duration support for webm LU-3510 Adding duration support for webm Oct 26, 2024
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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -73,6 +73,19 @@ describe('FrameFusion', () => {
await extractor.dispose();
});

it.only('can get duration from webm', async() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it.only('can get duration from webm', async() => {
it('can get duration from webm', async() => {

});

// Act and Assert
expect(extractor.duration).to.equal(115);
Copy link
Contributor

Choose a reason for hiding this comment

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

@animanathome can we use test data which we inspect in this repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean with that @stepancar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work for you locally?

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

@stepancar stepancar left a comment

Choose a reason for hiding this comment

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

Just a minor question

if (stream.duration !== null) {
return this.ptsToTime(stream.duration);
}
if (stream?.metadata?.DURATION) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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://ffmpeg.org/doxygen/7.0/structAVStream.html#a4e04af7a5a4d8298649850df798dd0bc
Have you tried this?

https://stackoverflow.com/a/27208276
it seems like beamocoder executes similar code under the hood, so, the duration should be available somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that stream.duration is null in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

exactly , beamcoder executes code from stack overflow and it expands avformat context

@animanathome animanathome merged commit 9228fc8 into main Oct 28, 2024
1 check passed
@animanathome animanathome deleted the LU-3510-WebmDuration branch October 28, 2024 15:24
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.

2 participants