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 ffmpeg-wasm-demuxer sample #549

Closed
wants to merge 5 commits into from
Closed

Conversation

chcunningham
Copy link
Collaborator

@chcunningham chcunningham commented Sep 3, 2022

@chcunningham
Copy link
Collaborator Author

@sandersdan, friendly ping :)

// while the data-to-be-read is being asynchronously fetched from the network.

self.debugLog = function(msg) {
console.debug('[blocking worker]' + msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: , msg) would allow more message types.

// Blocking is required because FFmpeg's AVIO read callback is synchronous,
// while the data-to-be-read is being asynchronously fetched from the network.

self.debugLog = function(msg) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This is the same as function debugLog(msg) {

console.debug('[blocking worker]' + msg);
}

debugLog(` -- worker started`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: -- not required with above change.
Nit: Template string literal not necessary for static string.


debugLog(` -- worker started`);

import {FFmpegDemuxerBlockingHelper} from './ffmpeg_demuxer_blocking_helper.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work? When did it start working? (Even recently I was forced to use importSync() in worker contexts.)

self.addEventListener('message', onMessage);

async function onMessage(e) {
// debugLog(`Blocking demuxer worker message: ${JSON.stringify(e.data)}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: remove commented code.

this.#readPtr += numBytes;
}

_onChunk(chunk) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Private methods can also just be # (although there may be cases where that is impossible because a "caller" is external; # private is very private).

import {SharedReadBuffer} from './shared_read_buffer.js'
import {PullDemuxerBase, AUDIO_STREAM_TYPE, VIDEO_STREAM_TYPE} from '../library/pull_demuxer_base.js'

let Module = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: module, or better wasmModule.

@@ -0,0 +1,29 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

File seems incomplete?

let audioRenderer = null;

self.addEventListener('message', async function(e) {
// console.info(`Worker message: ${JSON.stringify(e.data)}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Remove commented code.

Base automatically changed from pull-demuxer-interface to main October 10, 2022 05:52
@aboba aboba added the samples label Oct 21, 2022
@dalecurtis
Copy link
Contributor

Chris left Google and unfortunately won't be able to complete this PR. Chris you mentioned you might want to try to close this out still. Did you want me to leave this open for a bit longer?

@dalecurtis dalecurtis mentioned this pull request Apr 11, 2023
@KevinBoeing
Copy link

Did somebody already tried to demux a file with a video and audiostream?

Currently I get the following warnings from FFmpeg:

  • parser not found for codec h264, packets or times may be invalid.
  • Could not find codec parameters for stream 0 (Video: h264, 1 reference frame (avc1 / 0x31637661), none, 1280x720 (0x0), 0/1, 2322 kb/s): unspecified pixel format
  • Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
  • Could not find codec parameters for stream 1 (Audio: aac (mp4a / 0x6134706D), 48000 Hz, 1 channels, 69 kb/s): unspecified sample format
  • Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options

When I try to read a Chunk, FFmpeg gives me the following error:

Invalid data found when processing input

@dalecurtis
Copy link
Contributor

This copy of ffmpeg is built without proprietary codecs, otherwise we wouldn't be able to host/share it. You'll have to tweak the ffmpeg build options if you want other codecs enabled.

@dalecurtis
Copy link
Contributor

Going to close this PR for now since we don't have anyone to finish it at this time. Others are welcome to clean it up and land it if they're so inclined.

@dalecurtis dalecurtis closed this Apr 18, 2023
@chrisn
Copy link
Member

chrisn commented Apr 18, 2023

I'm interested to have a look at this if I can make some time.

@KevinBoeing
Copy link

Hey, sorry that I still comment under a closed PR but I am currently working on it. I am almost finished with this project, but have two thing I still dont understand / I am struggling with.

  1. Is there an easy way to create a codec string using FFmpeg as required by the WebCodecs decoder configurations (e.g. mp4a.40.2)? I am already aware that I can get important codec information from the AVCodecParameters structure. The prefix (e.g. mp4a) can be determined by the codec_tag property and other important information is in my opinion the codec-profile and the codec-level. However, I'm still not sure how to get a mapping between the FFmpeg AVCodecParameters and the WebCodecs codec string.

  2. In the FFmpegDemuxerBlockingHelper class, the AVIO_BUFFER_SIZE is set to 4,000 bytes. If I increase this value to 20,000 bytes, it works fine with a container that contains only a video stream or an audio stream. If it contains both, I need to set the AVIO_BUFFER_SIZE to the bytes of the container. Otherwise I get a "stream 0/1, offset 0x30 partial file" warning from ffmpeg and when I try to read the next frame (av_read_frame()), I get an error "Invalid data found when processing input". Is it correct that I always have to set the AVIO_BUFFER_SIZE to the size of the container or is there a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants