[FFmpeg-cvslog] avplay: Add support for rotated video
Martin Storsjö
git at videolan.org
Sat May 2 22:38:12 CEST 2015
ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Wed Apr 29 22:28:45 2015 +0300| [e2d50fc2f5f3600e13055acf1a10fec35e941f37] | committer: Martin Storsjö
avplay: Add support for rotated video
This is enabled by default, but can be disbled via the -noautorotate
option.
Based on a patch by Clément Bœsch.
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e2d50fc2f5f3600e13055acf1a10fec35e941f37
---
avplay.c | 19 +++++++++++++++++++
configure | 2 +-
doc/avplay.texi | 2 ++
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/avplay.c b/avplay.c
index e353a66..7437bd6 100644
--- a/avplay.c
+++ b/avplay.c
@@ -27,6 +27,7 @@
#include "libavutil/avstring.h"
#include "libavutil/colorspace.h"
+#include "libavutil/display.h"
#include "libavutil/mathematics.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
@@ -265,6 +266,7 @@ static int rdftspeed = 20;
#if CONFIG_AVFILTER
static char *vfilters = NULL;
#endif
+static int autorotate = 1;
/* current context */
static int is_full_screen;
@@ -1548,6 +1550,22 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c
INSERT_FILT("format", "yuv420p");
+ if (autorotate) {
+ uint8_t* displaymatrix = av_stream_get_side_data(is->video_st,
+ AV_PKT_DATA_DISPLAYMATRIX, NULL);
+ 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 (vfilters) {
AVFilterInOut *outputs = avfilter_inout_alloc();
AVFilterInOut *inputs = avfilter_inout_alloc();
@@ -2928,6 +2946,7 @@ static const OptionDef options[] = {
{ "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, { &rdftspeed }, "rdft speed", "msecs" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, { opt_default }, "generic catch all option", "" },
{ "i", 0, { NULL }, "avconv compatibility dummy option", ""},
+ { "autorotate", OPT_BOOL, { &autorotate }, "automatically rotate video", "" },
{ NULL, },
};
diff --git a/configure b/configure
index e2d9642..c5ea29c 100755
--- a/configure
+++ b/configure
@@ -2233,7 +2233,7 @@ avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter format_fi
setpts_filter trim_filter"
avplay_deps="avcodec avformat avresample swscale sdl"
avplay_libs='$sdl_libs'
-avplay_select="rdft"
+avplay_select="rdft transpose_filter hflip_filter vflip_filter"
avprobe_deps="avcodec avformat"
# documentation
diff --git a/doc/avplay.texi b/doc/avplay.texi
index d526213..d143f75 100644
--- a/doc/avplay.texi
+++ b/doc/avplay.texi
@@ -115,6 +115,8 @@ Do not exit after playback is finished.
Exit if any key is pressed.
@item -exitonmousedown
Exit if any mouse button is pressed.
+ at item -noautorotate
+Disable automatically rotating video based on file metadata.
@end table
@section While playing
More information about the ffmpeg-cvslog
mailing list