From 800df6a849c81ee74ad770e4551327aa2159336c Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sun, 3 May 2015 23:53:32 +0200 Subject: [PATCH] ffmpeg_filter: use get_rotation() This unifies the rotation extraction code between ffplay and ffmpeg Signed-off-by: Michael Niedermayer --- ffmpeg_filter.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c index 6a891d3d10..0be49bea87 100644 --- a/ffmpeg_filter.c +++ b/ffmpeg_filter.c @@ -700,23 +700,24 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, last_filter = ifilter->filter; if (ist->autorotate) { - uint8_t* displaymatrix = av_stream_get_side_data(ist->st, - AV_PKT_DATA_DISPLAYMATRIX, NULL); - if (displaymatrix) { - double rot = av_display_rotation_get((int32_t*) displaymatrix); - if (rot < -135 || rot > 135) { - ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL); - if (ret < 0) - return ret; - ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL); - } else if (rot < -45) { - ret = insert_filter(&last_filter, &pad_idx, "transpose", "dir=clock"); - } else if (rot > 45) { - ret = insert_filter(&last_filter, &pad_idx, "transpose", "dir=cclock"); - } + double theta = get_rotation(ist->st); + + if (fabs(theta - 90) < 1.0) { + ret = insert_filter(&last_filter, &pad_idx, "transpose", "clock"); + } else if (fabs(theta - 180) < 1.0) { + ret = insert_filter(&last_filter, &pad_idx, "hflip", NULL); if (ret < 0) return ret; + ret = insert_filter(&last_filter, &pad_idx, "vflip", NULL); + } else if (fabs(theta - 270) < 1.0) { + ret = insert_filter(&last_filter, &pad_idx, "transpose", "cclock"); + } else if (fabs(theta) > 1.0) { + char rotate_buf[64]; + snprintf(rotate_buf, sizeof(rotate_buf), "%f*PI/180", theta); + ret = insert_filter(&last_filter, &pad_idx, "rotate", rotate_buf); } + if (ret < 0) + return ret; } if (ist->framerate.num) {