From patchwork Thu Jan 26 19:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Coiner X-Patchwork-Id: 40129 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp764957pzj; Thu, 26 Jan 2023 11:16:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXtijbfwy0fbFlxW9gkV8B/a2y+jot2yDvR8LNqBLlXdE/I0ECV7r4WXHYCRk/rV3an2eX03 X-Received: by 2002:a17:906:1be1:b0:7c1:5248:4f3a with SMTP id t1-20020a1709061be100b007c152484f3amr35496779ejg.56.1674760600480; Thu, 26 Jan 2023 11:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674760600; cv=none; d=google.com; s=arc-20160816; b=xgikLYQb+OoTDylWZandaW7Gqb1iqhGzzERgkyVCLJVa0X7zTMHCuGwH5PF5Docj0U BONnZDqxEAcbR6OuIE27+ix37UZN8V6VDBDMLmo0XkJFt4GZD9uGWsMwcGoKPy3RnbfS xgX/59zvayIfEUgURqWO4C+BhR1PMK4qzi7DSvk3kx8RdRhJ0fIHH3R6hPNTKO6UFtKj kfiyvwAcoE+5udTqH/d4GHuksJFt7NEm2HxOD8ZxVKvIEqkV63nbQxOJvTC8ZUy+hnA8 OdzKk0T6OiO1le/rANAR/+hICNNeyhwhbI3/4sqld3rrkh/pLAc41rCyh+TnKIWR8Bht eUqQ== 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:to:message-id:date:from:mime-version :dkim-signature:delivered-to; bh=9xFVl9fT4pEwMqvea6ZFkLR6z/7U/aTMOg8rENpK7pI=; b=I3z18KszpQdJYqXFTSrMfi0tXo3MoW5dClvZ3Fdjo/8gu0yiE9UvdtBZAEj5iZBAsj fV/xoLHyVRKJQenJc0j+oUAH8YoZbqCxC3OzAU23K5Fl5ipFrcJlY1KZLGOLb4eWdUzi uzRxsym2slqCh0TkXOFTeqR+WymSgAITbLCGOJvrRbvZWPcyM09f8vb+i6r9NbUxpBxC N61/e4Y/DgFf0N4DvuBqYoFdqyoPKhsiAGSQYWuLPmyXwMZR/v2M91S4OplLlICZG18l rXUTm3ro+Vph2SjwlUi28ohiC0MJobRLW27gdZyglxp0TNK2FDl8RfnE+ZM0CHpdmT/A fgrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=A4CQmm2N; 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 fx34-20020a1709069ea200b008787aa103e3si1223839ejc.90.2023.01.26.11.16.38; Thu, 26 Jan 2023 11:16:40 -0800 (PST) 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=20210112 header.b=A4CQmm2N; 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 42E9368BC7B; Thu, 26 Jan 2023 21:16:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EDB7E68AD83 for ; Thu, 26 Jan 2023 21:16:28 +0200 (EET) Received: by mail-pl1-f174.google.com with SMTP id z13so2745988plg.6 for ; Thu, 26 Jan 2023 11:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=xqPMOieaeoYKhffmeG1UAyGSCWrQyLHtquLkxleNHm0=; b=A4CQmm2NYu3LTW0XR7qgw3hZqmc1R5b1lZB1/w3IBd6/aRxLEnCeEYVEAYCLmA3zoP J7AtizaVZWEBZ/k2ilvxu1tdpAx7bbA3980u5SqSdRNxJtW6DY+qEuZayo0QrX8bspxJ zqBws7bhU0IhvZEEeMl4rf+19F/Fx4mJILb+XryhSt2W85wa9pcCLX2a1IobMGiIHWVW UlWPPOzfgNkQjf+hUhrxndoDRjd7DSCkwsAHYv4Ie55qPOmsThwWXwS+0mzhz/T39UAm sL6tdCQHCS56lcr/suSwPE/lMV9VzBumM/rfSTrFPlxLZJpWjsGK11o/sF2Sm2T/OH8u n37Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xqPMOieaeoYKhffmeG1UAyGSCWrQyLHtquLkxleNHm0=; b=NMiqdZj2Xnl3kTsB8e91apbwwXe9ant5Xb1H7cnVY+0GW1QSopb3CVWjzfQODoMiCF p9HQ0cPGnVhCIqlASAK+C8CLTrzj2tkhHvT9aa3jnlTe2DHaIkrQESrO2egfVe2tSwEc y6GrD/sSwlDA5roydpgvg0bqVinQCcQSq8POhvW8xXMRVJHwFtW/XVqQnLkzka7xWBF7 QnV0GLhnpaoenC7bZOE+2fk0Ehl/Y3kI7cBfv06RLYJv1t532W3f2QUMSW/YSPOcOrOs yv9A6dWaY9ReuEu/TtGzJEfjOcwu+Of4uYi8MvMndlpklyGVCeMGKURqRqgUp5efTgbW WhoA== X-Gm-Message-State: AFqh2kp7SVPNnFOenCFcdUdjOX6McOKcF7g3MS/qtqGEepchwPcgEU9m z+wPqUwUr7ViHt5vIm/zWH0Bf8zwghjWhZcV/HhzyBPZEVQ= X-Received: by 2002:a17:90a:2882:b0:22b:b832:4125 with SMTP id f2-20020a17090a288200b0022bb8324125mr3706163pjd.146.1674760586574; Thu, 26 Jan 2023 11:16:26 -0800 (PST) MIME-Version: 1.0 From: John Coiner Date: Thu, 26 Jan 2023 14:16:15 -0500 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures 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: HKeaNLS/MpOT Trying again to upload the same patch, this time inline: From 09c4bbd3d4ef6fbcb1558fce5cff4d15d7839526 Mon Sep 17 00:00:00 2001 From: John Coiner Date: Thu, 26 Jan 2023 13:34:24 -0500 Subject: [PATCH] Proposed fix for https://trac.ffmpeg.org/ticket/10148 --- libavformat/mpegtsenc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) return AVERROR(ENOMEM); diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 48d39e6a7d..6cb398f99c 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -1886,17 +1886,21 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) if (extradd && AV_RB24(st->codecpar->extradata) > 1) extradd = 0; - do { + while (p < buf_end + && extradd > 0 + && (state & 0x1f) != 5 // IDR picture + && (state & 0x1f) != 1 // non-IDR picture + ) { p = avpriv_find_start_code(p, buf_end, &state); av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f); - if ((state & 0x1f) == 7) + if ((state & 0x1f) == 7) // SPS NAL extradd = 0; - } while (p < buf_end && (state & 0x1f) != 9 && - (state & 0x1f) != 5 && (state & 0x1f) != 1); - - if ((state & 0x1f) != 5) + } + if ((state & 0x1f) != 5) { + // Not an IDR picture extradd = 0; - if ((state & 0x1f) != 9) { // AUD NAL + } + if (extradd > 0) { data = av_malloc(pkt->size + 6 + extradd); if (!data)