ffmpeg 将视频解码为 YUV 和损坏的像素
ffmpeg decode video to YUV and damaged pixels
我用this example to decode a mpeg1 video
解码开始时
log(每 3 到 10 帧):
[mpeg1video @ 0x5626caf74e40] ac-tex damaged at 39 15
[mpeg1video @ 0x5626caf74e40] Warning MVs not available
[mpeg1video @ 0x5626caf74e40] concealing 405 DC, 405 AC, 405 MV errors in P frame
结果是:
我尝试使用 opencv 从 YUV 制作 rgb,但 rgb 结果相同
cv::Size actual_size(frame->width, frame->height);
cv::Size half_size(frame->width/2, frame->height/2);
cv::Mat y(actual_size, CV_8UC1, frame->data[0]);
cv::Mat u(half_size, CV_8UC1, frame->data[1]);
cv::Mat v(half_size, CV_8UC1, frame->data[2]);
cv::Mat u_resized, v_resized;
cv::resize(u, u_resized, actual_size, 0, 0, cv::INTER_NEAREST); //repeat u values 4 times
cv::resize(v, v_resized, actual_size, 0, 0, cv::INTER_NEAREST); //repeat v values 4 times
cv::Mat yuv;
std::vector<cv::Mat> yuv_channels = { y, u_resized, v_resized };
cv::merge(yuv_channels, yuv);
cv::Mat bgr;
cv::cvtColor(yuv, bgr, cv::COLOR_YUV2BGR);
cv::imshow("x",bgr);
cv::waitKey(1000/25);
问题已通过使用 mpeg2 video 和 AV_CODEC_ID_MPEG2VIDEO
解决
codec = avcodec_find_decoder(AV_CODEC_ID_MPEG2VIDEO);
我用this example to decode a mpeg1 video
解码开始时
log(每 3 到 10 帧):
[mpeg1video @ 0x5626caf74e40] ac-tex damaged at 39 15
[mpeg1video @ 0x5626caf74e40] Warning MVs not available
[mpeg1video @ 0x5626caf74e40] concealing 405 DC, 405 AC, 405 MV errors in P frame
结果是:
我尝试使用 opencv 从 YUV 制作 rgb,但 rgb 结果相同
cv::Size actual_size(frame->width, frame->height);
cv::Size half_size(frame->width/2, frame->height/2);
cv::Mat y(actual_size, CV_8UC1, frame->data[0]);
cv::Mat u(half_size, CV_8UC1, frame->data[1]);
cv::Mat v(half_size, CV_8UC1, frame->data[2]);
cv::Mat u_resized, v_resized;
cv::resize(u, u_resized, actual_size, 0, 0, cv::INTER_NEAREST); //repeat u values 4 times
cv::resize(v, v_resized, actual_size, 0, 0, cv::INTER_NEAREST); //repeat v values 4 times
cv::Mat yuv;
std::vector<cv::Mat> yuv_channels = { y, u_resized, v_resized };
cv::merge(yuv_channels, yuv);
cv::Mat bgr;
cv::cvtColor(yuv, bgr, cv::COLOR_YUV2BGR);
cv::imshow("x",bgr);
cv::waitKey(1000/25);
问题已通过使用 mpeg2 video 和 AV_CODEC_ID_MPEG2VIDEO
解决codec = avcodec_find_decoder(AV_CODEC_ID_MPEG2VIDEO);