From patchwork Mon May 6 03:41:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 13000 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 0FF184499A1 for ; Mon, 6 May 2019 06:41:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F403268ACAD; Mon, 6 May 2019 06:41:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07F4668A8A0 for ; Mon, 6 May 2019 06:41:40 +0300 (EEST) Received: by mail-pg1-f173.google.com with SMTP id z16so5758385pgv.11 for ; Sun, 05 May 2019 20:41:39 -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=pakjCLU6IzIiSBSPyEk6Loe2AuBTxCTvwwkmpoSjbnA=; b=fz2Vqo5veb5MXIi1gimMXLn3S3RNaxRfY7W8SIFyixdGt9bXQ+jBf0JMqtVnKEVO/Z JszVB6pXS6bVl9np30YKDEKtA2Mqq3tRnl8tgsUQ5Z7esNvgGGW7rudVSl7TpffQjzJ9 2WSoIGp5ilJkqiyTRUUYind8/gumFxOUSJMHutJ4QUc+JbjVgPAd086atp/+1vKCheJK xMnHK26wFfySKdTw6GBhvsUXDIMeKk+FkSrj44xTdVD4iXD/6BfBK809LYIAo4DLVkbd Bjg0/W2a5Ztny1g49SkmAJguWzUaHB2SoFa//vKOAm3fUSWxAEHygpP85jj0Sq9DMGEY Ea0A== 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=pakjCLU6IzIiSBSPyEk6Loe2AuBTxCTvwwkmpoSjbnA=; b=LnJmGABWfSfiRzr233pIUE1shqx//F0jpBWmXtH8427lZdzsJbu+c1sdyCp0LMn06j xDsQCQwnDqjABw5tLLHNi5PiYm7GYMdFv+hL56zRMB2/qATG8pMruSMnR39My+cqEyjb XcWbuV1MC3q3inxw5mRng3X98gEGS3mT+uNMnOaDKsSegntqgRuoORi9oPTPAaYmf/nN TviMBJ9yTkqgU2si8D0Yex9g0sJvU90f7SlS4XC2Z6nDqXMC35fZ9MQnRHBEb0lSPkZF XZm2sVcajZrqkhJn0oRP6vFNANxQvfqGaCuQxCKlmRJKxg1d2+JSvKFqjazNHMbqZFKZ pOEA== X-Gm-Message-State: APjAAAV7k9Mu2vkGH5Ot3h8AsPJaCgxGOv4k4ZpXumaWPC00c6kh5JO4 ZS1JBnNTllTS22P/qaGe39JuynrG X-Google-Smtp-Source: APXvYqyNBKcAr33Q7VfRd0hd65P3OEBcT2f2sx78zfoDdHhocfHUNnN9j0xRIQFnJZaGMIBSaMNY7g== X-Received: by 2002:a63:1604:: with SMTP id w4mr29763076pgl.148.1557114098117; Sun, 05 May 2019 20:41:38 -0700 (PDT) Received: from super.lan (c-73-193-9-32.hsd1.wa.comcast.net. [73.193.9.32]) by smtp.gmail.com with ESMTPSA id h20sm18266441pfj.40.2019.05.05.20.41.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 May 2019 20:41:37 -0700 (PDT) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Sun, 5 May 2019 20:41:28 -0700 Message-Id: <20190506034128.22929-2-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506034128.22929-1-junli1026@gmail.com> References: <20190506034128.22929-1-junli1026@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 2/2] fftools/ffmpeg: Add stream metadata from first 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 Exif extension has 'Orientaion' field for image flip and rotation. This change is to add the first frame's exif into stream so that autorotation would use the info to adjust the frames. --- fftools/ffmpeg.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 01f04103cf..cea85c601e 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2341,6 +2341,56 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, return err < 0 ? err : ret; } +static void set_metadata_from_1stframe(InputStream* ist, AVFrame* frame) +{ + // read exif Orientation data + AVDictionaryEntry *entry = av_dict_get(frame->metadata, "Orientation", NULL, 0); + int orientation = 0; + uint8_t* sd = NULL; + if (entry) { + orientation = atoi(entry->value); + sd = av_stream_new_side_data(ist->st, AV_PKT_DATA_DISPLAYMATRIX, + sizeof(int32_t) * 9); + memset(sd, 0, sizeof(int32_t) * 9); + switch (orientation) + { + case 1: // horizontal (normal) + av_display_rotation_set((int32_t*)sd, 0.0); + break; + case 2: // mirror horizontal + av_display_rotation_set((int32_t*)sd, 0.0); + av_display_matrix_flip(sd, 1, 0); + break; + case 3: // rotate 180 + av_display_rotation_set((int32_t*)sd, 180.0); + break; + case 4: // mirror vertical + av_display_rotation_set((int32_t*)sd, 0.0); + av_display_matrix_flip(sd, 0, 1); + break; + case 5: // mirror horizontal and rotate 270 CW + av_display_rotation_set((int32_t*)sd, 270.0); + av_display_matrix_flip(sd, 0, 1); + break; + case 6: // rotate 90 CW + av_display_rotation_set((int32_t*)sd, 90.0); + break; + case 7: // mirror horizontal and rotate 90 CW + av_display_rotation_set((int32_t*)sd, 90.0); + av_display_matrix_flip(sd, 0, 1); + break; + case 8: // rotate 270 CW + av_display_rotation_set((int32_t*)sd, 270.0); + break; + default: + av_display_rotation_set((int32_t*)sd, 0.0); + av_log(ist->dec_ctx, AV_LOG_WARNING, + "Exif orientation data out of range: %i. Set to default value: horizontal(normal).", orientation); + break; + } + } +} + static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *duration_pts, int eof, int *decode_failed) { @@ -2423,6 +2473,8 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_ decoded_frame->top_field_first = ist->top_field_first; ist->frames_decoded++; + if (ist->frames_decoded == 1) + set_metadata_from_1stframe(ist, decoded_frame); if (ist->hwaccel_retrieve_data && decoded_frame->format == ist->hwaccel_pix_fmt) { err = ist->hwaccel_retrieve_data(ist->dec_ctx, decoded_frame);