File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,16 @@ extern "C" {
2626#error "FFmpeg 5.0+ (libavcodec 59+) is required"
2727#endif
2828
29+ // AVFrame::duration was added in FFmpeg 5.1 (libavutil 57.28.100)
30+ // Before that, use pkt_duration (deprecated in 5.1+)
31+ #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
32+ #define AV_FRAME_DURATION (frame ) ((frame)->duration)
33+ #define AV_FRAME_SET_DURATION (frame, val ) ((frame)->duration = (val))
34+ #else
35+ #define AV_FRAME_DURATION (frame ) ((frame)->pkt_duration)
36+ #define AV_FRAME_SET_DURATION (frame, val ) ((frame)->pkt_duration = (val))
37+ #endif
38+
2939namespace webcodecs {
3040
3141// ==============================================================================
Original file line number Diff line number Diff line change @@ -546,8 +546,8 @@ bool ImageDecoder::ParseAnimatedImageMetadata() {
546546
547547 // Duration from packet or frame
548548 int64_t duration = pkt->duration ;
549- if (duration <= 0 && frm-> duration > 0 ) {
550- duration = frm-> duration ;
549+ if (duration <= 0 && AV_FRAME_DURATION ( frm. get ()) > 0 ) {
550+ duration = AV_FRAME_DURATION ( frm. get ()) ;
551551 }
552552 if (duration > 0 ) {
553553 decoded_frame.duration =
Original file line number Diff line number Diff line change @@ -526,7 +526,7 @@ Napi::Value VideoEncoder::Encode(const Napi::CallbackInfo& info) {
526526 frame->height = video_frame->GetHeight ();
527527 frame->format = AV_PIX_FMT_RGBA ;
528528 frame->pts = video_frame->GetTimestampValue ();
529- frame-> duration = video_frame->GetDurationValue ();
529+ AV_FRAME_SET_DURATION ( frame. get (), video_frame->GetDurationValue () );
530530
531531 // Copy RGBA data
532532 size_t data_size = frame->width * frame->height * kBytesPerPixelRgba ;
Original file line number Diff line number Diff line change @@ -341,7 +341,7 @@ void VideoEncoderWorker::OnEncode(const EncodeMessage& msg) {
341341 int src_width = src_frame->width ;
342342 int src_height = src_frame->height ;
343343 int64_t timestamp = src_frame->pts ;
344- int64_t duration = src_frame-> duration ;
344+ int64_t duration = AV_FRAME_DURATION ( src_frame) ;
345345
346346 // For RGBA input, convert to YUV420P
347347 // The source frame contains RGBA data packed in data[0]
You can’t perform that action at this time.
0 commit comments