2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/log.h"
22 #include "libavutil/opt.h"
32 typedef struct RemoveExtradataContext {
36 AVCodecParserContext *parser;
37 AVCodecContext *avctx;
38 } RemoveExtradataContext;
40 static int remove_extradata(AVBSFContext *ctx, AVPacket *out)
42 RemoveExtradataContext *s = ctx->priv_data;
47 ret = ff_bsf_get_packet(ctx, &in);
51 if (s->parser && s->parser->parser->split) {
52 if (s->freq == REMOVE_FREQ_ALL ||
53 (s->freq == REMOVE_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) {
54 int i = s->parser->parser->split(s->avctx, in->data, in->size);
60 av_packet_move_ref(out, in);
66 static int remove_extradata_init(AVBSFContext *ctx)
68 RemoveExtradataContext *s = ctx->priv_data;
71 s->parser = av_parser_init(ctx->par_in->codec_id);
74 s->avctx = avcodec_alloc_context3(NULL);
76 return AVERROR(ENOMEM);
78 ret = avcodec_parameters_to_context(s->avctx, ctx->par_in);
86 static void remove_extradata_close(AVBSFContext *ctx)
88 RemoveExtradataContext *s = ctx->priv_data;
90 avcodec_free_context(&s->avctx);
91 av_parser_close(s->parser);
94 #define OFFSET(x) offsetof(RemoveExtradataContext, x)
95 static const AVOption options[] = {
96 { "freq", NULL, OFFSET(freq), AV_OPT_TYPE_INT, { .i64 = REMOVE_FREQ_KEYFRAME }, REMOVE_FREQ_KEYFRAME, REMOVE_FREQ_ALL, 0, "freq" },
97 { "keyframe", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = REMOVE_FREQ_KEYFRAME }, .unit = "freq" },
98 { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = REMOVE_FREQ_ALL }, .unit = "freq" },
102 static const AVClass remove_extradata_class = {
103 .class_name = "remove_extradata",
104 .item_name = av_default_item_name,
106 .version = LIBAVUTIL_VERSION_INT,
109 const AVBitStreamFilter ff_remove_extradata_bsf = {
110 .name = "remove_extra",
111 .priv_data_size = sizeof(RemoveExtradataContext),
112 .priv_class = &remove_extradata_class,
113 .init = remove_extradata_init,
114 .close = remove_extradata_close,
115 .filter = remove_extradata,