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 790124BD19 for ; Mon, 3 Feb 2025 02:16:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3877B68C1EC; Mon, 3 Feb 2025 04:16:37 +0200 (EET) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0541368A412 for ; Mon, 3 Feb 2025 04:16:29 +0200 (EET) Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2ee76befe58so6735828a91.2 for ; Sun, 02 Feb 2025 18:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738548986; x=1739153786; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+e7FggmY9SE9sPyyl7wHI/fsBgjgvZoEQI/lZjIgq+Q=; b=MsmTYDNboW6/BRFcVhULRKiZ3LuOhRcL0kpPFCAvo25hdszccNLyWgNhC8zIrpm7rg K2FNqpV6kq0znvzAopP5mgLUmnpgycDS5uVEno2mZe7JfjgdgstdNAtoBNpPnAapC9dK mB3NMvZkUkRPxf5TohIFWadrKR9Tg2CeYNYTSG0ym+1N8hqnIHhRBKyZvXlIHs9G3OYP Tafod8J5sXIBxQZJE/JtW6TjyojJunCYxUSfHDPeZ+7/vG2hlh+azTCGjOYgvwGp0wTS umyaiXdieIhRNXtHshvGqBfCB+sVtJpRsixRWU9IYLywK2H87Y7mVkt6gBOfrtHxdnjG 8aRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738548986; x=1739153786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+e7FggmY9SE9sPyyl7wHI/fsBgjgvZoEQI/lZjIgq+Q=; b=ZFJ6WOzpf2ujvdKT77IgJ+oeu0NZR6wqE+shHUwScAk5y8IoxgDTxjdErwfBxumYVe rGMvxjsztWzO8DRCxgDR/znC0FFzMR8JLU1W15IDLXOpFEBfK8iz3vp7TZaBj4X4DwWt BkfRwayBKypEEaEwAItEN1mhKA/PCsEPNUgdOFpECGQJhgwljysGgCntcfaZFeFO4KAp n/M2t8+UdZPrSDfFUeK0l9VKqXYYZBeU7Rrt1HCZP/ajv1/R32BmWe0T8JSb//64V87+ 3NmZ+W7siwiP1PQycPILwC5LzOq6GuFU+YDcfQjRMb8k8doniVdA81XRdiQQBAhKEsDX Kq4A== X-Gm-Message-State: AOJu0YyBKFv43p5rpYz1V+XAqy7FcMBqwuPOzW04hTpi54lYXRBFU6co qrXeu1SC7ddoFl+8HE+fxbsJuXsPpppKofS8eRvXcuvsOB4wug0pBf/+JTw8 X-Gm-Gg: ASbGncukSNwsXsbO7RYmK7kcIptgpdgfIYebT+xUMBLEQgwry9t0cfqU7e5g0dZFH2Q qd9v2qWX0gntqfymyNU+v/GeIVfLKOFeiruQfOfoc8GMrNIpI1PS/x+3YCBD91vs1NKnXdrtITN jo92f6NWpgyl75DXPPiiFbySD9qgq4dHljwLDRZaUtJNDfJE5e7aouJqHng676ErqYeQoeSVPfF 5vht5/5ez1EsLX+9w/5R000J7sFDL5Nmkjq4G/vIn4QMtj4BMW88hEiMpMn5zbiUKpUVoncWfyw ZGEEEv9E3aYGnP5aZFsG6CWUk4x2D5G2 X-Google-Smtp-Source: AGHT+IGDtRWvvj6MAYAcK5g1GgtnayGDt/62Tor0smDlDHOeP4L4UIOjd+7FzRqKiAR6wXjSvOe2Nw== X-Received: by 2002:a05:6a00:2406:b0:72d:56d6:a7a7 with SMTP id d2e1a72fcca58-72fd0c5b253mr29184653b3a.15.1738548985908; Sun, 02 Feb 2025 18:16:25 -0800 (PST) Received: from localhost.localdomain ([2800:2121:b040:c:511c:7b61:5388:930d]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72fe69cec0fsm7340139b3a.137.2025.02.02.18.16.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2025 18:16:25 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Feb 2025 23:16:03 -0300 Message-ID: <20250203021603.6413-2-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250203021603.6413-1-jamrial@gmail.com> References: <20250203021603.6413-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] avcodec: add a ffv1 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 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: Only setting frame and stream properties. No packetization is performed. Signed-off-by: James Almer --- configure | 1 + libavcodec/Makefile | 1 + libavcodec/ffv1_parser.c | 86 ++++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 4 files changed, 89 insertions(+) create mode 100644 libavcodec/ffv1_parser.c diff --git a/configure b/configure index 06f641ead0..f09faaf505 100755 --- a/configure +++ b/configure @@ -3469,6 +3469,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec" aac_parser_select="adts_header mpeg4audio" av1_parser_select="cbs_av1" evc_parser_select="evcparse" +ffv1_parser_select="rangecoder" ftr_parser_select="adts_header mpeg4audio" h264_parser_select="golomb h264dsp h264parse h264_sei" hevc_parser_select="hevcparse hevc_sei" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 44bb34182a..973e2c45d6 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1207,6 +1207,7 @@ OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o OBJS-$(CONFIG_DVD_NAV_PARSER) += dvd_nav_parser.o OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o OBJS-$(CONFIG_EVC_PARSER) += evc_parser.o +OBJS-$(CONFIG_FFV1_PARSER) += ffv1_parser.o ffv1_parse.o ffv1.o OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o OBJS-$(CONFIG_FTR_PARSER) += ftr_parser.o OBJS-$(CONFIG_G723_1_PARSER) += g723_1_parser.o diff --git a/libavcodec/ffv1_parser.c b/libavcodec/ffv1_parser.c new file mode 100644 index 0000000000..d0b396b693 --- /dev/null +++ b/libavcodec/ffv1_parser.c @@ -0,0 +1,86 @@ +/* + * 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 "avcodec.h" +#include "ffv1.h" +#include "rangecoder.h" + +typedef struct FFV1ParseContext { + FFV1Context f; + int got_first; +} FFV1ParseContext; + +static int parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + FFV1ParseContext *p = s->priv_data; + FFV1Context *f = &p->f; + RangeCoder c; + uint8_t keystate = 128; + + *poutbuf = buf; + *poutbuf_size = buf_size; + + if (!p->got_first) { + int ret = ff_ffv1_common_init(avctx, f); + p->got_first = 1; + if (ret < 0) + return buf_size; + + if (avctx->extradata_size > 0 && (ret = ff_ffv1_read_extra_header(f)) < 0) + return buf_size; + } + + ff_init_range_decoder(&c, buf, buf_size); + ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); + + f->avctx = avctx; + s->key_frame = get_rac(&c, &keystate); + s->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P, see ffv1dec.c + s->field_order = AV_FIELD_UNKNOWN; + s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; + + if (s->key_frame) { + uint8_t state[CONTEXT_SIZE]; + memset(state, 128, sizeof(state)); + ff_ffv1_parse_header(f, &c, state); + } + + s->width = f->width; + s->height = f->height; + s->format = f->pix_fmt; + + return buf_size; +} + +static void close(AVCodecParserContext *s) +{ + FFV1ParseContext *p = s->priv_data; + + p->f.avctx = NULL; + ff_ffv1_close(&p->f); +} + +const AVCodecParser ff_ffv1_parser = { + .codec_ids = { AV_CODEC_ID_FFV1 }, + .priv_data_size = sizeof(FFV1ParseContext), + .parser_parse = parse, + .parser_close = close, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 8bfd2dbce0..5387351fd0 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -45,6 +45,7 @@ extern const AVCodecParser ff_dvd_nav_parser; extern const AVCodecParser ff_evc_parser; extern const AVCodecParser ff_flac_parser; extern const AVCodecParser ff_ftr_parser; +extern const AVCodecParser ff_ffv1_parser; extern const AVCodecParser ff_g723_1_parser; extern const AVCodecParser ff_g729_parser; extern const AVCodecParser ff_gif_parser; -- 2.48.1 _______________________________________________ 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".