| 1029 | } |
| 1030 | |
| 1031 | void FFmpegReader::UpdateVideoInfo() { |
| 1032 | if (info.vcodec.length() > 0) { |
| 1033 | // Skip init - if info struct already populated |
| 1034 | return; |
| 1035 | } |
| 1036 | |
| 1037 | auto record_duration = [](double &target, double seconds) { |
| 1038 | if (seconds > 0.0) |
| 1039 | target = std::max(target, seconds); |
| 1040 | }; |
| 1041 | |
| 1042 | // Set values of FileInfo struct |
| 1043 | info.has_video = true; |
| 1044 | info.file_size = pFormatCtx->pb ? avio_size(pFormatCtx->pb) : -1; |
| 1045 | info.height = AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->height; |
| 1046 | info.width = AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->width; |
| 1047 | info.vcodec = pCodecCtx->codec->name; |
| 1048 | info.video_bit_rate = (pFormatCtx->bit_rate / 8); |
| 1049 | |
| 1050 | // Frame rate from the container and codec |
| 1051 | AVRational framerate = av_guess_frame_rate(pFormatCtx, pStream, NULL); |
| 1052 | if (!check_fps) { |
| 1053 | info.fps.num = framerate.num; |
| 1054 | info.fps.den = framerate.den; |
| 1055 | } |
| 1056 | |
| 1057 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdateVideoInfo", "info.fps.num", info.fps.num, "info.fps.den", info.fps.den); |
| 1058 | |
| 1059 | // TODO: remove excessive debug info in the next releases |
| 1060 | // The debug info below is just for comparison and troubleshooting on users side during the transition period |
| 1061 | ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdateVideoInfo (pStream->avg_frame_rate)", "num", pStream->avg_frame_rate.num, "den", pStream->avg_frame_rate.den); |
| 1062 | |
| 1063 | if (pStream->sample_aspect_ratio.num != 0) { |
| 1064 | info.pixel_ratio.num = pStream->sample_aspect_ratio.num; |
| 1065 | info.pixel_ratio.den = pStream->sample_aspect_ratio.den; |
| 1066 | } else if (AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->sample_aspect_ratio.num != 0) { |
| 1067 | info.pixel_ratio.num = AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->sample_aspect_ratio.num; |
| 1068 | info.pixel_ratio.den = AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->sample_aspect_ratio.den; |
| 1069 | } else { |
| 1070 | info.pixel_ratio.num = 1; |
| 1071 | info.pixel_ratio.den = 1; |
| 1072 | } |
| 1073 | info.pixel_format = AV_GET_CODEC_PIXEL_FORMAT(pStream, pCodecCtx); |
| 1074 | |
| 1075 | // Calculate the DAR (display aspect ratio) |
| 1076 | Fraction size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den); |
| 1077 | |
| 1078 | // Reduce size fraction |
| 1079 | size.Reduce(); |
| 1080 | |
| 1081 | // Set the ratio based on the reduced fraction |
| 1082 | info.display_ratio.num = size.num; |
| 1083 | info.display_ratio.den = size.den; |
| 1084 | |
| 1085 | // Get scan type and order from codec context/params |
| 1086 | if (!check_interlace) { |
| 1087 | check_interlace = true; |
| 1088 | AVFieldOrder field_order = AV_GET_CODEC_ATTRIBUTES(pStream, pCodecCtx)->field_order; |
nothing calls this directly
no test coverage detected