@@ -316,13 +316,23 @@ tvh_video_context_encode(TVHContext *self, AVFrame *avframe)
316316 return AVERROR (EAGAIN );
317317 }
318318 self -> pts = avframe -> pts ;
319+ #if LIBAVUTIL_VERSION_MAJOR > 58 || (LIBAVUTIL_VERSION_MAJOR == 58 && LIBAVUTIL_VERSION_MINOR > 2 )
320+ if (avframe -> flags & AV_FRAME_FLAG_INTERLACED ) {
321+ self -> oavctx -> field_order =
322+ (avframe -> flags & AV_FRAME_FLAG_TOP_FIELD_FIRST ) ? AV_FIELD_TB : AV_FIELD_BT ;
323+ }
324+ else {
325+ self -> oavctx -> field_order = AV_FIELD_PROGRESSIVE ;
326+ }
327+ #else
319328 if (avframe -> interlaced_frame ) {
320329 self -> oavctx -> field_order =
321330 avframe -> top_field_first ? AV_FIELD_TB : AV_FIELD_BT ;
322331 }
323332 else {
324333 self -> oavctx -> field_order = AV_FIELD_PROGRESSIVE ;
325334 }
335+ #endif
326336 return 0 ;
327337}
328338
@@ -347,15 +357,24 @@ tvh_video_context_wrap(TVHContext *self, AVPacket *avpkt, th_pkt_t *pkt)
347357 pict_type = AV_PICTURE_TYPE_I ;
348358 }
349359 if (pict_type == AV_PICTURE_TYPE_NONE ) {
350- // some codecs do not set pict_type but set key_frame , in this case,
351- // we assume that when key_frame == 1 the frame is an I-frame
360+ // some codecs do not set pict_type but set AV_FRAME_FLAG_KEY , in this case,
361+ // we assume that when AV_FRAME_FLAG_KEY is set the frame is an I-frame
352362 // (all the others are assumed to be P-frames)
363+ #if LIBAVUTIL_VERSION_MAJOR > 58 || (LIBAVUTIL_VERSION_MAJOR == 58 && LIBAVUTIL_VERSION_MINOR > 2 )
364+ if (self -> oavframe -> flags & AV_FRAME_FLAG_KEY ) {
365+ pict_type = AV_PICTURE_TYPE_I ;
366+ }
367+ else {
368+ pict_type = AV_PICTURE_TYPE_P ;
369+ }
370+ #else
353371 if (self -> oavframe -> key_frame ) {
354372 pict_type = AV_PICTURE_TYPE_I ;
355373 }
356374 else {
357375 pict_type = AV_PICTURE_TYPE_P ;
358376 }
377+ #endif
359378 }
360379
361380 switch (pict_type ) {
0 commit comments