Skip to content

Commit

Permalink
fix: calculate nb_frames for vp8 codec when it is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
ForeverSc committed Jul 20, 2024
1 parent 08f507d commit 7743a20
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/web-demuxer/web_demuxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ 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;

int64_t nb_frames = raw_stream->nb_frames;

// vp8 codec does not have nb_frames
if (nb_frames == 0) {
nb_frames = (fmt_ctx->duration * (double)raw_stream->avg_frame_rate.num) / ((double)raw_stream->avg_frame_rate.den * AV_TIME_BASE);
}

stream->nb_frames = nb_frames;

avformat_close_input(&fmt_ctx);

Expand Down

0 comments on commit 7743a20

Please sign in to comment.