From patchwork Sun May 5 02:13:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 12990 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 9F5C1446B4E for ; Sun, 5 May 2019 05:13:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81E4668AAAD; Sun, 5 May 2019 05:13:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB2C668AAAD for ; Sun, 5 May 2019 05:13:45 +0300 (EEST) Received: by mail-pl1-f179.google.com with SMTP id n8so4584463plp.10 for ; Sat, 04 May 2019 19:13:45 -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=Y7nBSpNlH2sZqW4/cMkcC4V52+gww0p11BgB2p9DB38=; b=WDzCIEsBEAmWjMZ29CvZ27jMKo5Kvnt5WITt+FZkJo+s7+r5syR60hZJPwRPBJMG8N C+Z2jTe2tSVY+yDZj/f86c8j5lqcEAkIBx1U5uCsk7or0RBANcInAnUQxDD8avKB72TM jZf6O7kTzffc7CX/QSY1GjKNnycGCVNbwO9mD1tQh4tcevZ9v3c70BikJsDWqaWU7vjr wU0Ub4h8Ztp0SLCUdXiluObxdm1HT9fg5AyxrH4CM6lOxO6xKYYpN+sBFITiTMKSug2C yR6q8e5fjl19WhGtKUzvuTkV/brICVUmE+Y25jif4f6j7kEBsvEt2T4X0IkRR8Hh8zUB zOQQ== 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=Y7nBSpNlH2sZqW4/cMkcC4V52+gww0p11BgB2p9DB38=; b=Zhb1/YdRtmvu7GGbTOb1JO04cvQyx0Eo7phJD77vLKtWCNBtu/1O/Hi11opnred+xM PO2X4UZ7y7AWmSpKHXHRWPVNR7rxWEWxjNf30ngKssX6iGPlyVKatQZGwoGInCDkcAuV jqGbBF61ayiThxyIpNrPR6v5j/3jnZIAOJ0kLAO+aRBiJpzgUQkS+PoRdj895mzFU3WN KF7woyetEniGK5xg/SeWgofZql6HaKu0D/DgmMX+Dc+knbqbed8vznedtXxNlg3OWgpw bTFnTonEN1tmTojBZ6uunQijrZrPQ0Vkc4mtVaOsjLqoylHBsd/SkB8rSDfUf8LIirr0 NDMw== X-Gm-Message-State: APjAAAXxWzUMVYJ3Zo2IKbAZ3YUzVkJbH3JGG5EXGKiyBJRbPWHTMKOt yKsE/9bMTW5ddtzZqoWcufq2AVEu X-Google-Smtp-Source: APXvYqxwC0FZC7bDOO4BXXsYMk/eI8ucHlgxkqJTW3y+JmgI1NE6quBzmFPgKbqobiS+EZaUWRGcCQ== X-Received: by 2002:a17:902:8f84:: with SMTP id z4mr21304501plo.124.1557022423516; Sat, 04 May 2019 19:13:43 -0700 (PDT) Received: from jun-ubuntu.corp.microsoft.com ([2001:4898:80e8:7:5811:1b50:3dbb:d20c]) by smtp.googlemail.com with ESMTPSA id b77sm14151982pfj.99.2019.05.04.19.13.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 May 2019 19:13:42 -0700 (PDT) From: Jun Li To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 May 2019 19:13:34 -0700 Message-Id: <20190505021334.465-2-junli1026@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190505021334.465-1-junli1026@gmail.com> References: <20190505021334.465-1-junli1026@gmail.com> Subject: [FFmpeg-devel] [PATCH v1 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 | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 01f04103cf..1b59542e6c 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2341,6 +2341,49 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, return err < 0 ? err : ret; } +static void set_metadata_from_1stframe(AVStream* stream, 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(stream, AV_PKT_DATA_DISPLAYMATRIX, + sizeof(int32_t) * 9); + switch (orientation) + { + 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: + break; + } + } +} + static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *duration_pts, int eof, int *decode_failed) { @@ -2423,6 +2466,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->st, decoded_frame); if (ist->hwaccel_retrieve_data && decoded_frame->format == ist->hwaccel_pix_fmt) { err = ist->hwaccel_retrieve_data(ist->dec_ctx, decoded_frame);