From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 7C5DD4CE53 for ; Thu, 13 Feb 2025 00:09:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C02CE68C0DD; Thu, 13 Feb 2025 02:09:19 +0200 (EET) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6520568B5E7 for ; Thu, 13 Feb 2025 02:09:13 +0200 (EET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21f49bd087cso3737265ad.0 for ; Wed, 12 Feb 2025 16:09:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739405351; x=1740010151; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Aao/OeFA5bY2ncitrfw+1pHr+e8zXu6iXP7/Ov5Q27M=; b=fwnnfL1D9FzQJCtWt/VtPtwl6Y5E8nqUrE0aVV8dncOJhP+ltFCPXCrhEdl/+sBO+U Ms+3WPtCCpFnDIPpEdVfeYdKI3C6OSA/RNFaP4ZqoA+le/y0Gn8rCSzkkGUhYTiyx1ei GHbDiAH9gEUFdDkqUuI7ALOUp2GApP9BQYMVQLYaHS5heFd1x7gMuIxCbd1/nrLdC3o2 26onRVw3kZyDkxJP7c2VKg3lZqj7rhSsidDpjm3JbRguOD6phboahlIjt1T9VJB0Xv4h 2wKrg78xBvwvs8wwf/Qolbc7sx9PDya0n7R7zsp2e7eC+aY0vu4WX38b476kErkix4v5 iyoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739405351; x=1740010151; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Aao/OeFA5bY2ncitrfw+1pHr+e8zXu6iXP7/Ov5Q27M=; b=HIZhjhja7yeHwYX7gSEWahaXPWzzTN4o9SvZKbfPKy+Lc/cBSDAaeWR+blUVYj39mp KbJhs/tQiNDelGBblAIMKR37If9OkCd/twIB6Y+DhuN6llO/sC/yg+7jOEP2zfgRg8ri SUEAf34xRP2gA4JIBzJyNBhf6B2fmBBW9DKayqohZxaIIVMYrDkugRaARlRsXG2MTqUl pzNgFavEQGp2QDaQJCPkJzlSFF5ikqyvAIY7mjoN4CczeFJvHpA6OEuaT77yoMxKPmFo 7ZLprrvByV+efwS9jS0GXKgqqug27Ah97A7Eim1jsbSX5gkRwEHV+aps3QyrQKy+2QOa ET6w== X-Gm-Message-State: AOJu0Yy/uGj7ivDc/R62RTCN8slA1b6Qz1amT167ew1F5YHvZJK+ktuf 6CdVnk3LZMVMeZ8w+Kbr5ffwCpkxyORFDrggWgA/AGbJ9SfhXcWsTleSVA== X-Gm-Gg: ASbGnct92QDtcAtuYiPTA9fxOFSj6P0chEMqcRYQiJovLwvxjcQnP0tnmdf2DaptUSt //839tYqGQ7X/yaxoFQ8eXZaymGdwOuCqtP47O6XTMg1uFDSBXRMLYUF7ywGLkg7zqDoLOAd3Tq qJ7Nm/sArF7KyaTiyBzZPO68es8mNU/vnNyhywhIZRXWeBxb6hEkRiGKowNgqU+EJi+/BbCUdkX agJj+7yQJ32JhqkVts0gy2bS7vVCaUYUu0N1dNCy49lGTauGmJQQgWobfwkV8KQQ/grIzBl+Ztw qopWbKaGlEqVUK67f8WFl4483SjJwA== X-Google-Smtp-Source: AGHT+IGnzkSgEuFM4AuGxD8V+YOpYo7/Klzy8UCU2q1jXJNvlf+HXpfnVUTKMdnhjdINczPLWyGDRw== X-Received: by 2002:a17:902:e84f:b0:21f:4c8b:c514 with SMTP id d9443c01a7336-220d216b869mr15793995ad.45.1739405351173; Wed, 12 Feb 2025 16:09:11 -0800 (PST) Received: from homestead.aragog.com ([2605:a601:a9a2:a100:67c:16ff:fe02:37f0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d5363848sm1253965ad.55.2025.02.12.16.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2025 16:09:10 -0800 (PST) From: Pavel Koshevoy To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Feb 2025 17:09:09 -0700 Message-ID: <20250213000909.21112-1-pkoshevoy@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: Fix get_eia608_packet c608 caption reformatting 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 Cc: Pavel Koshevoy Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavformat/mov.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 85aef33b19..422e515fe8 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -10790,22 +10790,44 @@ static int mov_change_extradata(AVStream *st, AVPacket *pkt) static int get_eia608_packet(AVIOContext *pb, AVPacket *pkt, int size) { - int new_size, ret; - + /* We can't make assumptions about the structure of the payload, + because it may include multiple cdat and cdt2 samples. */ + int ret, out_size = 0; if (size <= 8) return AVERROR_INVALIDDATA; - new_size = ((size - 8) / 2) * 3; - ret = av_new_packet(pkt, new_size); + + /* Allocate 3 times the required buffer size to give us enough space + to store the original c608 packet and (potentially 3/2 times larger) + reformatted data, safely. */ + ret = av_new_packet(pkt, size * 3); if (ret < 0) return ret; - avio_skip(pb, 8); - for (int j = 0; j < new_size; j += 3) { - pkt->data[j] = 0xFC; - pkt->data[j+1] = avio_r8(pb); - pkt->data[j+2] = avio_r8(pb); + /* Load the original c608 payload into the last 3rd of the buffer. */ + if (avio_read(pb, pkt->data + size * 2, size) != size) + return AVERROR_EOF; + + /* parse and re-format the c608 payload in one pass */ + for (uint8_t *out = pkt->data, *src = out + size * 2, *end = src + size; src + 8 <= end; ) { + uint32_t atom_size = AV_RB32(src); + uint8_t cc_field = + memcmp(src + 4, "cdat", 4) == 0 ? 1 : + memcmp(src + 4, "cdt2", 4) == 0 ? 2 : + 0; + + if (cc_field != 0) { + for (uint8_t *cc = src + 8, *cc_end = src + atom_size; cc < cc_end; cc += 2) { + out[0] = (0x1F << 3) | (1 << 2) | (cc_field - 1); + out[1] = cc[0]; + out[2] = cc[1]; + out_size += 3; + out += 3; + } + } + src += atom_size; } + pkt->size = out_size; return 0; } -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".