From patchwork Wed Sep 11 10:56:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51505 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:14c:b0:48e:c0f8:d0de with SMTP id h12csp209760vqi; Wed, 11 Sep 2024 03:06:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWEdGwBJpIhdUjFD0pxUj8VEaGXM8HdNm8D7tZlFndLNxWx9nBcNe263Fk1hoxt7YsbrHAZOlJl2M7tV7oJxmlA@gmail.com X-Google-Smtp-Source: AGHT+IEufguoP0pPURIKiLZKGNPEbJoyeF499pP25L4vX3F3YXEpwGpiJMmwRwEobUZKoeNeGX5m X-Received: by 2002:a05:6402:50cb:b0:5c2:524b:7711 with SMTP id 4fb4d7f45d1cf-5c40bc5d02fmr1885822a12.33.1726049169104; Wed, 11 Sep 2024 03:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726049169; cv=none; d=google.com; s=arc-20240605; b=A4ynhcU7sTJgwppaIq5ZipPv8fe2lbG7QQkoZN7V4OEujQ1A0VZDR1x9925uYS3lbe DrYgXlwUQWaTke5S9ithMiSr3awZ6nNOMzDtzNjqI89pIvEZKQ6TcWJgWSQgp+eKHIiU wb50n4Zw8A++hf//TQtt4HSsy9eGhw6Md7l1rXnE96G32KkPzJ/nGlItbXJOo7LkgD4f kKQs07CYIftb+oVBx8EbO+X6O0LtWxYmdw8mPBhgOBMytFfeRuWpUH3CuQ27RUWggulG lzi7xihtpDmoDmUPdLgHb8Qmy5Gbkbd6DH/A/5w88MV8D4SX0GEne+G/KRY95Jg+m4zY iYSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc: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=VxEqIZAPVegUejbAn1ffCPyHNAGfXgasga0G5RShqio=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=D2oocYIX/SyPDd8oZ0MHsAX2hNpZVl0ma2huUhYsem5m+YENOXo4hYoZhpYaYMw0gX jV3BSp7RJ7VUmaZdx5IJq1/abI1oAtm9pChwSej3Pp+sO74awoF6qvG87LDKrwSeJ6gF FzSFNpdpzZRcif8a64IitjoA/8hwq/1Aznq9/Lg0/nfOdqe7ZCdIkSFNaALjBnOGrzhk MDGznqtQkHAo5IcInn9kKBP2H/a6nF3gCdDD1N4x3pD/hmIRtgywQX6PN+kkkxVoD3K+ X/+BH3qo2AosNJosw+d8E3gO5IcPUVR/RMFR4jSGGyFb/sAuPIuhL9idZd69BXRSYvns hqUA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=RJ3aWqVx; 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=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5c3ebda9a0csi6447070a12.545.2024.09.11.03.06.08; Wed, 11 Sep 2024 03:06:09 -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=@mur.at header.s=dkim2 header.b=RJ3aWqVx; 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=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4ED7768E087; Wed, 11 Sep 2024 13:06:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 49D8268DEFD for ; Wed, 11 Sep 2024 13:05:57 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id E9CB04622A; Wed, 11 Sep 2024 12:05:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1726049156; bh=pcucNgWXu55Mj+YKP37R2z3RceON2t8aaWKdAXaPYNY=; h=From:To:Cc:Subject:Date:From; b=RJ3aWqVx8rkmF43VBmK3wSwdNPdjzrzwGMleN2/CRVR1vPvsSaqn/0lyK9WiVkGdN Aa0W750rOqs54dC8UQNtRxie98CnIebluER1yCQm5twqN0gVP2Br7iTa8UwUZ+URlN XfAwnPXrRhC6N6oM4uqGBq+NQwnvWaQHZVq9lIsvLX0ucxFt01i7Mk8dDY+oLIMVRw YAklVDR2v6K6tuT+VP1ZFBq3KOkzD45QZ9p2fNbC/9EZTs8/hUajOrUY6rnwp+tbmi 7hQUFW/HzrJKmK0HwEqBGsjWRpHhfrFFgKiEDx4fGwJ6oodRidrwVitG7DaAv2rcOC YaoQltRvMczbuQ8KModcHjLa9PSIz1+l7oMzvltQNbeGtWEZSjM8SqQn3NQ/oyRmh4 ID7/qqWe52mcefDk/0KMHqNj3EHQnx2CrsVNMl75JP1lJ7BImBOD6ZQ2sn4I8Ua63H cj20GgW6anJ6UaeQKd8sOj0oKWU3MpM9dKOQ9xP5+b9qET352k/ From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Sep 2024 12:56:14 +0200 Message-ID: <20240911105616.849239-2-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 1/4] libavcodec/dnxuc_parser: DNxUncompressed essence parser 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tAvUsw5OQM4y This time only small corrections... --- libavcodec/dnxuc_parser.c | 124 ++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 2 files changed, 125 insertions(+) create mode 100644 libavcodec/dnxuc_parser.c diff --git a/libavcodec/dnxuc_parser.c b/libavcodec/dnxuc_parser.c new file mode 100644 index 0000000..55d5763 --- /dev/null +++ b/libavcodec/dnxuc_parser.c @@ -0,0 +1,124 @@ +/* + * Avid DNxUncomressed / SMPTE RDD 50 parser + * Copyright (c) 2024 Martin Schitter + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + This parser for DNxUncompressed video data is mostly based on + reverse engineering of output generated by DaVinci Resolve 19 + but was later also checked against the SMPTE RDD 50 specification. + + Limitations: Multiple image planes are not supported. +*/ + +#include "avcodec.h" +#include "libavutil/intreadwrite.h" + +typedef struct DNxUcParseContext { + uint32_t fourcc_tag; + uint32_t width; + uint32_t height; + uint32_t nr_bytes; +} DNxUcParseContext; + +/* +DNxUncompressed frame data comes wrapped in nested boxes of metadata +(box structure: len + fourcc marker + data): + +[0-4] len of outer essence unit box (typically 37 bytes of header + frame data) +[4-7] fourcc 'pack' + +[8-11] len of "signal info box" (always 21) +[12-15] fourcc 'sinf' +[16-19] frame width / line packing size +[20-23] frame hight / nr of lines +[24-27] fourcc pixel format indicator +[28] frame_layout (0: progressive, 1: interlaced) + +[29-32] len of "signal data box" (nr of frame data bytes + 8) +[33-36] fourcc 'sdat' +[37-..] frame data + +A sequence of 'signal info'+'signal data' box pairs wrapped in +'icmp'(=image component) boxes can be utilized to compose more +complex multi plane images. +This feature is only partially supported in the present implementation. +We never pick more than the first pair of info and image data enclosed +in this way. +*/ + +static int dnxuc_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + char fourcc_buf[5]; + const int HEADER_SIZE = 37; + int icmp_offset = 0; + + DNxUcParseContext *pc; + pc = (DNxUcParseContext *) s->priv_data; + + if (!buf_size) { + return 0; + } + if (buf_size > 16 && MKTAG('i','c','m','p') == AV_RL32(buf+12)){ + icmp_offset += 8; + } + if ( buf_size < 37 + icmp_offset /* check metadata structure expectations */ + || MKTAG('p','a','c','k') != AV_RL32(buf+4+icmp_offset) + || MKTAG('s','i','n','f') != AV_RL32(buf+12+icmp_offset) + || MKTAG('s','d','a','t') != AV_RL32(buf+33+icmp_offset)){ + av_log(avctx, AV_LOG_ERROR, "can't read DNxUncompressed metadata.\n"); + *poutbuf_size = 0; + return buf_size; + } + + pc->fourcc_tag = AV_RL32(buf+24+icmp_offset); + pc->width = AV_RL32(buf+16+icmp_offset); + pc->height = AV_RL32(buf+20+icmp_offset); + pc->nr_bytes = AV_RL32(buf+29+icmp_offset) - 8; + + if (!avctx->codec_tag) { + av_fourcc_make_string(fourcc_buf, pc->fourcc_tag); + av_log(avctx, AV_LOG_INFO, "dnxuc_parser: '%s' %dx%d %dbpp %d\n", + fourcc_buf, + pc->width, pc->height, + (pc->nr_bytes*8)/(pc->width*pc->height), + pc->nr_bytes); + avctx->codec_tag = pc->fourcc_tag; + } + + if (pc->nr_bytes > buf_size - HEADER_SIZE + icmp_offset){ + av_log(avctx, AV_LOG_ERROR, "Insufficient size of image essence data.\n"); + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf + HEADER_SIZE + icmp_offset; + *poutbuf_size = pc->nr_bytes; + + return buf_size; +} + +const AVCodecParser ff_dnxuc_parser = { + .codec_ids = { AV_CODEC_ID_DNXUC }, + .priv_data_size = sizeof(DNxUcParseContext), + .parser_parse = dnxuc_parse, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 5128009..8bfd2db 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -35,6 +35,7 @@ extern const AVCodecParser ff_cri_parser; extern const AVCodecParser ff_dca_parser; extern const AVCodecParser ff_dirac_parser; extern const AVCodecParser ff_dnxhd_parser; +extern const AVCodecParser ff_dnxuc_parser; extern const AVCodecParser ff_dolby_e_parser; extern const AVCodecParser ff_dpx_parser; extern const AVCodecParser ff_dvaudio_parser; From patchwork Wed Sep 11 10:56:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51506 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:14c:b0:48e:c0f8:d0de with SMTP id h12csp209889vqi; Wed, 11 Sep 2024 03:06:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUmmOKMYCkoBcct0Xg2L52VRydRE/y0GJFtSSWD3Ox+N/u/wNPqbkyOw/+cHg+mj2a25Na7VkFI3vaer3fJCAoo@gmail.com X-Google-Smtp-Source: AGHT+IEETEvl8Q/U8223KP19D9BeGQq1zuE8qwOLQOguTKaXncLYyZpadv2wlxV71gxFIVF1H/o1 X-Received: by 2002:a17:907:ea4:b0:a7a:b4bd:d0eb with SMTP id a640c23a62f3a-a900481d1c3mr199431666b.24.1726049181430; Wed, 11 Sep 2024 03:06:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726049181; cv=none; d=google.com; s=arc-20240605; b=Z7Cv6CmIAM/jjtWWD0vKy3iWL7g7+2mebbF9L81BtYxuMwG/lrXxfdD2iRopD2ToLd 6taOjkFXobduquheuJZZITL9ui6UEX5ToxmolG5UdynMd91rW58K9bSobgthrNnDrQcI vDcpJOWKkH6+R8cTqkKAPeKSM1VKAbt3qJUn8iI4AuTGiHw9YfOtGHmStSQsCm4h44ph C8w2ZmxbZxiW3AAazNiwPu+QwCM5AgeBTC9txVMPyM/6LJwlSpvUbOEBO8eJSUwgJjFb 3J9bNuyNYgFMbZg79L1uRLmJwmZj8cuVw9B+4J+88xnjwUm+jjq78KVWhdG7eEUL5nmp awYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=DrvUkoEssRJUWyS5e+req6+37SQi5j9oJnpou6I0K2w=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=lmwBcOgJJ4f4Eup98ouJVRp+O5jQWiObzFO4Z8M7z+rEG5NMXHpCASxbvG4Kkmvlpm AC7AssQtAqhcP/2M+fHuNOmWVc1pW8Dh5eGlv9Bc5Rz6eq8lHnIYQL7kuNAq2ffMu43K qRSS6mU6e2NdQYVD7diSf8sxPqD+Tpagg3qmmKC1BORmwfvQgAn4vCn/TpjbsSCbBK6o EMu2/UH+00hGFSlDdVqk385r9mBOHcEfimUPFrU4+gES5AssxIqdHAy/NBPF0m32UCWf ZqqxVzLL7YKU/shjoADSogwMn66oGgIpSLi+ZvuNodVFDPCbytkvPU/yCA8f+XY41oYK 69Zg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b="aSYwR/pA"; 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=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a8d25c60b9asi679743566b.437.2024.09.11.03.06.20; Wed, 11 Sep 2024 03:06:21 -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=@mur.at header.s=dkim2 header.b="aSYwR/pA"; 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=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FB3468E089; Wed, 11 Sep 2024 13:06:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6626D68DF1C for ; Wed, 11 Sep 2024 13:05:57 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 0FC2A46233; Wed, 11 Sep 2024 12:05:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1726049157; bh=BlF9cqSZZGfUgwf4J3P3yAlAhigvQ8sBjEtPD2dFsJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aSYwR/pAqxmoRpFDWulDQv5oMxO11zKbNlZngDbS71QVGRwu/AUJeFBeSdwnT1Yfu oxj7lXtZsjFJ8Si9mIPjMnpgo6Hy32J5KHwbzXfQXWwF4YgjcDQgPK0ktWsVIvS2+u ql0SnUZ9rAfEdyIY+30lzSQpR3P5YbRVeSucWIcGeBY+EFPtpEsn/BqkIjZLKuu02P HkdyFmW/1R1H/poXIt77oGFAZ2H44Lt5cMATKfhHODINri67HgjK5MgH8zl9flDs4U QYOicpIBI/h8iaVCpfrYgw2hN3wHqjv9JrwLEV/gAfp+oOskWp7RT1kyeUuTQaGjP5 DsEieQJmYPyYAMBp0Y6YyUrrXJfAS4wNGo3a1UGUdo/N9vpWsLK/ioOi5sfUaqnOmW uw6DxWzzkEHxOZVxjbuDZHwe0Pgfvste3Lqnncmyj6aifzkfEGYOyojEwosiysnGsB +CsM2OR/zv4Tv+9iSZRfbiNxUqUKnNO1Jd3XY7emQDKJxXvb4IK From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Sep 2024 12:56:15 +0200 Message-ID: <20240911105616.849239-3-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240911105616.849239-2-ms+git@mur.at> References: <20240911105616.849239-2-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 2/4] libavformat/mxf: add DNxUncompressed MXF ULs 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: pXGv+7VX2c6Z --- libavformat/mxf.c | 1 + libavformat/mxfdec.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index a73e40e..885b4df 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -61,6 +61,7 @@ const MXFCodecUL ff_mxf_codec_uls[] = { { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x71,0x00,0x00,0x00 }, 13, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0E,0x04,0x02,0x01,0x02,0x04,0x01,0x00 }, 16, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD Legacy Avid Media Composer MXF */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0D,0x04,0x01,0x02,0x02,0x03,0x07,0x01,0x00 }, 15, AV_CODEC_ID_DNXUC }, /* DNxUncompressed/SMPTE RDD 50 */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, AV_CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 14, AV_CODEC_ID_H264 }, /* H.264/MPEG-4 AVC SPS/PPS in-band */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x01 }, 16, AV_CODEC_ID_V210 }, /* V210 */ diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index ac63c0d..142b3e6 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1597,6 +1597,7 @@ static const MXFCodecUL mxf_picture_essence_container_uls[] = { { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 }, 14, AV_CODEC_ID_JPEG2000, NULL, 14, J2KWrap }, { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x10,0x60,0x01 }, 14, AV_CODEC_ID_H264, NULL, 15 }, /* H.264 */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 }, 14, AV_CODEC_ID_DNXHD, NULL, 14 }, /* VC-3 */ + { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1e,0x01,0x00 }, 14, AV_CODEC_ID_DNXUC, NULL, 14 }, /* DNxUncompressed / SMPTE RDD 50 */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x12,0x01,0x00 }, 14, AV_CODEC_ID_VC1, NULL, 14 }, /* VC-1 */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x14,0x01,0x00 }, 14, AV_CODEC_ID_TIFF, NULL, 14 }, /* TIFF */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x15,0x01,0x00 }, 14, AV_CODEC_ID_DIRAC, NULL, 14 }, /* VC-2 */ From patchwork Wed Sep 11 10:56:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51507 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:14c:b0:48e:c0f8:d0de with SMTP id h12csp210024vqi; Wed, 11 Sep 2024 03:06:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWqCELEBeh4E13U1BdsH2oTow1ShXTs1ax99aFIkMehEyO4xG9JqKbpvpfPpXrUS9RhrPnPvyLausfqEO77yc42@gmail.com X-Google-Smtp-Source: AGHT+IFUziqIloU3DhNvAclw7PjUXrq61MAj2iXI6VTmKVsAQFM72IyYPWqDazxuEzNmujwCoPVM X-Received: by 2002:a05:651c:50f:b0:2f3:b38c:a142 with SMTP id 38308e7fff4ca-2f751fa4a8amr51764981fa.6.1726049193969; Wed, 11 Sep 2024 03:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726049193; cv=none; d=google.com; s=arc-20240605; b=kFksGGdMZhBdgUblqso61+JAYf3JJHRDxXeepbouBWvLAcQFAL+ykizPVKHReQevmd c5Pr0Abs7lZMnuX4wT5dxocYBtmDj1pVhau/mI+kRnM8Q/YNLQtLigjh4FCevuU647G8 9PMDhzoWxh5/S0jqouC9DauM4tnP3jzvIUiAgkCrrjE7VOAP/zwVh3c1RygMQ/gGXxBE 3/cHngA4Lazt/BpdQ+Go54w+QUwCtvZudGxcQV6xV5pKKDR0ZCNVrb8TxYjKQKt2RYMe 0RpMX5whB1FvvJ9Xmfna0XdmaVSvMGYfnKrvbpPYD8qm8gTBSlb/wTbwDFUs3aKfRJ6W vx9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=IAGSl/Uk9Ig7TjF4xe3bY4C0/UDc6/pDSFU1gzMNH9U=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=Wj0t2Mx0E8iV5CM0eEYaMrgMlDu0/KTbu77OEEXNP6yThQOezMmKbrNXAM21v5sZGj 0AfhgedcIVMjsQdsBwWpjJ8BzeNdCWPgZEaWEfk1WbFmvl89NWo0Y3WLDY3bj+75OdDz 0ppPMLPZIk7IGscdpm8pHhEoTvE+Pq1nEXhds6zNJixba/qAnugD38Wo/n/5aSvFj+SH 48Y7cbASy6RdFieVom1qNKV+gq9TGToxmPv4rEBudy6pRchee7FAM9teIMde78eZpa2K P7pe97Pmk70EPWmTJHrRmG+ZjgVkyHPrAl7vjS8OurxyfpGL6xov9upMS7tFT/bNohLx gKug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=sVcn8tlJ; 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=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2f75c0b8a22si27321471fa.624.2024.09.11.03.06.33; Wed, 11 Sep 2024 03:06:33 -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=@mur.at header.s=dkim2 header.b=sVcn8tlJ; 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=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 88D6468E097; Wed, 11 Sep 2024 13:06:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7AE3068DFE4 for ; Wed, 11 Sep 2024 13:05:57 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 29F4846238; Wed, 11 Sep 2024 12:05:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1726049157; bh=ioi6G+2ytLZ1VtONTYKT+3FFlwi1+8sist6CaWt9gSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sVcn8tlJ+YpBTRC14J4Z9oLqsE8jHMYU05Pbq2hCeDtgL5aWDczvEHd7NF7FqyQ0t AF4cLOOjUzvpRogBl3foLtJm066JRPGQe2LjJkpyFxmdQrRRrXYHOaFxZWiBd7q1EZ YfX+tcruMGVxg9CabBvPCsc7754c7oKPBWUYhpVjDEdVeylAXhQG20Vr2OTO+XwsK4 SgCJh92/c5VjDVZi49AO6zEb2yfh7EttOZR5CVQYDRXiVEAuBR91ZiLTokHNk0aB1S CLQ15TrlFyOd4q35EOOsmrdpdpw4ric5X8oq4bxP1FBkQSvYBt8bI/hGcMQZdK560Q O9CtNowHtC6zgMkR1nya5kNYv8mfSllSKhmQdwkbMn49CivlGHdQkOPA+FAgMnGH9b L7bPKMqZLS7s8gHTUZdCysZT/NmAdrcQGJNH5A28H9ZJwNEzk+s4NY3ddsT6VOYbrG 1p527ZKgZWpwPiBy8qlnwc1um3CTb5uja63y5NzcMg5a8o9tIQM From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Sep 2024 12:56:16 +0200 Message-ID: <20240911105616.849239-4-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240911105616.849239-2-ms+git@mur.at> References: <20240911105616.849239-2-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 3/4] libavformat/dnxucdec: DNxUncompressed decoder 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JI74XPvIyqqA --- libavcodec/allcodecs.c | 1 + libavcodec/codec_desc.c | 7 + libavcodec/codec_id.h | 1 + libavcodec/dnxucdec.c | 391 ++++++++++++++++++++++++++++++++++++++++ libavcodec/version.c | 2 +- 5 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 libavcodec/dnxucdec.c diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index d773ac3..1a3c084 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -93,6 +93,7 @@ extern const FFCodec ff_dfa_decoder; extern const FFCodec ff_dirac_decoder; extern const FFCodec ff_dnxhd_encoder; extern const FFCodec ff_dnxhd_decoder; +extern const FFCodec ff_dnxuc_decoder; extern const FFCodec ff_dpx_encoder; extern const FFCodec ff_dpx_decoder; extern const FFCodec ff_dsicinvideo_decoder; diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index a28ef68..27bf105 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1959,6 +1959,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("LEAD MCMP"), .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_DNXUC, + .type = AVMEDIA_TYPE_VIDEO, + .name = "dnxuc", + .long_name = NULL_IF_CONFIG_SMALL("DNxUncompressed / SMPTE RDD 50"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, + }, /* various PCM "codecs" */ { diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index 0ab1e34..c8f8072 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -322,6 +322,7 @@ enum AVCodecID { AV_CODEC_ID_RTV1, AV_CODEC_ID_VMIX, AV_CODEC_ID_LEAD, + AV_CODEC_ID_DNXUC, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/dnxucdec.c b/libavcodec/dnxucdec.c new file mode 100644 index 0000000..8fffd0a --- /dev/null +++ b/libavcodec/dnxucdec.c @@ -0,0 +1,391 @@ +/* + * Avid DNxUncomressed / SMPTE RDD 50 decoder + * Copyright (c) 2024 Martin Schitter + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + This decoder for DNxUncompressed video data is mostly based on + reverse engineering of output generated by DaVinci Resolve 19 + but was later also checked against the SMPTE RDD 50 specification. + + Not all DNxUncompressed pixel format variants are supported, + but at least an elementary base set is already usable: + + - YUV 4:2:2 8/10/12bit + - RGB 8/10/12bit/half/float + +*/ + +#include "avcodec.h" +#include "codec_internal.h" +#include "decode.h" +#include "libavutil/imgutils.h" +#include "thread.h" + +static av_cold int dnxuc_decode_init(AVCodecContext *avctx) +{ + return 0; +} + + +static int pass_though(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt) +{ + /* there is no need to copy as the data already match + * a known pixel format */ + + frame->buf[0] = av_buffer_ref(avpkt->buf); + + if (!frame->buf[0]) { + return AVERROR(ENOMEM); + } + + return av_image_fill_arrays(frame->data, frame->linesize, avpkt->data, + avctx->pix_fmt, avctx->width, avctx->height, 1); +} + +static int float2planes(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw; + const size_t sof = 4; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + memcpy(&frame->data[2][sof*(lw*y + x)], &pkt->data[sof* 3*(lw*y + x)], sof); + memcpy(&frame->data[0][sof*(lw*y + x)], &pkt->data[sof*(3*(lw*y + x) + 1)], sof); + memcpy(&frame->data[1][sof*(lw*y + x)], &pkt->data[sof*(3*(lw*y + x) + 2)], sof); + } + } + return pkt->size; +} + +static int half_add_alpha(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + /* ffmpeg doesn't provide RGB half bit depth without alpha channel right now + * we simply add an opaque alpha layer as workaround */ + + int x, y, lw; + const size_t soh = 2; + const uint16_t opaque = 0x3c00; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + memcpy(&frame->data[0][soh*4*(lw*y + x)], &pkt->data[soh*3*(lw*y + x)], soh*3); + memcpy(&frame->data[0][soh*(4*(lw*y + x) + 3)], &opaque, soh); + } + } + return pkt->size; +} + +/* DNxUncompressed utilizes a very dense bitpack representation of 10bit and 12bit pixel data. + +Lines of Image data, which look like in their ordinary 8bit counterpart, contain the most +significant upper bits of the pixel data. These sections alternate with shorter segments in +which the complementary least significant bits of information get packed in a gapless sequence. + ++----------------------+ +----------------------+ +------------------------+ +----------~ +| 8 m.s.bits of R[1] | | 8 m.s.bits of G[1] | | 8 m.s.bits of B[1] | | msb R[2] ... one line ++----------------------+ +----------------------+ +------------------------+ +----------~ + ++---------------------------------------------------------------+ +-----------~ +| +------------+ +------------+ +------------+ +--------------+ | | +--------~ +| | 2 lsb R[2] | | 2 lsb B[1] | | 2 lsb G[1] | | 2 lsb R[1] | | | | G[3]lsb ... LSB bits for line +| +------------+ +------------+ +------------+ +--------------+ | | +--------~ ++---------------------------- one byte ------------------------ + +-----------~ + +next line of MSB bytes... */ + +static int unpack_rg10(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t r,g,b; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + msp = pkt->data[y*3*(lw + lw/4) + 3*x]; + p_off = y*(3*(lw + lw/4)) + 3*lw + 3*x/4; + pack = pkt->data[p_off]; + lsp = (pack >> (3*x%4)*2) & 0x3; + r = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "r: %04x, %02x, %02x, %02x, %d\n", + // r, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/4) + 3*x + 1]; + p_off = y*(3*(lw + lw/4)) + 3*lw + (3*x+1)/4; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+1)%4)*2) & 0x3; + g = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "g: %04x, %02x, %02x, %02x, %d\n", + // g, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/4) + 3*x + 2]; + p_off = y*(3*(lw + lw/4)) + 3*lw + (3*x+2)/4; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+2)%4)*2) & 0x3; + b = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "b: %04x, %02x, %02x, %02x, %d\n\n", + // b, msp, lsp, pack, p_off); + + memcpy(&frame->data[2][2*(y*lw + x)], &r, 2); + memcpy(&frame->data[0][2*(y*lw + x)], &g, 2); + memcpy(&frame->data[1][2*(y*lw + x)], &b, 2); + } + } + return pkt->size; +} + +static int unpack_rg12(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t r,g,b; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + msp = pkt->data[y*3*(lw + lw/2) + 3*x]; + p_off = y*(3*(lw + lw/2)) + 3*lw + 3*x/2; + pack = pkt->data[p_off]; + lsp = (pack >> (3*x%2)*4) & 0xf; + r = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "r: %04x, %02x, %02x, %02x, %d\n", + // r, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/2) + 3*x + 1]; + p_off =y*(3*(lw + lw/2)) + 3*lw + (3*x+1)/2; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+1)%2)*4) & 0xf; + g = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "g: %04x, %02x, %02x, %02x, %d\n", + // g, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/2) + 3*x + 2]; + p_off = y*(3*(lw + lw/2)) + 3*lw + (3*x+2)/2; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+2)%2)*4) & 0xf; + b = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "b: %04x, %02x, %02x, %02x, %d\n\n", + // b, msp, lsp, pack, p_off); + + memcpy(&frame->data[2][2*(y*lw + x)], &r, 2); + memcpy(&frame->data[0][2*(y*lw + x)], &g, 2); + memcpy(&frame->data[1][2*(y*lw + x)], &b, 2); + } + } + return pkt->size; +} + + +static int unpack_y210(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t y1, y2, u, v; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x += 2){ + + p_off = y*(2*(lw + lw/4)) + 2*lw + x/2; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/4) + 2*x]; + lsp = pack & 0x3; + u = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, " u: %04x, %02x, %02x, %02x, %d\n", + // u, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 1]; + lsp = (pack >> 2) & 0x3; + y1 = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "y1: %04x, %02x, %02x, %02x, %d\n", + // y1, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 2]; + lsp = (pack >> 4) & 0x3; + v = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, " v: %04x, %02x, %02x, %02x, %d\n", + // v, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 3]; + lsp = (pack >> 6) & 0x3; + y2 = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "y2: %04x, %02x, %02x, %02x, %d\n\n", + // y2, msp, lsp, pack, p_off); + + memcpy(&frame->data[0][2*(y*lw + x)], &y1, 2); + memcpy(&frame->data[0][2*(y*lw + x+1)], &y2, 2); + memcpy(&frame->data[1][2*(y*lw/2 + x/2)], &u, 2); + memcpy(&frame->data[2][2*(y*lw/2 + x/2)], &v, 2); + } + } + return pkt->size; +} + + +static int unpack_y212(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t y1, y2, u, v; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x += 2){ + + p_off = y*(2*(lw + lw/2)) + 2*lw + x; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/2) + 2*x]; + lsp = pack & 0xf; + u = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, " u: %04x, %02x, %02x, %02x, %d\n", + // u, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 1]; + lsp = (pack >> 4) & 0xf; + y1 = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "y1: %04x, %02x, %02x, %02x, %d\n", + // y1, msp, lsp, pack, p_off); + + p_off = y*(2*(lw + lw/2)) + 2*lw + x+1; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 2]; + lsp = pack & 0xf; + v = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, " v: %04x, %02x, %02x, %02x, %d\n", + // v, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 3]; + lsp = (pack >> 4) & 0xf; + y2 = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "y2: %04x, %02x, %02x, %02x, %d\n\n", + // y2, msp, lsp, pack, p_off); + + memcpy(&frame->data[0][2*(y*lw + x)], &y1, 2); + memcpy(&frame->data[0][2*(y*lw + x+1)], &y2, 2); + memcpy(&frame->data[1][2*(y*lw/2 + x/2)], &u, 2); + memcpy(&frame->data[2][2*(y*lw/2 + x/2)], &v, 2); + } + } + return pkt->size; +} + +static int check_pkt_size(AVCodecContext *avctx, AVPacket *avpkt, int bpp) +{ + int needed = ((avctx->width * bpp + 7) / 8) * avctx->height; + if (avpkt->size < needed){ + av_log(avctx, AV_LOG_ERROR, + "Insufficient size of AVPacket data (pkg size: %d needed: %d)\n", avpkt->size, needed); + return AVERROR_EXIT; + } + return 0; +} + +static int fmt_frame(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt, + enum AVPixelFormat pix_fmt, int src_bpp, + int (*frame_handler)(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt)) +{ + int ret; + avctx->pix_fmt = pix_fmt; + + ret = check_pkt_size(avctx, avpkt, src_bpp); + if (ret) + return ret; + + ret = ff_thread_get_buffer(avctx, frame, 0); + if (ret < 0) + return ret; + + return frame_handler(avctx, frame, avpkt); +} + +static int dnxuc_decode_frame(AVCodecContext *avctx, AVFrame *frame, + int *got_frame, AVPacket *avpkt) +{ + char fourcc_buf[5]; + int ret; + + av_fourcc_make_string(fourcc_buf, avctx->codec_tag); + if ((avctx->width % 2) && ((fourcc_buf[0] == 'y' && fourcc_buf[1] == '2') + ||(fourcc_buf[1] == 'y' && fourcc_buf[2] == '2'))){ + av_log(avctx, AV_LOG_ERROR, + "Image width must be a multiple of 2 for YUV 4:2:2 DNxUncompressed!\n"); + return AVERROR_EXIT; + } + + switch (avctx->codec_tag) { + case MKTAG('r','g','0','8'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_RGB24, 24, pass_though); + break; + case MKTAG('r','g','1','0'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRP10LE, 30, unpack_rg10); + break; + case MKTAG('r','g','1','2'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRP12LE, 36, unpack_rg12); + break; + case MKTAG(' ','r','g','h'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_RGBAF16LE, 48, half_add_alpha); + break; + case MKTAG(' ','r','g','f'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRPF32LE, 96, float2planes); + break; + + case MKTAG('y','2','0','8'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_UYVY422, 16, pass_though); + break; + case MKTAG('y','2','1','0'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_YUV422P10LE, 20, unpack_y210); + break; + case MKTAG('y','2','1','2'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_YUV422P12LE, 24, unpack_y212); + break; + + default: + av_log(avctx, AV_LOG_ERROR, + "Unsupported DNxUncompressed pixel format variant: '%s'\n", + fourcc_buf); + return AVERROR(ENOSYS); + } + + if (ret < 0) { + av_buffer_unref(&frame->buf[0]); + return ret; + } + + *got_frame = 1; + + return avpkt->size; +} + +const FFCodec ff_dnxuc_decoder = { + .p.name = "dnxuc", + CODEC_LONG_NAME("DNxUncompressed (SMPTE RDD 50)"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_DNXUC, + .init = dnxuc_decode_init, + FF_CODEC_DECODE_CB(dnxuc_decode_frame), + .p.capabilities = AV_CODEC_CAP_FRAME_THREADS, +}; diff --git a/libavcodec/version.c b/libavcodec/version.c index 27f9432..03dd95e 100644 --- a/libavcodec/version.c +++ b/libavcodec/version.c @@ -31,7 +31,7 @@ const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION; unsigned avcodec_version(void) { - static_assert(AV_CODEC_ID_LEAD == 269 && + static_assert(AV_CODEC_ID_DNXUC == 270 && AV_CODEC_ID_PCM_SGA == 65572 && AV_CODEC_ID_ADPCM_XMD == 69683 && AV_CODEC_ID_CBD2_DPCM == 81928 && From patchwork Wed Sep 11 10:56:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51508 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:14c:b0:48e:c0f8:d0de with SMTP id h12csp210125vqi; Wed, 11 Sep 2024 03:06:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXeqoWQdNcpFl4I2QuGC8R6yRvdmDAw1auyRI5jljF49RKmt5sW/ZPgOqzRA7mn+EwaImEqEs05mdlnd7tR23VD@gmail.com X-Google-Smtp-Source: AGHT+IGW3tRSvpCKER4joaEb0jetnU91gB4bb4zXu7/PAw8rjLc64dAiiAYjJC/E0O08MZK4BWYA X-Received: by 2002:a05:6512:3a94:b0:52c:dc6f:75a3 with SMTP id 2adb3069b0e04-53673c95d26mr1389292e87.40.1726049206277; Wed, 11 Sep 2024 03:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726049206; cv=none; d=google.com; s=arc-20240605; b=Rc9aBIMg4pBGspPozRzvN99E0KcPsEY85Jypu447UvPdHUBqROgbK175wojt16Nz8s ruSsmEYlMRfH42sUwkbxV3Hv/l8vm6C7BTbzevvXcmb9pWPLsikB/RBoz5D2j80xX7Y+ e0UB9wSyMDKcYUtF3e/5SQ3NeF4QKvAuep5cNoLNxEcFcbDQjz3waW3zTUZnKXO1nm1C WW36OYmFJndsZjJ9a2GYH/K5pYmWpevB8u4gWcDDO1Ut5w7h/DCkP61rtnhbQlIxDzKt j8/UayZ0RtBGqc5pZEw63McGFfdXZAjLulWh3yFEBf1cdlNHnP0wscFC3ac5W1LtKtVH 23Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=aVx4au0vAFuKTDqVRMt54XaMK8ugQFwQNBry+idwxEY=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=L1qM7qPS0O+uwJ6qtvYbArCrPa6LgIUnZMcaAIm8s0S7K7VwUtCPeBuzZ2wn0rUqBI yDu6MQn6NnOBKfRX6T77WPVLk1eDTG8xJoCCwykFgdgJC17P5km9KiZn9crSTibDSJ26 73XY5Gyc7SRTOemZDaxXHl2d3HqAaJpU3M+Q5eMrRhYh1AZgkk+Q8n9FuCZqFH/Scauy XYstqSFcnAS1tmWGbvl43in6gqOYFM5bbOqCBH+OQAx93Y/xh2NT1nQVScnXq0JI4eFq R8a8fGuWyQ15kMr0Mtrvxjt2cJQjc2QuToRJc9NNiOsZwnoiWb04m41ed1JUCw3pjgNK CjgA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=YafCOqaU; 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=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-5365f90ef40si3116944e87.593.2024.09.11.03.06.45; Wed, 11 Sep 2024 03:06:46 -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=@mur.at header.s=dkim2 header.b=YafCOqaU; 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=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 06ADD68E0A4; Wed, 11 Sep 2024 13:06:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9269D68DF1C for ; Wed, 11 Sep 2024 13:05:57 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 41E9D4623D; Wed, 11 Sep 2024 12:05:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1726049157; bh=EgRVy4yrJNQQ+auAUFZNT8Dt7UUJ+Y0xfHmM1FYp/RY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YafCOqaUK15JRrGu7SsMEa0XOKJDK5DhOdKuoPLeF3A3dSZvss0+NNkENkYA3E47j 8waWCURocxwuzb+K2mwW8+Fxd0m824sO43rx283NzUCs86FO6HNfAg9sntOXB56hcR gxx6Zj6tqhHkzlWRTavh2u63HFMNdDo57pFj1GplmJhOnzVRe50M7+zazbIHP/UMiG Ku6BpARTl61p8HI2iDXr3I277EQW4BvHjV/TzsZMZOvZQ/ExvcmL5j6WiBlGgCmH4z BQcFxn8aBAEzCyY+CqpzaLSQYP/RLQ+YJdPEqGWJk8M2F/8Lylku+FQ/zeofypkz2w 7BZWxdxvCDExbMhCAV/0tMbtf9tLW71Ek6zDlS9iS3RAcSECsT4cFuk8jkDqluDeW3 tatllOeEAJWKX1NjqHBZUyib1/6HloqHWOTvt3ErGEguNFPSRbQintoH8nWjHIMF7j p+cBpXLzMXas37+4T7JnXvOQDnfAXR0SYwdff91dbNblgaBb9QL From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Sep 2024 12:56:17 +0200 Message-ID: <20240911105616.849239-5-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240911105616.849239-2-ms+git@mur.at> References: <20240911105616.849239-2-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 4/4] libavformat: DNxUncompressed aux files 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /nub/YLEQbPl --- Changelog | 1 + libavcodec/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 7237648..0464bee 100644 --- a/Changelog +++ b/Changelog @@ -20,6 +20,7 @@ version : - Intel QSV-accelerated VVC decoding - MediaCodec AAC/AMR-NB/AMR-WB/MP3 decoding - YUV colorspace negotiation for codecs and filters, obsoleting YUVJ +- DNxUncompressed (SMPTE RDD 50) decoder version 7.0: diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1d27e55..eee98ed 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -325,6 +325,7 @@ OBJS-$(CONFIG_DFPWM_DECODER) += dfpwmdec.o OBJS-$(CONFIG_DFPWM_ENCODER) += dfpwmenc.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o +OBJS-$(CONFIG_DNXUC_DECODER) += dnxucdec.o dnxuc_parser.o OBJS-$(CONFIG_DOLBY_E_DECODER) += dolby_e.o dolby_e_parse.o kbdwin.o OBJS-$(CONFIG_DPX_DECODER) += dpx.o OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o