Commit f9e80201 authored by Michael Niedermayer's avatar Michael Niedermayer

ffplay: unify displaymatrix based rotation code

Reviewed-by: 's avatarMarton Balint <cus@passwd.hu>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 372aa077
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/colorspace.h" #include "libavutil/colorspace.h"
#include "libavutil/display.h" #include "libavutil/display.h"
#include "libavutil/eval.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h" #include "libavutil/imgutils.h"
...@@ -2020,31 +2021,31 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c ...@@ -2020,31 +2021,31 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
AVDictionaryEntry *rotate_tag = av_dict_get(is->video_st->metadata, "rotate", NULL, 0); AVDictionaryEntry *rotate_tag = av_dict_get(is->video_st->metadata, "rotate", NULL, 0);
uint8_t* displaymatrix = av_stream_get_side_data(is->video_st, uint8_t* displaymatrix = av_stream_get_side_data(is->video_st,
AV_PKT_DATA_DISPLAYMATRIX, NULL); AV_PKT_DATA_DISPLAYMATRIX, NULL);
double theta = 0;
if (rotate_tag && *rotate_tag->value && strcmp(rotate_tag->value, "0")) { if (rotate_tag && *rotate_tag->value && strcmp(rotate_tag->value, "0")) {
if (!strcmp(rotate_tag->value, "90")) { char *tail;
theta = av_strtod(rotate_tag->value, &tail);
if (*tail)
theta = 0;
}
if (displaymatrix && !theta)
theta = av_display_rotation_get((int32_t*) displaymatrix);
theta -= 360*floor(theta/360 + 0.9/360);
if (fabs(theta - 90) < 1.0) {
INSERT_FILT("transpose", "clock"); INSERT_FILT("transpose", "clock");
} else if (!strcmp(rotate_tag->value, "180")) { } else if (fabs(theta - 180) < 1.0) {
INSERT_FILT("hflip", NULL); INSERT_FILT("hflip", NULL);
INSERT_FILT("vflip", NULL); INSERT_FILT("vflip", NULL);
} else if (!strcmp(rotate_tag->value, "270")) { } else if (fabs(theta - 270) < 1.0) {
INSERT_FILT("transpose", "cclock"); INSERT_FILT("transpose", "cclock");
} else { } else if (fabs(theta) > 1.0) {
char rotate_buf[64]; char rotate_buf[64];
snprintf(rotate_buf, sizeof(rotate_buf), "%s*PI/180", rotate_tag->value); snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta);
INSERT_FILT("rotate", rotate_buf); INSERT_FILT("rotate", rotate_buf);
} }
} else if (displaymatrix) {
double rot = av_display_rotation_get((int32_t*) displaymatrix);
if (rot < -135 || rot > 135) {
INSERT_FILT("vflip", NULL);
INSERT_FILT("hflip", NULL);
} else if (rot < -45) {
INSERT_FILT("transpose", "dir=clock");
} else if (rot > 45) {
INSERT_FILT("transpose", "dir=cclock");
}
}
} }
if ((ret = configure_filtergraph(graph, vfilters, filt_src, last_filter)) < 0) if ((ret = configure_filtergraph(graph, vfilters, filt_src, last_filter)) < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment