mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Merge pull request #22333 from cudawarped:fix_for_21101
Fix video codec fourcc #21101
This commit is contained in:
commit
42561e1233
@ -1699,7 +1699,7 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
|
||||
return (double)av_get_picture_type_char(picture->pict_type);
|
||||
case CAP_PROP_FPS:
|
||||
return get_fps();
|
||||
case CAP_PROP_FOURCC:
|
||||
case CAP_PROP_FOURCC: {
|
||||
codec_id = video_st->CV_FFMPEG_CODEC_FIELD->codec_id;
|
||||
codec_tag = (double) video_st->CV_FFMPEG_CODEC_FIELD->codec_tag;
|
||||
|
||||
@ -1709,12 +1709,26 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
|
||||
}
|
||||
|
||||
codec_fourcc = _opencv_avcodec_get_name(codec_id);
|
||||
if(!codec_fourcc || strlen(codec_fourcc) < 4 || strcmp(codec_fourcc, "unknown_codec") == 0)
|
||||
if (!codec_fourcc || strcmp(codec_fourcc, "unknown_codec") == 0 || strlen(codec_fourcc) != 4)
|
||||
{
|
||||
return codec_tag;
|
||||
const struct AVCodecTag* fallback_tags[] = {
|
||||
// APIchanges:
|
||||
// 2012-01-31 - dd6d3b0 - lavf 54.01.0
|
||||
// Add avformat_get_riff_video_tags() and avformat_get_riff_audio_tags().
|
||||
avformat_get_riff_video_tags(),
|
||||
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 25, 100) && defined LIBAVFORMAT_VERSION_MICRO && LIBAVFORMAT_VERSION_MICRO >= 100
|
||||
// APIchanges: ffmpeg only
|
||||
// 2014-01-19 - 1a193c4 - lavf 55.25.100 - avformat.h
|
||||
// Add avformat_get_mov_video_tags() and avformat_get_mov_audio_tags().
|
||||
avformat_get_mov_video_tags(),
|
||||
#endif
|
||||
codec_bmp_tags, // fallback for avformat < 54.1
|
||||
NULL };
|
||||
return av_codec_get_tag(fallback_tags, codec_id);
|
||||
}
|
||||
|
||||
return (double) CV_FOURCC(codec_fourcc[0], codec_fourcc[1], codec_fourcc[2], codec_fourcc[3]);
|
||||
}
|
||||
case CAP_PROP_SAR_NUM:
|
||||
return _opencv_ffmpeg_get_sample_aspect_ratio(ic->streams[video_stream]).num;
|
||||
case CAP_PROP_SAR_DEN:
|
||||
|
@ -399,7 +399,37 @@ const ffmpeg_cap_properties_param_t videoio_ffmpeg_properties[] = {
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(videoio, ffmpeg_cap_properties, testing::ValuesIn(videoio_ffmpeg_properties));
|
||||
|
||||
typedef tuple<string, string> ffmpeg_get_fourcc_param_t;
|
||||
typedef testing::TestWithParam<ffmpeg_get_fourcc_param_t> ffmpeg_get_fourcc;
|
||||
|
||||
TEST_P(ffmpeg_get_fourcc, check_short_codecs)
|
||||
{
|
||||
const VideoCaptureAPIs api = CAP_FFMPEG;
|
||||
if (!videoio_registry::hasBackend(api))
|
||||
throw SkipTestException("Backend was not found");
|
||||
const string fileName = get<0>(GetParam());
|
||||
const string fourcc_string = get<1>(GetParam());
|
||||
VideoCapture cap(findDataFile(fileName), api);
|
||||
if (!cap.isOpened())
|
||||
throw SkipTestException("Video stream is not supported");
|
||||
const double fourcc = cap.get(CAP_PROP_FOURCC);
|
||||
#ifdef _WIN32 // handle old FFmpeg backend
|
||||
if(!fourcc && fileName == "../cv/tracking/faceocc2/data/faceocc2.webm")
|
||||
throw SkipTestException("Feature not yet supported by Windows FFmpeg shared library!");
|
||||
#endif
|
||||
ASSERT_EQ(fourccToString(fourcc), fourcc_string);
|
||||
}
|
||||
|
||||
const ffmpeg_get_fourcc_param_t ffmpeg_get_fourcc_param[] =
|
||||
{
|
||||
ffmpeg_get_fourcc_param_t("../cv/tracking/faceocc2/data/faceocc2.webm", "VP80"),
|
||||
ffmpeg_get_fourcc_param_t("video/sample_322x242_15frames.yuv420p.libvpx-vp9.mp4", "vp09"),
|
||||
ffmpeg_get_fourcc_param_t("video/sample_322x242_15frames.yuv420p.libaom-av1.mp4", "av01"),
|
||||
ffmpeg_get_fourcc_param_t("video/big_buck_bunny.h265", "hevc"),
|
||||
ffmpeg_get_fourcc_param_t("video/big_buck_bunny.h264", "h264")
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(videoio, ffmpeg_get_fourcc, testing::ValuesIn(ffmpeg_get_fourcc_param));
|
||||
|
||||
// related issue: https://github.com/opencv/opencv/issues/15499
|
||||
TEST(videoio, mp4_orientation_meta_auto)
|
||||
|
Loading…
Reference in New Issue
Block a user