@@ -729,6 +729,31 @@ void FFmpegReader::UpdateVideoInfo() {
729729 info.display_ratio .num = size.num ;
730730 info.display_ratio .den = size.den ;
731731
732+ // Get scan type and order from codec context/params
733+ if (!check_interlace) {
734+ check_interlace = true ;
735+ AVFieldOrder field_order = AV_GET_CODEC_ATTRIBUTES (pStream, pCodecCtx)->field_order ;
736+ switch (field_order) {
737+ case AV_FIELD_PROGRESSIVE:
738+ info.interlaced_frame = false ;
739+ break ;
740+ case AV_FIELD_TT:
741+ case AV_FIELD_TB:
742+ info.interlaced_frame = true ;
743+ info.top_field_first = true ;
744+ break ;
745+ case AV_FIELD_BT:
746+ case AV_FIELD_BB:
747+ info.interlaced_frame = true ;
748+ info.top_field_first = false ;
749+ break ;
750+ case AV_FIELD_UNKNOWN:
751+ // Check again later?
752+ check_interlace = false ;
753+ break ;
754+ }
755+ }
756+
732757 // Set the video timebase
733758 info.video_timebase .num = pStream->time_base .num ;
734759 info.video_timebase .den = pStream->time_base .den ;
@@ -1078,14 +1103,14 @@ bool FFmpegReader::GetAVFrame() {
10781103 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::GetAVFrame (Packet not sent)" );
10791104 }
10801105 else {
1081- AVFrame *next_frame2;
1082- if (hw_de_on && hw_de_supported) {
1083- next_frame2 = AV_ALLOCATE_FRAME ();
1084- }
1085- else
1086- {
1087- next_frame2 = next_frame;
1088- }
1106+ AVFrame *next_frame2;
1107+ if (hw_de_on && hw_de_supported) {
1108+ next_frame2 = AV_ALLOCATE_FRAME ();
1109+ }
1110+ else
1111+ {
1112+ next_frame2 = next_frame;
1113+ }
10891114 pFrame = AV_ALLOCATE_FRAME ();
10901115 while (ret >= 0 ) {
10911116 ret = avcodec_receive_frame (pCodecCtx, next_frame2);
@@ -1119,11 +1144,6 @@ bool FFmpegReader::GetAVFrame() {
11191144 av_image_alloc (pFrame->data , pFrame->linesize , info.width , info.height , (AVPixelFormat)(pStream->codecpar ->format ), 1 );
11201145 av_image_copy (pFrame->data , pFrame->linesize , (const uint8_t **)next_frame->data , next_frame->linesize ,
11211146 (AVPixelFormat)(pStream->codecpar ->format ), info.width , info.height );
1122- if (!check_interlace) {
1123- check_interlace = true ;
1124- info.interlaced_frame = next_frame->interlaced_frame ;
1125- info.top_field_first = next_frame->top_field_first ;
1126- }
11271147 }
11281148 }
11291149 if (hw_de_on && hw_de_supported) {
@@ -1143,13 +1163,6 @@ bool FFmpegReader::GetAVFrame() {
11431163 avpicture_alloc ((AVPicture *) pFrame, pCodecCtx->pix_fmt , info.width , info.height );
11441164 av_picture_copy ((AVPicture *) pFrame, (AVPicture *) next_frame, pCodecCtx->pix_fmt , info.width ,
11451165 info.height );
1146-
1147- // Detect interlaced frame (only once)
1148- if (!check_interlace) {
1149- check_interlace = true ;
1150- info.interlaced_frame = next_frame->interlaced_frame ;
1151- info.top_field_first = next_frame->top_field_first ;
1152- }
11531166 }
11541167#endif
11551168 }
0 commit comments