2016-08-21 17:08:34 +02:00
|
|
|
/*
|
2017-03-23 21:31:15 +02:00
|
|
|
* This file is part of FFmpeg.
|
2016-08-21 17:08:34 +02:00
|
|
|
*
|
2017-03-23 21:31:15 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2016-08-21 17:08:34 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2017-03-23 21:31:15 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2016-08-21 17:08:34 +02:00
|
|
|
* 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
|
2017-03-23 21:31:15 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2016-08-21 17:08:34 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "libavutil/log.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
2018-07-07 21:32:52 +02:00
|
|
|
#include "av1.h"
|
|
|
|
#include "av1_parse.h"
|
2020-04-07 16:41:48 +02:00
|
|
|
#include "bsf.h"
|
2020-04-07 16:49:28 +02:00
|
|
|
#include "bsf_internal.h"
|
2019-11-30 15:30:19 +02:00
|
|
|
#include "bytestream.h"
|
2016-08-21 17:08:34 +02:00
|
|
|
#include "h2645_parse.h"
|
|
|
|
#include "h264.h"
|
|
|
|
#include "hevc.h"
|
2022-02-04 16:43:14 +02:00
|
|
|
#include "startcode.h"
|
2016-08-21 17:08:34 +02:00
|
|
|
#include "vc1_common.h"
|
|
|
|
|
|
|
|
typedef struct ExtractExtradataContext {
|
|
|
|
const AVClass *class;
|
|
|
|
|
|
|
|
int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
|
|
|
|
uint8_t **data, int *size);
|
|
|
|
|
2019-11-06 09:00:59 +02:00
|
|
|
/* AV1 specific fields */
|
2018-07-07 21:32:52 +02:00
|
|
|
AV1Packet av1_pkt;
|
|
|
|
|
2019-11-06 09:00:59 +02:00
|
|
|
/* H264/HEVC specific fields */
|
2018-03-11 00:57:35 +02:00
|
|
|
H2645Packet h2645_pkt;
|
|
|
|
|
2016-08-21 17:08:34 +02:00
|
|
|
/* AVOptions */
|
|
|
|
int remove;
|
|
|
|
} ExtractExtradataContext;
|
|
|
|
|
|
|
|
static int val_in_array(const int *arr, int len, int val)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
if (arr[i] == val)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-07 21:32:52 +02:00
|
|
|
static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
|
|
|
|
uint8_t **data, int *size)
|
|
|
|
{
|
|
|
|
static const int extradata_obu_types[] = {
|
|
|
|
AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA,
|
|
|
|
};
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
|
|
|
|
|
|
|
int extradata_size = 0, filtered_size = 0;
|
|
|
|
int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
|
2018-07-21 01:43:40 +02:00
|
|
|
int i, has_seq = 0, ret = 0;
|
2018-07-07 21:32:52 +02:00
|
|
|
|
|
|
|
ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < s->av1_pkt.nb_obus; i++) {
|
|
|
|
AV1OBU *obu = &s->av1_pkt.obus[i];
|
|
|
|
if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) {
|
|
|
|
extradata_size += obu->raw_size;
|
2018-07-21 01:43:40 +02:00
|
|
|
if (obu->type == AV1_OBU_SEQUENCE_HEADER)
|
|
|
|
has_seq = 1;
|
2018-07-07 21:32:52 +02:00
|
|
|
} else if (s->remove) {
|
|
|
|
filtered_size += obu->raw_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 01:43:40 +02:00
|
|
|
if (extradata_size && has_seq) {
|
2019-11-30 08:38:10 +02:00
|
|
|
AVBufferRef *filtered_buf = NULL;
|
2019-11-30 15:30:19 +02:00
|
|
|
PutByteContext pb_filtered_data, pb_extradata;
|
|
|
|
uint8_t *extradata;
|
2018-07-07 21:32:52 +02:00
|
|
|
|
|
|
|
if (s->remove) {
|
|
|
|
filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!filtered_buf) {
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!extradata) {
|
|
|
|
av_buffer_unref(&filtered_buf);
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
*data = extradata;
|
|
|
|
*size = extradata_size;
|
|
|
|
|
2019-11-30 15:30:19 +02:00
|
|
|
bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
|
|
|
|
if (s->remove)
|
|
|
|
bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
|
|
|
|
|
2018-07-07 21:32:52 +02:00
|
|
|
for (i = 0; i < s->av1_pkt.nb_obus; i++) {
|
|
|
|
AV1OBU *obu = &s->av1_pkt.obus[i];
|
|
|
|
if (val_in_array(extradata_obu_types, nb_extradata_obu_types,
|
|
|
|
obu->type)) {
|
2019-11-30 15:30:19 +02:00
|
|
|
bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size);
|
2018-07-07 21:32:52 +02:00
|
|
|
} else if (s->remove) {
|
2019-11-30 15:30:19 +02:00
|
|
|
bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size);
|
2018-07-07 21:32:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->remove) {
|
|
|
|
av_buffer_unref(&pkt->buf);
|
|
|
|
pkt->buf = filtered_buf;
|
|
|
|
pkt->data = filtered_buf->data;
|
|
|
|
pkt->size = filtered_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-21 17:08:34 +02:00
|
|
|
static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
|
|
|
|
uint8_t **data, int *size)
|
|
|
|
{
|
|
|
|
static const int extradata_nal_types_hevc[] = {
|
|
|
|
HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,
|
|
|
|
};
|
|
|
|
static const int extradata_nal_types_h264[] = {
|
|
|
|
H264_NAL_SPS, H264_NAL_PPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
|
|
|
|
2018-03-09 19:31:30 +02:00
|
|
|
int extradata_size = 0, filtered_size = 0;
|
2016-08-21 17:08:34 +02:00
|
|
|
const int *extradata_nal_types;
|
|
|
|
int nb_extradata_nal_types;
|
2017-03-25 03:37:34 +02:00
|
|
|
int i, has_sps = 0, has_vps = 0, ret = 0;
|
2016-08-21 17:08:34 +02:00
|
|
|
|
|
|
|
if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
|
|
|
|
extradata_nal_types = extradata_nal_types_hevc;
|
|
|
|
nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc);
|
|
|
|
} else {
|
|
|
|
extradata_nal_types = extradata_nal_types_h264;
|
|
|
|
nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264);
|
|
|
|
}
|
|
|
|
|
2018-03-11 00:57:35 +02:00
|
|
|
ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
|
2018-11-28 02:24:09 +02:00
|
|
|
ctx, 0, 0, ctx->par_in->codec_id, 1, 0);
|
2016-08-21 17:08:34 +02:00
|
|
|
if (ret < 0)
|
2018-03-11 00:57:35 +02:00
|
|
|
return ret;
|
2016-08-21 17:08:34 +02:00
|
|
|
|
2018-03-11 00:57:35 +02:00
|
|
|
for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
|
|
|
|
H2645NAL *nal = &s->h2645_pkt.nals[i];
|
2017-03-25 03:37:34 +02:00
|
|
|
if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {
|
2016-08-21 17:08:34 +02:00
|
|
|
extradata_size += nal->raw_size + 3;
|
2017-03-25 03:37:34 +02:00
|
|
|
if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
|
|
|
|
if (nal->type == HEVC_NAL_SPS) has_sps = 1;
|
|
|
|
if (nal->type == HEVC_NAL_VPS) has_vps = 1;
|
|
|
|
} else {
|
|
|
|
if (nal->type == H264_NAL_SPS) has_sps = 1;
|
|
|
|
}
|
2018-03-09 19:31:30 +02:00
|
|
|
} else if (s->remove) {
|
|
|
|
filtered_size += nal->raw_size + 3;
|
2017-03-25 03:37:34 +02:00
|
|
|
}
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
|
2017-03-25 03:37:34 +02:00
|
|
|
if (extradata_size &&
|
|
|
|
((ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) ||
|
|
|
|
(ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) {
|
2019-11-30 08:38:10 +02:00
|
|
|
AVBufferRef *filtered_buf = NULL;
|
2019-11-30 15:30:19 +02:00
|
|
|
PutByteContext pb_filtered_data, pb_extradata;
|
|
|
|
uint8_t *extradata;
|
2016-08-21 17:08:34 +02:00
|
|
|
|
|
|
|
if (s->remove) {
|
2018-03-09 19:31:30 +02:00
|
|
|
filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2017-09-13 22:03:56 +02:00
|
|
|
if (!filtered_buf) {
|
2018-03-11 00:57:35 +02:00
|
|
|
return AVERROR(ENOMEM);
|
2017-09-13 22:03:56 +02:00
|
|
|
}
|
2018-03-09 19:31:30 +02:00
|
|
|
memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!extradata) {
|
|
|
|
av_buffer_unref(&filtered_buf);
|
2018-03-11 00:57:35 +02:00
|
|
|
return AVERROR(ENOMEM);
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*data = extradata;
|
|
|
|
*size = extradata_size;
|
|
|
|
|
2019-11-30 15:30:19 +02:00
|
|
|
bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
|
|
|
|
if (s->remove)
|
|
|
|
bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
|
|
|
|
|
2018-03-11 00:57:35 +02:00
|
|
|
for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
|
|
|
|
H2645NAL *nal = &s->h2645_pkt.nals[i];
|
2016-08-21 17:08:34 +02:00
|
|
|
if (val_in_array(extradata_nal_types, nb_extradata_nal_types,
|
|
|
|
nal->type)) {
|
2019-11-30 15:30:19 +02:00
|
|
|
bytestream2_put_be24u(&pb_extradata, 1); //startcode
|
|
|
|
bytestream2_put_bufferu(&pb_extradata, nal->raw_data, nal->raw_size);
|
2016-08-21 17:08:34 +02:00
|
|
|
} else if (s->remove) {
|
2019-11-30 15:30:19 +02:00
|
|
|
bytestream2_put_be24u(&pb_filtered_data, 1); // startcode
|
|
|
|
bytestream2_put_bufferu(&pb_filtered_data, nal->raw_data, nal->raw_size);
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->remove) {
|
|
|
|
av_buffer_unref(&pkt->buf);
|
|
|
|
pkt->buf = filtered_buf;
|
|
|
|
pkt->data = filtered_buf->data;
|
2018-03-09 19:31:30 +02:00
|
|
|
pkt->size = filtered_size;
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-11 00:57:35 +02:00
|
|
|
return 0;
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt,
|
|
|
|
uint8_t **data, int *size)
|
|
|
|
{
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
2017-03-24 23:26:03 +02:00
|
|
|
const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size;
|
2016-08-21 17:08:34 +02:00
|
|
|
uint32_t state = UINT32_MAX;
|
|
|
|
int has_extradata = 0, extradata_size = 0;
|
|
|
|
|
2017-03-24 23:26:03 +02:00
|
|
|
while (ptr < end) {
|
|
|
|
ptr = avpriv_find_start_code(ptr, end, &state);
|
|
|
|
if (state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT) {
|
|
|
|
has_extradata = 1;
|
2017-03-28 06:14:17 +02:00
|
|
|
} else if (has_extradata && IS_MARKER(state)) {
|
2017-03-24 23:26:03 +02:00
|
|
|
extradata_size = ptr - 4 - pkt->data;
|
2017-03-28 06:14:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-08-21 17:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (extradata_size) {
|
|
|
|
*data = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!*data)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
memcpy(*data, pkt->data, extradata_size);
|
|
|
|
*size = extradata_size;
|
|
|
|
|
|
|
|
if (s->remove) {
|
|
|
|
pkt->data += extradata_size;
|
|
|
|
pkt->size -= extradata_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-24 23:10:53 +02:00
|
|
|
static int extract_extradata_mpeg12(AVBSFContext *ctx, AVPacket *pkt,
|
2016-08-21 17:08:34 +02:00
|
|
|
uint8_t **data, int *size)
|
|
|
|
{
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
2017-03-24 23:10:53 +02:00
|
|
|
uint32_t state = UINT32_MAX;
|
|
|
|
int i, found = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < pkt->size; i++) {
|
|
|
|
state = (state << 8) | pkt->data[i];
|
|
|
|
if (state == 0x1B3)
|
|
|
|
found = 1;
|
|
|
|
else if (found && state != 0x1B5 && state < 0x200 && state >= 0x100) {
|
2020-09-07 15:01:23 +02:00
|
|
|
*size = i - 3;
|
|
|
|
*data = av_malloc(*size + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!*data)
|
|
|
|
return AVERROR(ENOMEM);
|
2017-03-24 23:10:53 +02:00
|
|
|
|
2020-09-07 15:01:23 +02:00
|
|
|
memcpy(*data, pkt->data, *size);
|
2017-03-24 23:10:53 +02:00
|
|
|
|
2020-09-07 15:01:23 +02:00
|
|
|
if (s->remove) {
|
|
|
|
pkt->data += *size;
|
|
|
|
pkt->size -= *size;
|
|
|
|
}
|
2017-03-24 23:10:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt,
|
|
|
|
uint8_t **data, int *size)
|
|
|
|
{
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
2017-03-24 23:27:37 +02:00
|
|
|
const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size;
|
2016-08-21 17:08:34 +02:00
|
|
|
uint32_t state = UINT32_MAX;
|
|
|
|
|
2017-03-24 23:27:37 +02:00
|
|
|
while (ptr < end) {
|
|
|
|
ptr = avpriv_find_start_code(ptr, end, &state);
|
|
|
|
if (state == 0x1B3 || state == 0x1B6) {
|
|
|
|
if (ptr - pkt->data > 4) {
|
|
|
|
*size = ptr - 4 - pkt->data;
|
2016-08-21 17:08:34 +02:00
|
|
|
*data = av_malloc(*size + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!*data)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
memcpy(*data, pkt->data, *size);
|
|
|
|
|
|
|
|
if (s->remove) {
|
|
|
|
pkt->data += *size;
|
|
|
|
pkt->size -= *size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
enum AVCodecID id;
|
|
|
|
int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
|
|
|
|
uint8_t **data, int *size);
|
|
|
|
} extract_tab[] = {
|
2018-07-07 21:32:52 +02:00
|
|
|
{ AV_CODEC_ID_AV1, extract_extradata_av1 },
|
2018-08-06 15:42:51 +02:00
|
|
|
{ AV_CODEC_ID_AVS2, extract_extradata_mpeg4 },
|
2021-08-24 13:10:19 +02:00
|
|
|
{ AV_CODEC_ID_AVS3, extract_extradata_mpeg4 },
|
2017-03-24 23:10:53 +02:00
|
|
|
{ AV_CODEC_ID_CAVS, extract_extradata_mpeg4 },
|
2016-08-21 17:08:34 +02:00
|
|
|
{ AV_CODEC_ID_H264, extract_extradata_h2645 },
|
|
|
|
{ AV_CODEC_ID_HEVC, extract_extradata_h2645 },
|
2017-03-24 23:10:53 +02:00
|
|
|
{ AV_CODEC_ID_MPEG1VIDEO, extract_extradata_mpeg12 },
|
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO, extract_extradata_mpeg12 },
|
|
|
|
{ AV_CODEC_ID_MPEG4, extract_extradata_mpeg4 },
|
2016-08-21 17:08:34 +02:00
|
|
|
{ AV_CODEC_ID_VC1, extract_extradata_vc1 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int extract_extradata_init(AVBSFContext *ctx)
|
|
|
|
{
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(extract_tab); i++) {
|
|
|
|
if (extract_tab[i].id == ctx->par_in->codec_id) {
|
|
|
|
s->extract = extract_tab[i].extract;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!s->extract)
|
|
|
|
return AVERROR_BUG;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:45:05 +02:00
|
|
|
static int extract_extradata_filter(AVBSFContext *ctx, AVPacket *pkt)
|
2016-08-21 17:08:34 +02:00
|
|
|
{
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
|
|
|
uint8_t *extradata = NULL;
|
|
|
|
int extradata_size;
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-03-11 18:45:05 +02:00
|
|
|
ret = ff_bsf_get_packet_ref(ctx, pkt);
|
2016-08-21 17:08:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2018-03-11 18:45:05 +02:00
|
|
|
ret = s->extract(ctx, pkt, &extradata, &extradata_size);
|
2016-08-21 17:08:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (extradata) {
|
2020-09-07 14:42:46 +02:00
|
|
|
memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
2018-03-11 18:45:05 +02:00
|
|
|
ret = av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
|
2016-08-21 17:08:34 +02:00
|
|
|
extradata, extradata_size);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_freep(&extradata);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:45:05 +02:00
|
|
|
return 0;
|
2016-08-21 17:08:34 +02:00
|
|
|
|
|
|
|
fail:
|
2018-03-11 18:45:05 +02:00
|
|
|
av_packet_unref(pkt);
|
2016-08-21 17:08:34 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-11 00:57:35 +02:00
|
|
|
static void extract_extradata_close(AVBSFContext *ctx)
|
|
|
|
{
|
|
|
|
ExtractExtradataContext *s = ctx->priv_data;
|
2018-07-07 21:32:52 +02:00
|
|
|
ff_av1_packet_uninit(&s->av1_pkt);
|
2018-03-11 00:57:35 +02:00
|
|
|
ff_h2645_packet_uninit(&s->h2645_pkt);
|
|
|
|
}
|
|
|
|
|
2016-08-21 17:08:34 +02:00
|
|
|
static const enum AVCodecID codec_ids[] = {
|
2018-07-07 21:32:52 +02:00
|
|
|
AV_CODEC_ID_AV1,
|
2018-08-06 15:42:51 +02:00
|
|
|
AV_CODEC_ID_AVS2,
|
2021-08-24 13:10:19 +02:00
|
|
|
AV_CODEC_ID_AVS3,
|
2016-08-21 17:08:34 +02:00
|
|
|
AV_CODEC_ID_CAVS,
|
|
|
|
AV_CODEC_ID_H264,
|
|
|
|
AV_CODEC_ID_HEVC,
|
|
|
|
AV_CODEC_ID_MPEG1VIDEO,
|
|
|
|
AV_CODEC_ID_MPEG2VIDEO,
|
|
|
|
AV_CODEC_ID_MPEG4,
|
|
|
|
AV_CODEC_ID_VC1,
|
|
|
|
AV_CODEC_ID_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(ExtractExtradataContext, x)
|
2018-03-08 08:05:53 +02:00
|
|
|
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
|
2016-08-21 17:08:34 +02:00
|
|
|
static const AVOption options[] = {
|
|
|
|
{ "remove", "remove the extradata from the bitstream", OFFSET(remove), AV_OPT_TYPE_INT,
|
2018-03-08 08:05:53 +02:00
|
|
|
{ .i64 = 0 }, 0, 1, FLAGS },
|
2016-08-21 17:08:34 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass extract_extradata_class = {
|
|
|
|
.class_name = "extract_extradata",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
|
|
|
};
|
|
|
|
|
|
|
|
const AVBitStreamFilter ff_extract_extradata_bsf = {
|
|
|
|
.name = "extract_extradata",
|
|
|
|
.codec_ids = codec_ids,
|
|
|
|
.priv_data_size = sizeof(ExtractExtradataContext),
|
|
|
|
.priv_class = &extract_extradata_class,
|
|
|
|
.init = extract_extradata_init,
|
|
|
|
.filter = extract_extradata_filter,
|
2018-03-11 00:57:35 +02:00
|
|
|
.close = extract_extradata_close,
|
2016-08-21 17:08:34 +02:00
|
|
|
};
|