From patchwork Mon Jul 24 02:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hung kuishing X-Patchwork-Id: 42934 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be1d:b0:130:ccc6:6c4b with SMTP id ge29csp1649535pzb; Sun, 23 Jul 2023 19:37:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlHiJDezjxQmG2f67u7nYsamsx4nH62OKaLntzk62iHQPJzj+iOnjKf53huRuo7rK8Me3RZN X-Received: by 2002:a17:906:7699:b0:98b:dc6c:b304 with SMTP id o25-20020a170906769900b0098bdc6cb304mr8737167ejm.38.1690166261329; Sun, 23 Jul 2023 19:37:41 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qp25-20020a170907207900b00988698d7c35si5576276ejb.944.2023.07.23.19.37.41; Sun, 23 Jul 2023 19:37:41 -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=@outlook.com header.s=selector1 header.b=X7k2vTua; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8A8B368C738; Mon, 24 Jul 2023 05:37:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12olkn2065.outbound.protection.outlook.com [40.92.21.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E12768C67D for ; Mon, 24 Jul 2023 05:37:32 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TNU1Dv1pQEaCd6KEIWF40zEi3bWV3m+xTy5XA2OfDCI1iw2aM5tXqcw0iIqdq/PsANYa7Hmm0lKwus0oA7SwlXPnV9nF5KD5WiCjLYbDHsbfxMKG9fMmiPMXEveWhZnUlcgJGdt7cUVz+vKz/VajidL0gB+gw+4kVnPZtKCr97MLOKta0NjM+2Q8jlHlqRAD+PTIkLFhNAca7L18jnuP1khGN8IWZ+qlZqpeEC2Z8X+rUHhUhcWEUO+2PthBMcJ7z5S1fK1ElnZQ/o+3BsKLlnGojoDQud4K9xeVg7ngtCNAujP1rvxkZ+phdL71bZupzTSYjrISWR7HngRC9EoeHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w7YJ14xEy8jcf+bFRNkIB3nGoiiXHtWEATAzglgW1Ew=; b=jRxh68U0QFr2gzBd1oK2PNHszhO+Zouc/BqjQ5ednzoVcUg4jK7gq8TFnRS8WQeOzfiiOBMWAcKrgDkkcNTQS5HSvXChnbdqYr4wuCNtWXJUnQ6DqBBA9mobgdcEBOVMFAgD4TXxIblfiTwYtG8OuU6+LXHU45WppJDXHVg70qL8ZZu8mp2llLEq/4kBTlyEvh7tnrtDEgmHnIJbyn3y8rprB+HGTWDrcnodXRdSs/f8xxzfFgXWwasTyAvv2hkh5mxy3JYvQ9Z6M8aWGha5QG4sFko6PX/c0PoJyNcwMhpdIEZ9mlA9doFyaMGeSVpU1im0FUe8ISMnL1DrK5jgaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w7YJ14xEy8jcf+bFRNkIB3nGoiiXHtWEATAzglgW1Ew=; b=X7k2vTuaWoRKgiLNvBmy85Dfsag/1ZQQaC/RVvlczl6lZ7mlkiRYfhNH2NlOl+kzJ7CfGHVfMGqt4NIYakqA8jVlN+3ZVN/aMEwjYWNf6JRgpixD/yafl/ftWLSLVtswbm+zL6vb68bKAtdCp16OHezCtB2tzela2+/zJUQCPO87iDXx8NrDgTep4hmIGvNme2ei+x0dkA7reuDjxi4azIhhn54hq7rhWbFoQrVntdh5xvL7xeNya+TdYF+KTTMz/nJFrKfHVrr/FbGoz8LD1m/j0jGAK3M/J3SbkZW3QeAz/GBBu06pKgOVOiNyw2VL3yNsWs6z9G30hllpzE7/zw== Received: from PH7PR11MB7430.namprd11.prod.outlook.com (2603:10b6:510:274::20) by PH8PR11MB7021.namprd11.prod.outlook.com (2603:10b6:510:223::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 02:37:29 +0000 Received: from PH7PR11MB7430.namprd11.prod.outlook.com ([fe80::6216:b3a7:a5b2:bd43]) by PH7PR11MB7430.namprd11.prod.outlook.com ([fe80::6216:b3a7:a5b2:bd43%4]) with mapi id 15.20.6609.031; Mon, 24 Jul 2023 02:37:29 +0000 From: hung kuishing To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] add prores bitstream demuxer and muxer Thread-Index: Adm3kVnd2HkDpZRvRuWzRFTGp4i0Ww== Date: Mon, 24 Jul 2023 02:37:29 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [TmCmckN8pFR7dDKT0oLpfu+5xkguSxyJCAuwFpNujq0=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH7PR11MB7430:EE_|PH8PR11MB7021:EE_ x-ms-office365-filtering-correlation-id: ec8f769b-ca55-4f21-e572-08db8beeecc0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dEVSg05Izii+ODLbWMLyMg/BfRKxlENEQ/eZ8dhQCcRSURzuNfvQb2yLfOnZ39JKtZp4lVcWnY6McHDou1X09VmM1OOeu8kaxY4ZHP9WzLLt9QBh4xmQT1Bbd7Ot8g2LWiVLYRCItShNWY2JppCKwRoxbqJ2brnieMdStINZTQmYlgwvKDdJ6yta6M7ZYiC9lqy2Qf/1BbQszUU+sjwJxnThfkBr+9c7VkZgEATdH6pZqT85C0I1mwjbuL2OXTaIqyU84yWAT/A+TN0S4uip8u09rhL2ZQbeH6YVVFCly991cWxWtUMRXuejhxj1Vw9YZR9nb5Ddcvc21PrBSBz8geSeskhw517nOjHgAZ6aX69s9fUAc4ps7nCRRmx7tM5KOvYhA9ybYd4QIP7tDaDakL96dLihQpX2PL+6gLYDo6OuUa0cnms1pfIVXP2kM4d2mog/KDeVoL11Mlf8FiOBoVLvafb+ggTg0DbvKe8Kr0Wsq3YrJSmpQdezu5vS+3kwFvkOsRprOkkuH7K3raKUZ1NJvz8E3hMBoqL4d+FYxFdtxTDNox1fJpeCYCevr08z x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: drlVQr4EMzJDeI0l70JjfzOFOBLc9fxBzdMJuXpkH16T0XA2QdxNlsVu0tUQSvtWKGXHLMTlsVn8NCDc1D82Ef8JB0bcx8cGy0pdMv+Et66RKVy05ln3GfajxDyS7RF5MfpcsKLiDCZRKuvxRJGNlmd/WANJF6a5wCK9hr0+gEeQ40inl64aHVBjEPEw33aWGX/LGQ5X/sbkBAcm+zzXo1G+OE/UhK5DZeefHezelGCGkZ6kAnzQ7AQtC9Dw3b9cOE5oVcmjMe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B7430.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: ec8f769b-ca55-4f21-e572-08db8beeecc0 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jul 2023 02:37:29.3084 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB7021 Subject: [FFmpeg-devel] [PATCH] add prores bitstream demuxer and muxer 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: DYpWq/sJqkQv --- libavcodec/Makefile | 1 + libavcodec/parsers.c | 1 + libavcodec/prores_parser.c | 91 ++++++++++++++++++++++++++++++++++++++ libavformat/Makefile | 2 + libavformat/allformats.c | 2 + libavformat/proresdec.c | 62 ++++++++++++++++++++++++++ libavformat/rawenc.c | 13 ++++++ 7 files changed, 172 insertions(+) create mode 100644 libavcodec/prores_parser.c create mode 100644 libavformat/proresdec.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1b0226c089..b6ebbfb340 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1214,6 +1214,7 @@ OBJS-$(CONFIG_WEBP_PARSER) += webp_parser.o OBJS-$(CONFIG_XBM_PARSER) += xbm_parser.o OBJS-$(CONFIG_XMA_PARSER) += xma_parser.o OBJS-$(CONFIG_XWD_PARSER) += xwd_parser.o +OBJS-$(CONFIG_PRORES_PARSER) += prores_parser.o # bitstream filters OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 285f81a901..ff7c15b7d1 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -80,6 +80,7 @@ extern const AVCodecParser ff_webp_parser; extern const AVCodecParser ff_xbm_parser; extern const AVCodecParser ff_xma_parser; extern const AVCodecParser ff_xwd_parser; +extern const AVCodecParser ff_prores_parser; #include "libavcodec/parser_list.c" diff --git a/libavcodec/prores_parser.c b/libavcodec/prores_parser.c new file mode 100644 index 0000000000..4b50147768 --- /dev/null +++ b/libavcodec/prores_parser.c @@ -0,0 +1,91 @@ +/* + * ProRes bitstream parser + * Copyright (c) 2023 clarkh + * + * 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 + */ + +#include "parser.h" +#include "libavutil/intreadwrite.h" + +static int prores_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +{ + int pic_found = pc->frame_start_found; + uint32_t state = pc->state; + int cur = 0; + + int flag = AV_RB32("icpf"); + if (!pic_found) { + for (; cur < buf_size; cur++) { + state = (state<<8) | buf[cur]; + if (state == flag){ + ++cur; + pic_found = 1; + break; + } + } + } + + if (pic_found) { + if (!buf_size) + return END_NOT_FOUND; + for (; cur < buf_size; ++cur) { + state = (state << 8) | buf[cur]; + if (state == flag) { + pc->frame_start_found = 0; + pc->state = -1; + return cur - 7; + } + } + } + + pc->frame_start_found = pic_found; + pc->state = state; + + return END_NOT_FOUND; +} + +static int prores_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { + next = buf_size; + } else { + next = prores_find_frame_end(pc, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; +} + +const AVCodecParser ff_prores_parser = { + .codec_ids = { AV_CODEC_ID_PRORES }, + .priv_data_size = sizeof(ParseContext), + .parser_parse = prores_parse, + .parser_close = ff_parse_close +}; diff --git a/libavformat/Makefile b/libavformat/Makefile index 4cb00f8700..a7f265252d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -639,6 +639,8 @@ OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o OBJS-$(CONFIG_YOP_DEMUXER) += yop.o OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpegdec.o OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpegenc.o +OBJS-$(CONFIG_PRORES_DEMUXER) += proresdec.o rawdec.o +OBJS-$(CONFIG_PRORES_MUXER) += rawenc.o # external library muxers/demuxers OBJS-$(CONFIG_AVISYNTH_DEMUXER) += avisynth.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 6324952bd2..89533eb686 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -520,6 +520,8 @@ extern const AVInputFormat ff_xwma_demuxer; extern const AVInputFormat ff_yop_demuxer; extern const AVInputFormat ff_yuv4mpegpipe_demuxer; extern const FFOutputFormat ff_yuv4mpegpipe_muxer; +extern const AVInputFormat ff_prores_demuxer; +extern const FFOutputFormat ff_prores_muxer; /* image demuxers */ extern const AVInputFormat ff_image_bmp_pipe_demuxer; extern const AVInputFormat ff_image_cri_pipe_demuxer; diff --git a/libavformat/proresdec.c b/libavformat/proresdec.c new file mode 100644 index 0000000000..11541f8cd3 --- /dev/null +++ b/libavformat/proresdec.c @@ -0,0 +1,62 @@ +/* + * ProRes bitstream demuxer + * Copyright (c) 2023 clarkh + * + * 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 + */ + +#include "libavutil/intreadwrite.h" +#include "avformat.h" +#include "rawdec.h" + +static int prores_check_frame_header(const uint8_t *buf, const int data_size) +{ + int hdr_size, width, height; + int version, alpha_info; + + hdr_size = AV_RB16(buf); + if (hdr_size < 20) + return AVERROR_INVALIDDATA; + + version = buf[3]; + if (version > 1) + return AVERROR_INVALIDDATA; + + width = AV_RB16(buf + 8); + height = AV_RB16(buf + 10); + if (!width || !height) + return AVERROR_INVALIDDATA; + + alpha_info = buf[17] & 0x0f; + if (alpha_info > 2) + return AVERROR_INVALIDDATA; + + return 0; +} + +static int prores_probe(const AVProbeData *p) +{ + if (p->buf_size < 28 || AV_RL32(p->buf + 4) != AV_RL32("icpf")) + return 0; + + if (prores_check_frame_header(p->buf + 8, p->buf_size - 8) < 0) + return 0; + + return AVPROBE_SCORE_MAX; +} + +FF_DEF_RAWVIDEO_DEMUXER(prores, "raw ProRes", prores_probe, NULL, AV_CODEC_ID_PRORES) diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c index f916db13a2..db7d88e782 100644 --- a/libavformat/rawenc.c +++ b/libavformat/rawenc.c @@ -588,3 +588,16 @@ const FFOutputFormat ff_vc1_muxer = { .p.flags = AVFMT_NOTIMESTAMPS, }; #endif + +#if CONFIG_PRORES_MUXER +const FFOutputFormat ff_prores_muxer = { + .p.name = "prores", + .p.long_name = NULL_IF_CONFIG_SMALL("raw prores video"), + .p.extensions = "prores", + .p.audio_codec = AV_CODEC_ID_NONE, + .p.video_codec = AV_CODEC_ID_PRORES, + .init = force_one_stream, + .write_packet = ff_raw_write_packet, + .p.flags = AVFMT_NOTIMESTAMPS, +}; +#endif