From patchwork Wed Jun 23 16:12:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 28607 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2042:0:0:0:0 with SMTP id z2csp4381090iod; Wed, 23 Jun 2021 14:18:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTrqYq30u0/u9IzLsUsMSR/PRMSPZnadAO8b+C0hdI/R7VDYbxvB4fDxfpm0yqUcb4IAT2 X-Received: by 2002:a17:906:f847:: with SMTP id ks7mr1981102ejb.338.1624483135418; Wed, 23 Jun 2021 14:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624483135; cv=none; d=google.com; s=arc-20160816; b=j4YlRxrvZ4crTDrQ0C7217R8xYGC1YIxx3/PgiAbhRWBFICdiRpEE23vFzb566/6SJ VB0MSgKW1esNe7CVPFX8SGwwObzZ3ziwTa6+ONCV5QYHry7mRdrsU2/GFv8Ayz8X0soi M5xoFJ82t77zh826lzR+BWzjgLQD9AND9n9Dl3Tu6yrR+fNGPqfPBBE6ZEC8H6TcEeBe U3NL/V9VOmbWvu3/uxykGgDFypEJbGR7Sd87uq5MIdPUXuWVxtsEvq6j2OEAFa3fzirg 4pf6meSFn/uRmAa7xv4s64dpj2HDXmXhL6YL5wIwEoI9Uefk0mA5U0mt5ZNEoAIq5Fo8 ReOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=bZ0CCUAyXQzfcEXkrj1w4riXyD1B3PcT8DW2KPUSxtI=; b=ROZryBG5R9AWTR8XULaBWdQDQ+t7FIVu8ODi2n+qzjAi9DgZr4X4w7FWljlmm2iSpb /L45oJyJWYFgh9Qt7l0f1pV8ls3ZuO/dcRZ1+F0yNbFxe4ciXMH3MN1sMtTcpGgetXnB YDDq+NMTz1/++3YNdNlbE1c9g22p+xGjmYxUQCm36AVmu/KHnvLXRI+r31klm1QUIf48 gDl7o1VePhAvJjRVSALZlJpWf6/pkyGh7FeTXd9NmPdd0RG49UuE28NEGnDfhtWjCOJ9 XMlJelZAq6wvXnxj1e0zC/qgh2LqwjMR4ZeD1X+st4mfF6oRymCY9R8WGfAO8GUUT/e9 I2LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=PmEQmLFS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y6si889868edo.399.2021.06.23.14.18.55; Wed, 23 Jun 2021 14:18:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=PmEQmLFS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5FC34689901; Thu, 24 Jun 2021 00:18:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C8E19680A9A for ; Thu, 24 Jun 2021 00:18:45 +0300 (EEST) Received: by mail-wm1-f48.google.com with SMTP id w13so2541838wmc.3 for ; Wed, 23 Jun 2021 14:18: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:mime-version :content-transfer-encoding; bh=TUWO04OKz/saL4d/K50PNS8kcNaTZfU38Gy7rfeJZU0=; b=PmEQmLFSf7lmeMcxxOSOH/Ietz3U8t6hjw8yS9u9kM/dT+M50e59FNXcThJ+DLdHol xdz08z7nBefQuVS1Ej0xLSFLGYiCuDRPoeZQHDyK6Q8PZKHgHYFz02jyO25Rv78BGTdR 3Hn3DCCj59qYzJfSX+5QBeJtcFkXEO8J2XT25glyJO2K2ehBvzHUfQdf/j+RnqVh/euJ VA0Qbq7+8gnWLP0iao/6i3Wrij+3XcTdeVE3xg8GXqvVx9crioyq7QiOF+QbbEUem1Sz MfeMfc/JVprPXGHUr/bpDRYfH7VxvnGT6BffBvhK6eG3KblUutfvrDcZ4jg0k2GeYhZc ewTQ== 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:mime-version :content-transfer-encoding; bh=TUWO04OKz/saL4d/K50PNS8kcNaTZfU38Gy7rfeJZU0=; b=AfSBJpfFdOFtrbmv9wnvITt5HSHcJLDJjPNEQb8R363UW9uDkdyu5HMfTFzna6XP39 0kh1rzDjIhWJ9sL7pedizQpbh+MvO/FkJUrvi7WW6ow4Fq42hXkouW6JbPOXCXBHN8iN APpVNYk98dkaPA/CXWelxMKfQAgaDt7qVtHZC0aJZb8BzMor0wAH4p+dRh3znIm0qi5F YwbqPQ1Z4i2VZsHEYRxcAjTGtDNaGR7JmHH0szXA5/IxsHMXSfJtjW24ImdIxZuOXLWO staQ2ivgTAveuYb57x0H7xZTYO3NOvE661afaYVDkV+NTmECWYI5+aQmCe2gBuyd0+6H m8PQ== X-Gm-Message-State: AOAM530DEc4GKeGi2tLC8q5qtXNfjqxMzUUE6sOBmegHjNjhAxNvTtz5 BHGeUqU+jJrg3Ty9KX1SDfnfeLzVAJA= X-Received: by 2002:a1c:a5ce:: with SMTP id o197mr11923410wme.84.1624464779502; Wed, 23 Jun 2021 09:12:59 -0700 (PDT) Received: from localhost.localdomain ([82.129.108.228]) by smtp.gmail.com with ESMTPSA id p5sm521270wrd.25.2021.06.23.09.12.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 09:12:59 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Jun 2021 17:12:43 +0100 Message-Id: <20210623161243.488097-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/h264_metadata_bsf: Allow zeroing constraint_set4_flag and constraint_set5_flag X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: EKpA9UXXqBec These bits are reserved in earlie versions of the H.264 spec, and some poor hardware decoders require they are zero. Thus, it is useful to be able to zero these on streams that may have them set. The result is still a valid H.264 bitstream. Signed-off-by: Derek Buitenhuis --- e.g. x264 wrote these bits for several months before reverting that functionality, since it broke several hardware decoders. --- doc/bitstream_filters.texi | 5 +++++ libavcodec/h264_metadata_bsf.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 60e729484d..81220638d4 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -253,6 +253,11 @@ Set whether the stream has fixed framerate - typically this indicates that the framerate is exactly half the tick rate, but the exact meaning is dependent on interlacing and the picture structure (see H.264 section E.2.1 and table E-6). +@item zero_new_constraint_set_flags +Zero constraint_set4_flag and constraint_set5_flag in the SPS. These +bits were reserved in a previous version of the H.264 spec, and thus +some hardware encoders require these to be zero. The result of zeroing +this is still a valid bitstream. @item crop_left @item crop_right diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index ef74cba560..452a8ec5dc 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -61,6 +61,7 @@ typedef struct H264MetadataContext { AVRational tick_rate; int fixed_frame_rate_flag; + int zero_new_constraint_set_flags; int crop_left; int crop_right; @@ -228,6 +229,10 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, need_vui = 1; } SET_VUI_FIELD(fixed_frame_rate_flag); + if (ctx->zero_new_constraint_set_flags) { + sps->constraint_set4_flag = 0; + sps->constraint_set5_flag = 0; + } if (sps->separate_colour_plane_flag || sps->chroma_format_idc == 0) { crop_unit_x = 1; @@ -618,6 +623,9 @@ static const AVOption h264_metadata_options[] = { { "fixed_frame_rate_flag", "Set VUI fixed frame rate flag", OFFSET(fixed_frame_rate_flag), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, FLAGS }, + { "zero_new_constraint_set_flags", "Set constraint_set4_flag / constraint_set5_flag to zero", + OFFSET(zero_new_constraint_set_flags), AV_OPT_TYPE_BOOL, + { .i64 = 0 }, 0, 1, FLAGS }, { "crop_left", "Set left border crop offset", OFFSET(crop_left), AV_OPT_TYPE_INT,