From patchwork Sat May 25 00:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 13282 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1F08A449366 for ; Sat, 25 May 2019 03:11:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF402689D32; Sat, 25 May 2019 03:11:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 538256802CF for ; Sat, 25 May 2019 03:11:00 +0300 (EEST) Received: by mail-pl1-f194.google.com with SMTP id g21so4786157plq.0 for ; Fri, 24 May 2019 17:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=DTaH83ibvYchRxtj7PUeNZIfhj0Pif8e/AwYhDkV5OI=; b=A8q/Fk7OEihtCKZjsSPHMm5pYSYuKufcw97zF+PmV3u03O/hRa/ftnkE8XCdyM4yiE 8HQmTgQVGCLq3+zBEnuQAu0L6wyI9s782Q0UrywEaWXNDA9A5H42cjKvhVtHPf+413WW P2UoQxXVSKRhfSLCgsuvnS3kZ+oOtzTp4Xo6a4c8YdyoLaf1ROU9AO5zlHM45FIYIvPB cl6YwtK+XHAPZPL6KRTIs5n50M4QvK14PeRA75vHf1sxYH9yBrXdHA1lNLPSFPDQA37h QuMQikkoBv3GqvgPQXTYoN7EWVjQvMogENbLt6luXV2t8ftWawwk4zWgy1CiFsj1gbfz Iq+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=DTaH83ibvYchRxtj7PUeNZIfhj0Pif8e/AwYhDkV5OI=; b=OND0uNx/WlmJl8hCLq+N4ZmbJudlYU3qI6Zpwqk1odagwP35iNt9atdWTkSNkM30n+ hg4U5xMBc79lYmBfhSs+zRKnKtOJqKedZUCyXFjawjj5T017qYfaLEeknuaLpQC3hr6r cJzwzvj/dPucYllIUBs/zqhIFyq29irV8vNd5npDPC9vdkjPgTu8IMg39G/U6j+UWKO0 gHziGxpu8l/Jbxs50xYZAfRVNsmGcMZoIqeWhfXcgYh3f//dKbRye0DDYCBtu77K++9n 3vOyeJCmkK2V3PyYKtowrcaGQyGRA3nx4XKbEAypUtd5NMaodJDg7ksbCl/xhGCarI2r 4+/w== X-Gm-Message-State: APjAAAW2+i8v7o3ldLEzeLCTFSdia+9UUsdl2iFEZKP3riXgd/zuFXKv n0KU7MImBMyfeECylFSQY0+lQwzA X-Google-Smtp-Source: APXvYqxWOLA5OQLY79rbN48hUGsrXz+M1BDNHeGAZKmeWCy5ZfAGjgacM+ZI2i6toL3YYWXVlZSrWg== X-Received: by 2002:a17:902:fa2:: with SMTP id 31mr111924680plz.128.1558742680191; Fri, 24 May 2019 17:04:40 -0700 (PDT) Received: from jun-ubuntu.corp.microsoft.com ([2001:4898:80e8:9:311a:6c69:a9e0:a9ae]) by smtp.googlemail.com with ESMTPSA id h62sm3404738pgc.77.2019.05.24.17.04.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 17:04:39 -0700 (PDT) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 May 2019 17:04:27 -0700 Message-Id: <20190525000427.25546-2-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190525000427.25546-1-junli1026@gmail.com> References: <20190525000427.25546-1-junli1026@gmail.com> Subject: [FFmpeg-devel] [PATCH v1 2/2] fftools/ffmpeg: add exif orientation support per frame's metadata X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fix #6945 Rotate or/and flip frame according to frame's metadata orientation --- fftools/ffmpeg.c | 3 ++- fftools/ffmpeg.h | 3 ++- fftools/ffmpeg_filter.c | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 01f04103cf..da4c19c782 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2142,7 +2142,8 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame) break; case AVMEDIA_TYPE_VIDEO: need_reinit |= ifilter->width != frame->width || - ifilter->height != frame->height; + ifilter->height != frame->height || + ifilter->orientation != get_frame_orientation(frame); break; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..54532ef0eb 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -244,7 +244,7 @@ typedef struct InputFilter { // parameters configured for this input int format; - int width, height; + int width, height, orientation; AVRational sample_aspect_ratio; int sample_rate; @@ -649,6 +649,7 @@ int init_complex_filtergraph(FilterGraph *fg); void sub2video_update(InputStream *ist, AVSubtitle *sub); int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame); +int get_frame_orientation(const AVFrame* frame); int ffmpeg_parse_options(int argc, char **argv); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 72838de1e2..b230dafdc9 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -743,6 +743,18 @@ static int sub2video_prepare(InputStream *ist, InputFilter *ifilter) return 0; } +int get_frame_orientation(const AVFrame *frame) +{ + AVDictionaryEntry *entry = NULL; + int orientation = 1; // orientation indicates 'Normal' + + // read exif orientation data + entry = av_dict_get(frame->metadata, "Orientation", NULL, 0); + if (entry) + orientation = atoi(entry->value); + return orientation > 8 ? 1 : orientation; +} + static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in) { @@ -809,7 +821,11 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, if (ist->autorotate) { double theta = get_rotation(ist->st); - if (fabs(theta - 90) < 1.0) { + if (fabs(theta) < 1.0) { // no rotation info in stream meta + char transpose_args[32]; + snprintf(transpose_args, sizeof(transpose_args), "orientation=%i", ifilter->orientation); + ret = insert_filter(&last_filter, &pad_idx, "transpose", transpose_args); + } else 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); @@ -1191,6 +1207,7 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame) ifilter->width = frame->width; ifilter->height = frame->height; ifilter->sample_aspect_ratio = frame->sample_aspect_ratio; + ifilter->orientation = get_frame_orientation(frame); ifilter->sample_rate = frame->sample_rate; ifilter->channels = frame->channels;