Skip to content

Commit

Permalink
Extra checks for rotation metadata support.
Browse files Browse the repository at this point in the history
  • Loading branch information
asmorkalov committed Jun 22, 2020
1 parent 9d7a47c commit 32912e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 23 additions & 2 deletions modules/videoio/src/cap_ffmpeg_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,17 @@ void CvCapture_FFMPEG::init()
frame_number = 0;
eps_zero = 0.000025;

rotation_auto = true;
rotation_angle = 0;

#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)
#if (LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0))
#if (LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 92, 100))
rotation_auto = true;
#else
rotation_auto = false;
#endif
dict = NULL;
#else
rotation_auto = false;
#endif

rawMode = false;
Expand Down Expand Up @@ -1458,7 +1464,12 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
case CV_FFMPEG_CAP_PROP_ORIENTATION_META:
return static_cast<double>(rotation_angle);
case CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO:
#if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
(LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 92, 100)))
return static_cast<double>(rotation_auto);
#else
return 0;
#endif
default:
break;
}
Expand Down Expand Up @@ -1540,9 +1551,12 @@ double CvCapture_FFMPEG::dts_to_sec(int64_t dts) const
void CvCapture_FFMPEG::get_rotation_angle()
{
rotation_angle = 0;
#if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
(LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 94, 100)))
AVDictionaryEntry *rotate_tag = av_dict_get(video_st->metadata, "rotate", NULL, 0);
if (rotate_tag != NULL)
rotation_angle = atoi(rotate_tag->value);
#endif
}

void CvCapture_FFMPEG::seek(int64_t _frame_number)
Expand Down Expand Up @@ -1641,7 +1655,14 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value )
return setRaw();
return false;
case CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO:
#if ((LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)) && \
(LIBAVUTIL_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0)))
rotation_auto = static_cast<bool>(value);
return true;
#else
rotation_auto = 0;
return false;
#endif
break;
default:
return false;
Expand Down
5 changes: 4 additions & 1 deletion modules/videoio/test/test_ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ TEST(videoio, mp4_orientation_meta_auto)
VideoCapture cap;
EXPECT_NO_THROW(cap.open(video_file, CAP_FFMPEG));
ASSERT_TRUE(cap.isOpened()) << "Can't open the video: " << video_file << " with backend " << CAP_FFMPEG << std::endl;
ASSERT_TRUE(cap.get(CAP_PROP_ORIENTATION_AUTO));

cap.set(CAP_PROP_ORIENTATION_AUTO, true);
if (cap.get(CAP_PROP_ORIENTATION_AUTO) == 0)
throw SkipTestException("FFmpeg frame rotation metadata is not supported");

Size actual;
EXPECT_NO_THROW(actual = Size((int)cap.get(CAP_PROP_FRAME_WIDTH),
Expand Down

0 comments on commit 32912e8

Please sign in to comment.