From patchwork Thu Nov 1 13:24:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valery Kot X-Patchwork-Id: 10878 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 21D1444D4C0 for ; Thu, 1 Nov 2018 15:24:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B4FF68A892; Thu, 1 Nov 2018 15:23:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E0CA268A82B for ; Thu, 1 Nov 2018 15:23:41 +0200 (EET) Received: by mail-ot1-f44.google.com with SMTP id f24so11967600otl.5 for ; Thu, 01 Nov 2018 06:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=ZYe4ddEcezfRu6tg6lNg0XmZCfeUr38nFnIFFuCV0bo=; b=DRVvrNr0+ivNQEZf+nEJhjKPtZZKfKIZ8CyKcDmiOoe/iV1Lq3QtvOvg9l8DpKMiYQ Ozp8UNtX51OLelxOc+iGMRsTx3TBBvFA2ROP1+phdQ+iZvp9Ymxrz64L7jvDdtmMX1jD +csh3RybsNwKYi5J+r5d2omSqfL/3MhP8Fyh5AKpTqLpDihUAy5EbkqE8QpziLwDipdT 5EFiuhXWP3LuRchAPV8MyHSh5fPhzUJMx/Ra7XTRmGYqk4ZbyVVyBs1PBbUAa1sHI/t3 asWUFn4xZ5tN0pmmM5iC1VDUfb+63bVluAUPwsJJe8aRVPi1+BXRr1tK17pUMmP59iew 1uag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=ZYe4ddEcezfRu6tg6lNg0XmZCfeUr38nFnIFFuCV0bo=; b=YCyE3xgcHHFPLRYgnOJOIh1CTh3IZ4ced6K6ZYQbN0GEe09ntMQAB+RwPojxvli+pJ g/kl1542n7i/PJsboPbDF0D6HIHOK5sVKohW6kX1jXBsInRSYrVg+1XS+Ce0qiiQS27b 6OU3D66sEpBwJTlB+6xC4ZH61++lNlAG4ntZ1WItrWwUcCMjCFrycrD6cyLIdYeTkNQy tbJKtmDBzjDCI1SmqPe+oq0fP4ESuc4p/YyMgo/9u4nIQ+Mpdni7yQgO/8njbhr3e8Kc 5japRsgPbp1g2XD1flsPOKr+vXVA2xM49tdGNiT3xj5SdgQ4ie1ioC8klxlCK02JJtiL oC1Q== X-Gm-Message-State: AGRZ1gIpgY//SS17lpUhsBFyNB7U2yy3EMdwc7MfXD0x/qHNFn+stwWY ulsVVraiduy2se5nnuJ94PWvGxl5KmijO+cGIMB+ow== X-Google-Smtp-Source: AJdET5dLTkvr6J1CbM+Dr3HnRVvJXFV3c0wYnhwhSOk+XnIxqhJjHdxO/V+vO4H1x/bxJjD6ucm0aLR/LLUn/eLPyoo= X-Received: by 2002:a9d:2087:: with SMTP id x7mr4740022ota.10.1541078652342; Thu, 01 Nov 2018 06:24:12 -0700 (PDT) MIME-Version: 1.0 References: <972a8331-53c1-71ea-3389-ef51b5bdf177@jkqxz.net> In-Reply-To: From: Valery Kot Date: Thu, 1 Nov 2018 14:24:00 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH v2] avcodec/libopenh264enc.c: Handle sample_aspect_ratio in libopenh264 encoder 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Thu, Nov 1, 2018 at 1:55 PM Valery Kot wrote: > > > I think this would look nicer (and generate less code) as a table + loop rather than an if-ladder making each fraction structure inline? > > > > E.g. something like . > > Thanks for the suggestion! Here is an updated patch. Was too hurry to send a patch, sorry! Here is the correct one. From 638277354338bf42020854e5bebec5fe61677135 Mon Sep 17 00:00:00 2001 From: vkot Date: Thu, 1 Nov 2018 14:15:11 +0100 Subject: [PATCH] Handle sample_aspect_ratio in libopenh264-encoder --- libavcodec/libopenh264enc.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c index 83c3f0ce20..b3ddb4609b 100644 --- a/libavcodec/libopenh264enc.c +++ b/libavcodec/libopenh264enc.c @@ -164,6 +164,47 @@ FF_ENABLE_DEPRECATION_WARNINGS param.sSpatialLayers[0].iSpatialBitrate = param.iTargetBitrate; param.sSpatialLayers[0].iMaxSpatialBitrate = param.iMaxBitrate; +#if OPENH264_VER_AT_LEAST(1, 7) + if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den) { + // Table E-1. + static const AVRational sar_idc[] = { + { 0, 0 }, // Unspecified (never written here). + { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 }, + { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 }, + { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 }, + { 160, 99 }, // Last 3 are unknown to openh264: { 4, 3 }, { 3, 2 }, { 2, 1 }, + }; + static const ESampleAspectRatio asp_idc[] = { + ASP_UNSPECIFIED, + ASP_1x1, ASP_12x11, ASP_10x11, ASP_16x11, + ASP_40x33, ASP_24x11, ASP_20x11, ASP_32x11, + ASP_80x33, ASP_18x11, ASP_15x11, ASP_64x33, + ASP_160x99, + }; + int num, den, i; + + av_reduce(&num, &den, avctx->sample_aspect_ratio.num, + avctx->sample_aspect_ratio.den, 65535); + + for (i = 1; i < FF_ARRAY_ELEMS(sar_idc); i++) { + if (num == sar_idc[i].num && + den == sar_idc[i].den) + break; + } + if (i == FF_ARRAY_ELEMS(sar_idc)) { + param.sSpatialLayers[0].eAspectRatio = ASP_EXT_SAR; + param.sSpatialLayers[0].sAspectRatioExtWidth = num; + param.sSpatialLayers[0].sAspectRatioExtHeight = den; + } else { + param.sSpatialLayers[0].eAspectRatio = asp_idc[i]; + } + param.sSpatialLayers[0].bAspectRatioPresent = true; + } + else { + param.sSpatialLayers[0].bAspectRatioPresent = false; + } +#endif + if ((avctx->slices > 1) && (s->max_nal_size)) { av_log(avctx, AV_LOG_ERROR, "Invalid combination -slices %d and -max_nal_size %d.\n",