aboutsummaryrefslogtreecommitdiffstats
path: root/ffmpeg_filter.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-05-02 22:39:00 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-05-02 22:39:00 +0200
commitf5b26fbc2f564831b337f1de9faaaf6753a03871 (patch)
treed6983d185fdc2a2df77795a739493c0569872e2c /ffmpeg_filter.c
parentdeedf3e590027e53cf999b11a25fc9be9615b5f2 (diff)
parent16302246b1fcb7ad4e6f7bd31c49956a455336d2 (diff)
downloadffmpeg-f5b26fbc2f564831b337f1de9faaaf6753a03871.tar.gz
Merge commit '16302246b1fcb7ad4e6f7bd31c49956a455336d2'
* commit '16302246b1fcb7ad4e6f7bd31c49956a455336d2': avconv: Add an option for automatically rotating video according to display matrix Conflicts: Changelog ffmpeg_opt.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'ffmpeg_filter.c')
-rw-r--r--ffmpeg_filter.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c
index 264840b2e9..6a891d3d10 100644
--- a/ffmpeg_filter.c
+++ b/ffmpeg_filter.c
@@ -31,6 +31,7 @@
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
+#include "libavutil/display.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
@@ -339,6 +340,28 @@ static int insert_trim(int64_t start_time, int64_t duration,
return 0;
}
+static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
+ const char *filter_name, const char *args)
+{
+ AVFilterGraph *graph = (*last_filter)->graph;
+ AVFilterContext *ctx;
+ int ret;
+
+ ret = avfilter_graph_create_filter(&ctx,
+ avfilter_get_by_name(filter_name),
+ filter_name, args, NULL, graph);
+ if (ret < 0)
+ return ret;
+
+ ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);
+ if (ret < 0)
+ return ret;
+
+ *last_filter = ctx;
+ *pad_idx = 0;
+ return 0;
+}
+
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
{
char *pix_fmts;
@@ -676,6 +699,26 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
return ret;
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");
+ }
+ if (ret < 0)
+ return ret;
+ }
+ }
+
if (ist->framerate.num) {
AVFilterContext *setpts;