You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec: add an APV parser
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@ -14,6 +14,7 @@ version <next>:
|
|||||||
- CENC AV1 support in MP4 muxer
|
- CENC AV1 support in MP4 muxer
|
||||||
- pngenc: set default prediction method to PAETH
|
- pngenc: set default prediction method to PAETH
|
||||||
- APV decoder and APV raw bitstream muxing and demuxing
|
- APV decoder and APV raw bitstream muxing and demuxing
|
||||||
|
- APV parser
|
||||||
|
|
||||||
|
|
||||||
version 7.1:
|
version 7.1:
|
||||||
|
1
configure
vendored
1
configure
vendored
@ -3483,6 +3483,7 @@ vvc_qsv_decoder_select="vvc_mp4toannexb_bsf qsvdec"
|
|||||||
|
|
||||||
# parsers
|
# parsers
|
||||||
aac_parser_select="adts_header mpeg4audio"
|
aac_parser_select="adts_header mpeg4audio"
|
||||||
|
apv_parser_select="cbs_apv"
|
||||||
av1_parser_select="cbs_av1"
|
av1_parser_select="cbs_av1"
|
||||||
evc_parser_select="evcparse"
|
evc_parser_select="evcparse"
|
||||||
ffv1_parser_select="rangecoder"
|
ffv1_parser_select="rangecoder"
|
||||||
|
@ -1198,6 +1198,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
|
|||||||
ac3_channel_layout_tab.o
|
ac3_channel_layout_tab.o
|
||||||
OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
|
OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
|
||||||
OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
|
OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
|
||||||
|
OBJS-$(CONFIG_APV_PARSER) += apv_parser.o
|
||||||
OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
|
OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
|
||||||
OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
|
OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
|
||||||
OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
|
OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
|
||||||
|
133
libavcodec/apv_parser.c
Normal file
133
libavcodec/apv_parser.c
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* 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 "apv.h"
|
||||||
|
#include "cbs.h"
|
||||||
|
#include "cbs_apv.h"
|
||||||
|
|
||||||
|
typedef struct APVParseContext {
|
||||||
|
CodedBitstreamContext *cbc;
|
||||||
|
CodedBitstreamFragment au;
|
||||||
|
} APVParseContext;
|
||||||
|
|
||||||
|
static const enum AVPixelFormat apv_format_table[5][5] = {
|
||||||
|
{ AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16 },
|
||||||
|
{ 0 }, // 4:2:0 is not valid.
|
||||||
|
{ AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV422P16 },
|
||||||
|
{ AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV444P16 },
|
||||||
|
{ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUVA444P16 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static int parse(AVCodecParserContext *s,
|
||||||
|
AVCodecContext *avctx,
|
||||||
|
const uint8_t **poutbuf, int *poutbuf_size,
|
||||||
|
const uint8_t *buf, int buf_size)
|
||||||
|
{
|
||||||
|
APVParseContext *p = s->priv_data;
|
||||||
|
CodedBitstreamFragment *au = &p->au;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
*poutbuf = buf;
|
||||||
|
*poutbuf_size = buf_size;
|
||||||
|
|
||||||
|
p->cbc->log_ctx = avctx;
|
||||||
|
|
||||||
|
ret = ff_cbs_read(p->cbc, au, buf, buf_size);
|
||||||
|
if (ret < 0) {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "Failed to parse access unit.\n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
s->key_frame = 1;
|
||||||
|
s->pict_type = AV_PICTURE_TYPE_I;
|
||||||
|
s->field_order = AV_FIELD_UNKNOWN;
|
||||||
|
s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
|
||||||
|
|
||||||
|
for (int i = 0; i < au->nb_units; i++) {
|
||||||
|
const CodedBitstreamUnit *pbu = &au->units[i];
|
||||||
|
|
||||||
|
switch (pbu->type) {
|
||||||
|
case APV_PBU_PRIMARY_FRAME: {
|
||||||
|
const APVRawFrame *frame = pbu->content;
|
||||||
|
const APVRawFrameHeader *header = &frame->frame_header;
|
||||||
|
const APVRawFrameInfo *info = &header->frame_info;
|
||||||
|
int bit_depth = info->bit_depth_minus8 + 8;
|
||||||
|
|
||||||
|
if (bit_depth < 8 || bit_depth > 16 || bit_depth % 2)
|
||||||
|
break;
|
||||||
|
|
||||||
|
s->width = info->frame_width;
|
||||||
|
s->height = info->frame_height;
|
||||||
|
s->format = apv_format_table[info->chroma_format_idc][bit_depth - 4 >> 2];
|
||||||
|
avctx->profile = info->profile_idc;
|
||||||
|
avctx->level = info->level_idc;
|
||||||
|
avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
|
||||||
|
avctx->color_primaries = header->color_primaries;
|
||||||
|
avctx->color_trc = header->transfer_characteristics;
|
||||||
|
avctx->colorspace = header->matrix_coefficients;
|
||||||
|
avctx->color_range = header->full_range_flag ? AVCOL_RANGE_JPEG
|
||||||
|
: AVCOL_RANGE_MPEG;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
ff_cbs_fragment_reset(au);
|
||||||
|
p->cbc->log_ctx = NULL;
|
||||||
|
|
||||||
|
return buf_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const CodedBitstreamUnitType decompose_unit_types[] = {
|
||||||
|
APV_PBU_PRIMARY_FRAME,
|
||||||
|
};
|
||||||
|
|
||||||
|
static av_cold int init(AVCodecParserContext *s)
|
||||||
|
{
|
||||||
|
APVParseContext *p = s->priv_data;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ff_cbs_init(&p->cbc, AV_CODEC_ID_APV, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
p->cbc->decompose_unit_types = decompose_unit_types;
|
||||||
|
p->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void close(AVCodecParserContext *s)
|
||||||
|
{
|
||||||
|
APVParseContext *p = s->priv_data;
|
||||||
|
|
||||||
|
ff_cbs_fragment_free(&p->au);
|
||||||
|
ff_cbs_close(&p->cbc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const AVCodecParser ff_apv_parser = {
|
||||||
|
.codec_ids = { AV_CODEC_ID_APV },
|
||||||
|
.priv_data_size = sizeof(APVParseContext),
|
||||||
|
.parser_init = init,
|
||||||
|
.parser_parse = parse,
|
||||||
|
.parser_close = close,
|
||||||
|
};
|
@ -25,6 +25,7 @@ extern const AVCodecParser ff_aac_latm_parser;
|
|||||||
extern const AVCodecParser ff_ac3_parser;
|
extern const AVCodecParser ff_ac3_parser;
|
||||||
extern const AVCodecParser ff_adx_parser;
|
extern const AVCodecParser ff_adx_parser;
|
||||||
extern const AVCodecParser ff_amr_parser;
|
extern const AVCodecParser ff_amr_parser;
|
||||||
|
extern const AVCodecParser ff_apv_parser;
|
||||||
extern const AVCodecParser ff_av1_parser;
|
extern const AVCodecParser ff_av1_parser;
|
||||||
extern const AVCodecParser ff_avs2_parser;
|
extern const AVCodecParser ff_avs2_parser;
|
||||||
extern const AVCodecParser ff_avs3_parser;
|
extern const AVCodecParser ff_avs3_parser;
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
#include "version_major.h"
|
#include "version_major.h"
|
||||||
|
|
||||||
#define LIBAVCODEC_VERSION_MINOR 1
|
#define LIBAVCODEC_VERSION_MINOR 2
|
||||||
#define LIBAVCODEC_VERSION_MICRO 102
|
#define LIBAVCODEC_VERSION_MICRO 100
|
||||||
|
|
||||||
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
||||||
LIBAVCODEC_VERSION_MINOR, \
|
LIBAVCODEC_VERSION_MINOR, \
|
||||||
|
Reference in New Issue
Block a user