Skip to content

Commit

Permalink
feat: add nb_frames to WebAVStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ForeverSc committed Jul 18, 2024
1 parent 2f88068 commit c4e09de
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ WEB_DEMUXER_ARGS = \
-s EXPORTED_RUNTIME_METHODS=cwrap,getValue,UTF8ToString \
-s EXPORTED_FUNCTIONS=_free \
-s ASYNCIFY \
-s WASM_BIGINT \
-s ALLOW_MEMORY_GROWTH=1

clean:
Expand Down
4 changes: 3 additions & 1 deletion lib/web-demuxer/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function getAVStream(file, type = 0, streamIndex = -1) {
const id = Module.getValue(av_stream_ptr + 4, "i32");
const start_time = Module.getValue(av_stream_ptr + 8, "double");
const duration = Module.getValue(av_stream_ptr + 16, "double");
const codecpar_ptr = Module.getValue(av_stream_ptr + 24, "*");
const nb_frames = Module.getValue(av_stream_ptr + 24, "i64");
const codecpar_ptr = Module.getValue(av_stream_ptr + 32, "*");
const codecpar_codec_string_ptr = Module.getValue(codecpar_ptr + 8, "i8*");
let codecpar = {
codec_type: Module.getValue(codecpar_ptr, "i32"),
Expand Down Expand Up @@ -63,6 +64,7 @@ function getAVStream(file, type = 0, streamIndex = -1) {
codecpar,
start_time,
duration,
nb_frames
};

// free wasm memory
Expand Down
1 change: 1 addition & 0 deletions lib/web-demuxer/web_demuxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ WebAVStream *EMSCRIPTEN_KEEPALIVE get_av_stream(const char *filename, int type,
stream->id = raw_stream->id;
stream->start_time = raw_stream->start_time * av_q2d(raw_stream->time_base);
stream->duration = raw_stream->duration > 0 ? raw_stream->duration * av_q2d(raw_stream->time_base) : fmt_ctx->duration * av_q2d(AV_TIME_BASE_Q); // TODO: some file type can not get stream duration
stream->nb_frames = raw_stream->nb_frames;

avformat_close_input(&fmt_ctx);

Expand Down
1 change: 1 addition & 0 deletions lib/web-demuxer/web_demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct {
int id;
double start_time;
double duration;
int64_t nb_frames;
WebAVCodecParameters *codecpar;
} WebAVStream;

Expand Down
1 change: 1 addition & 0 deletions src/types/demuxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface WebAVStream {
id: number;
start_time: number;
duration: number;
nb_frames: number;
codecpar: WebAVCodecParameters;
}

Expand Down

0 comments on commit c4e09de

Please sign in to comment.