Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/avconv.c b/avconv.c
- index a058b1d..3a2e21d 100644
- --- a/avconv.c
- +++ b/avconv.c
- @@ -175,16 +175,16 @@ static void avconv_cleanup(int ret)
- }
- for (i = 0; i < nb_output_streams; i++) {
- OutputStream *ost = output_streams[i];
- - AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
- - while (bsfc) {
- - AVBitStreamFilterContext *next = bsfc->next;
- - av_bitstream_filter_close(bsfc);
- - bsfc = next;
- - }
- - ost->bitstream_filters = NULL;
- +
- + for (j = 0; j < ost->nb_bitstream_filters; j++)
- + av_bsf_free(&ost->bsf_ctx[j]);
- + av_freep(&ost->bsf_ctx);
- + av_freep(&ost->bitstream_filters);
- +
- av_frame_free(&ost->filtered_frame);
- av_parser_close(ost->parser);
- + avcodec_free_context(&ost->parser_avctx);
- av_freep(&ost->forced_keyframes);
- av_freep(&ost->avfilter);
- @@ -255,10 +255,9 @@ static void abort_codec_experimental(AVCodec *c, int encoder)
- exit_program(1);
- }
- -static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- +static void write_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- {
- - AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
- - AVCodecContext *avctx = ost->encoding_needed ? ost->enc_ctx : ost->st->codec;
- + AVStream *st = ost->st;
- int ret;
- /*
- @@ -268,14 +267,14 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- * Counting encoded video frames needs to be done separately because of
- * reordering, see do_video_out()
- */
- - if (!(avctx->codec_type == AVMEDIA_TYPE_VIDEO && avctx->codec)) {
- + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) {
- if (ost->frame_number >= ost->max_frames) {
- av_packet_unref(pkt);
- return;
- }
- ost->frame_number++;
- }
- - if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
- + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
- uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,
- NULL);
- ost->quality = sd ? *(int *)sd : -1;
- @@ -286,31 +285,6 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- }
- }
- - while (bsfc) {
- - AVPacket new_pkt = *pkt;
- - int a = av_bitstream_filter_filter(bsfc, avctx, NULL,
- - &new_pkt.data, &new_pkt.size,
- - pkt->data, pkt->size,
- - pkt->flags & AV_PKT_FLAG_KEY);
- - if (a > 0) {
- - av_packet_unref(pkt);
- - new_pkt.buf = av_buffer_create(new_pkt.data, new_pkt.size,
- - av_buffer_default_free, NULL, 0);
- - if (!new_pkt.buf)
- - exit_program(1);
- - } else if (a < 0) {
- - av_log(NULL, AV_LOG_ERROR, "%s failed for stream %d, codec %s",
- - bsfc->filter->name, pkt->stream_index,
- - avctx->codec ? avctx->codec->name : "copy");
- - print_error("", a);
- - if (exit_on_error)
- - exit_program(1);
- - }
- - *pkt = new_pkt;
- -
- - bsfc = bsfc->next;
- - }
- -
- if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
- ost->last_mux_dts != AV_NOPTS_VALUE &&
- pkt->dts < ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT)) {
- @@ -341,6 +315,49 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- }
- }
- +static void output_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
- +{
- + int ret = 0;
- +
- + /* apply the output bitstream filters, if any */
- + if (ost->nb_bitstream_filters) {
- + int idx;
- +
- + ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);
- + if (ret < 0)
- + goto finish;
- +
- + idx = 1;
- + while (idx) {
- + /* get a packet from the previous filter up the chain */
- + ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);
- + if (ret == AVERROR(EAGAIN)) {
- + ret = 0;
- + idx--;
- + continue;
- + } else if (ret < 0)
- + goto finish;
- +
- + /* send it to the next filter down the chain or to the muxer */
- + if (idx < ost->nb_bitstream_filters) {
- + ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);
- + if (ret < 0)
- + goto finish;
- + idx++;
- + } else
- + write_packet(s, pkt, ost);
- + }
- + } else
- + write_packet(s, pkt, ost);
- +
- +finish:
- + if (ret < 0 && ret != AVERROR_EOF) {
- + av_log(NULL, AV_LOG_FATAL, "Error applying bitstream filters to an output "
- + "packet for stream #%d:%d.\n", ost->file_index, ost->index);
- + exit_program(1);
- + }
- +}
- +
- static int check_recording_time(OutputStream *ost)
- {
- OutputFile *of = output_files[ost->file_index];
- @@ -379,7 +396,7 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
- if (got_packet) {
- av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
- - write_frame(s, &pkt, ost);
- + output_packet(s, &pkt, ost);
- }
- }
- @@ -448,7 +465,7 @@ static void do_subtitle_out(AVFormatContext *s,
- else
- pkt.pts += 90 * sub->end_display_time;
- }
- - write_frame(s, &pkt, ost);
- + output_packet(s, &pkt, ost);
- }
- }
- @@ -515,7 +532,7 @@ static void do_video_out(AVFormatContext *s,
- if (got_packet) {
- av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
- - write_frame(s, &pkt, ost);
- + output_packet(s, &pkt, ost);
- *frame_size = pkt.size;
- /* if two pass, output log */
- @@ -982,7 +999,7 @@ static void flush_encoders(void)
- break;
- }
- av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
- - write_frame(os, &pkt, ost);
- + output_packet(os, &pkt, ost);
- }
- if (stop_encoding)
- @@ -1062,7 +1079,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
- && ost->enc_ctx->codec_id != AV_CODEC_ID_MPEG2VIDEO
- && ost->enc_ctx->codec_id != AV_CODEC_ID_VC1
- ) {
- - if (av_parser_change(ost->parser, ost->st->codec,
- + if (av_parser_change(ost->parser, ost->parser_avctx,
- &opkt.data, &opkt.size,
- pkt->data, pkt->size,
- pkt->flags & AV_PKT_FLAG_KEY)) {
- @@ -1075,7 +1092,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
- opkt.size = pkt->size;
- }
- - write_frame(of->ctx, &opkt, ost);
- + output_packet(of->ctx, &opkt, ost);
- }
- int guess_input_channel_layout(InputStream *ist)
- @@ -1560,6 +1577,51 @@ static InputStream *get_input_stream(OutputStream *ost)
- return NULL;
- }
- +static int init_output_bsfs(OutputStream *ost)
- +{
- + AVBSFContext *ctx;
- + int i, ret;
- +
- + if (!ost->nb_bitstream_filters)
- + return 0;
- +
- + ost->bsf_ctx = av_mallocz_array(ost->nb_bitstream_filters, sizeof(*ost->bsf_ctx));
- + if (!ost->bsf_ctx)
- + return AVERROR(ENOMEM);
- +
- + for (i = 0; i < ost->nb_bitstream_filters; i++) {
- + ret = av_bsf_alloc(ost->bitstream_filters[i], &ctx);
- + if (ret < 0) {
- + av_log(NULL, AV_LOG_ERROR, "Error allocating a bistream filter context\n");
- + return ret;
- + }
- + ost->bsf_ctx[i] = ctx;
- +
- + ret = avcodec_parameters_copy(ctx->par_in,
- + i ? ost->bsf_ctx[i - 1]->par_out : ost->st->codecpar);
- + if (ret < 0)
- + return ret;
- +
- + ctx->time_base_in = i ? ost->bsf_ctx[i - 1]->time_base_out : ost->st->time_base;
- +
- + ret = av_bsf_init(ctx);
- + if (ret < 0) {
- + av_log(NULL, AV_LOG_ERROR, "Error initializing bistream filter: %s\n",
- + ost->bitstream_filters[i]->name);
- + return ret;
- + }
- + }
- +
- + ctx = ost->bsf_ctx[ost->nb_bitstream_filters - 1];
- + ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
- + if (ret < 0)
- + return ret;
- +
- + ost->st->time_base = ctx->time_base_out;
- +
- + return 0;
- +}
- +
- static int init_output_stream(OutputStream *ost, char *error, int error_len)
- {
- int ret = 0;
- @@ -1601,7 +1663,7 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
- av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
- "It takes bits/s as argument, not kbits/s\n");
- - ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);
- + ret = avcodec_parameters_from_context(ost->st->codecpar, ost->enc_ctx);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL,
- "Error initializing the output stream codec context.\n");
- @@ -1635,9 +1697,23 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
- ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);
- if (ret < 0)
- return ret;
- - ost->st->time_base = ost->st->codec->time_base;
- +
- + /*
- + * FIXME: will the codec context used by the parser during streamcopy
- + * This should go away with the new parser API.
- + */
- + ret = avcodec_parameters_to_context(ost->parser_avctx, ost->st->codecpar);
- + if (ret < 0)
- + return ret;
- }
- + /* initialize bitstream filters for the output stream
- + * needs to be done here, because the codec id for streamcopy is not
- + * known until now */
- + ret = init_output_bsfs(ost);
- + if (ret < 0)
- + return ret;
- +
- return ret;
- }
- @@ -1719,8 +1795,6 @@ static int transcode_init(void)
- /* for each output stream, we compute the right encoding parameters */
- for (i = 0; i < nb_output_streams; i++) {
- - AVCodecContext *enc_ctx;
- - AVCodecContext *dec_ctx = NULL;
- ost = output_streams[i];
- oc = output_files[ost->file_index]->ctx;
- ist = get_input_stream(ost);
- @@ -1728,56 +1802,46 @@ static int transcode_init(void)
- if (ost->attachment_filename)
- continue;
- - enc_ctx = ost->stream_copy ? ost->st->codec : ost->enc_ctx;
- -
- if (ist) {
- - dec_ctx = ist->dec_ctx;
- -
- ost->st->disposition = ist->st->disposition;
- - enc_ctx->bits_per_raw_sample = dec_ctx->bits_per_raw_sample;
- - enc_ctx->chroma_sample_location = dec_ctx->chroma_sample_location;
- }
- if (ost->stream_copy) {
- + AVCodecParameters *par_dst = ost->st->codecpar;
- + AVCodecParameters *par_src = ist->st->codecpar;
- AVRational sar;
- uint64_t extra_size;
- av_assert0(ist && !ost->filter);
- - extra_size = (uint64_t)dec_ctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE;
- + extra_size = (uint64_t)par_src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE;
- if (extra_size > INT_MAX) {
- return AVERROR(EINVAL);
- }
- /* if stream_copy is selected, no need to decode or encode */
- - enc_ctx->codec_id = dec_ctx->codec_id;
- - enc_ctx->codec_type = dec_ctx->codec_type;
- + par_dst->codec_id = par_src->codec_id;
- + par_dst->codec_type = par_src->codec_type;
- - if (!enc_ctx->codec_tag) {
- + if (!par_dst->codec_tag) {
- if (!oc->oformat->codec_tag ||
- - av_codec_get_id (oc->oformat->codec_tag, dec_ctx->codec_tag) == enc_ctx->codec_id ||
- - av_codec_get_tag(oc->oformat->codec_tag, dec_ctx->codec_id) <= 0)
- - enc_ctx->codec_tag = dec_ctx->codec_tag;
- + av_codec_get_id (oc->oformat->codec_tag, par_src->codec_tag) == par_dst->codec_id ||
- + av_codec_get_tag(oc->oformat->codec_tag, par_src->codec_id) <= 0)
- + par_dst->codec_tag = par_src->codec_tag;
- }
- - enc_ctx->bit_rate = dec_ctx->bit_rate;
- - enc_ctx->rc_max_rate = dec_ctx->rc_max_rate;
- - enc_ctx->rc_buffer_size = dec_ctx->rc_buffer_size;
- - enc_ctx->field_order = dec_ctx->field_order;
- - enc_ctx->extradata = av_mallocz(extra_size);
- - if (!enc_ctx->extradata) {
- + par_dst->bit_rate = par_src->bit_rate;
- + par_dst->field_order = par_src->field_order;
- + par_dst->chroma_location = par_src->chroma_location;
- + par_dst->extradata = av_mallocz(extra_size);
- + if (!par_dst->extradata) {
- return AVERROR(ENOMEM);
- }
- - memcpy(enc_ctx->extradata, dec_ctx->extradata, dec_ctx->extradata_size);
- - enc_ctx->extradata_size = dec_ctx->extradata_size;
- - if (!copy_tb) {
- - enc_ctx->time_base = dec_ctx->time_base;
- - enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
- - av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
- - enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
- - } else
- - enc_ctx->time_base = ist->st->time_base;
- + memcpy(par_dst->extradata, par_src->extradata, par_src->extradata_size);
- + par_dst->extradata_size = par_src->extradata_size;
- +
- + ost->st->time_base = ist->st->time_base;
- if (ist->st->nb_side_data) {
- ost->st->side_data = av_realloc_array(NULL, ist->st->nb_side_data,
- @@ -1799,37 +1863,37 @@ static int transcode_init(void)
- }
- }
- - ost->parser = av_parser_init(enc_ctx->codec_id);
- + ost->parser = av_parser_init(par_dst->codec_id);
- + ost->parser_avctx = avcodec_alloc_context3(NULL);
- + if (!ost->parser_avctx)
- + return AVERROR(ENOMEM);
- - switch (enc_ctx->codec_type) {
- + switch (par_dst->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- if (audio_volume != 256) {
- av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
- exit_program(1);
- }
- - enc_ctx->channel_layout = dec_ctx->channel_layout;
- - enc_ctx->sample_rate = dec_ctx->sample_rate;
- - enc_ctx->channels = dec_ctx->channels;
- - enc_ctx->frame_size = dec_ctx->frame_size;
- - enc_ctx->audio_service_type = dec_ctx->audio_service_type;
- - enc_ctx->block_align = dec_ctx->block_align;
- + par_dst->channel_layout = par_src->channel_layout;
- + par_dst->sample_rate = par_src->sample_rate;
- + par_dst->channels = par_src->channels;
- + par_dst->block_align = par_src->block_align;
- break;
- case AVMEDIA_TYPE_VIDEO:
- - enc_ctx->pix_fmt = dec_ctx->pix_fmt;
- - enc_ctx->width = dec_ctx->width;
- - enc_ctx->height = dec_ctx->height;
- - enc_ctx->has_b_frames = dec_ctx->has_b_frames;
- + par_dst->format = par_src->format;
- + par_dst->width = par_src->width;
- + par_dst->height = par_src->height;
- if (ost->frame_aspect_ratio)
- - sar = av_d2q(ost->frame_aspect_ratio * enc_ctx->height / enc_ctx->width, 255);
- + sar = av_d2q(ost->frame_aspect_ratio * par_dst->height / par_dst->width, 255);
- else if (ist->st->sample_aspect_ratio.num)
- sar = ist->st->sample_aspect_ratio;
- else
- - sar = dec_ctx->sample_aspect_ratio;
- - ost->st->sample_aspect_ratio = enc_ctx->sample_aspect_ratio = sar;
- + sar = par_src->sample_aspect_ratio;
- + ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
- break;
- case AVMEDIA_TYPE_SUBTITLE:
- - enc_ctx->width = dec_ctx->width;
- - enc_ctx->height = dec_ctx->height;
- + par_dst->width = par_src->width;
- + par_dst->height = par_src->height;
- break;
- case AVMEDIA_TYPE_DATA:
- case AVMEDIA_TYPE_ATTACHMENT:
- @@ -1838,6 +1902,9 @@ static int transcode_init(void)
- abort();
- }
- } else {
- + AVCodecContext *enc_ctx = ost->enc_ctx;
- + AVCodecContext *dec_ctx = NULL;
- +
- if (!ost->enc) {
- /* should only happen when a default codec is not present. */
- snprintf(error, sizeof(error), "Automatic encoder selection "
- @@ -1851,6 +1918,13 @@ static int transcode_init(void)
- set_encoder_id(output_files[ost->file_index], ost);
- + if (ist) {
- + dec_ctx = ist->dec_ctx;
- +
- + enc_ctx->bits_per_raw_sample = dec_ctx->bits_per_raw_sample;
- + enc_ctx->chroma_sample_location = dec_ctx->chroma_sample_location;
- + }
- +
- /*
- * We want CFR output if and only if one of those is true:
- * 1) user specified output framerate with -r
- diff --git a/avconv.h b/avconv.h
- index f0a948f..dc31f00 100644
- --- a/avconv.h
- +++ b/avconv.h
- @@ -326,7 +326,11 @@ typedef struct OutputStream {
- int64_t first_pts;
- /* dts of the last packet sent to the muxer */
- int64_t last_mux_dts;
- - AVBitStreamFilterContext *bitstream_filters;
- +
- + int nb_bitstream_filters;
- + const AVBitStreamFilter **bitstream_filters;
- + AVBSFContext **bsf_ctx;
- +
- AVCodecContext *enc_ctx;
- AVCodec *enc;
- int64_t max_frames;
- @@ -364,6 +368,7 @@ typedef struct OutputStream {
- enum AVPixelFormat pix_fmts[2];
- AVCodecParserContext *parser;
- + AVCodecContext *parser_avctx;
- /* stats */
- // combined size of all the packets written
- diff --git a/avconv_filter.c b/avconv_filter.c
- index aaf5851..3ecad56 100644
- --- a/avconv_filter.c
- +++ b/avconv_filter.c
- @@ -134,7 +134,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
- s = input_files[file_idx]->ctx;
- for (i = 0; i < s->nb_streams; i++) {
- - if (s->streams[i]->codec->codec_type != type)
- + if (s->streams[i]->codecpar->codec_type != type)
- continue;
- if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {
- st = s->streams[i];
- diff --git a/avconv_opt.c b/avconv_opt.c
- index 8fe53e6..ffba54f 100644
- --- a/avconv_opt.c
- +++ b/avconv_opt.c
- @@ -470,11 +470,11 @@ static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *
- MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
- if (codec_name) {
- - AVCodec *codec = find_codec_or_die(codec_name, st->codec->codec_type, 0);
- - st->codec->codec_id = codec->id;
- + AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
- + st->codecpar->codec_id = codec->id;
- return codec;
- } else
- - return avcodec_find_decoder(st->codec->codec_id);
- + return avcodec_find_decoder(st->codecpar->codec_id);
- }
- /* Add all the streams from the given input file to the global
- @@ -485,7 +485,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
- for (i = 0; i < ic->nb_streams; i++) {
- AVStream *st = ic->streams[i];
- - AVCodecContext *dec = st->codec;
- + AVCodecParameters *par = st->codecpar;
- InputStream *ist = av_mallocz(sizeof(*ist));
- char *framerate = NULL, *hwaccel = NULL, *hwaccel_device = NULL;
- char *codec_tag = NULL;
- @@ -516,11 +516,11 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
- uint32_t tag = strtol(codec_tag, &next, 0);
- if (*next)
- tag = AV_RL32(codec_tag);
- - st->codec->codec_tag = tag;
- + st->codecpar->codec_tag = tag;
- }
- ist->dec = choose_decoder(o, ic, st);
- - ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codec->codec_id, ic, st, ist->dec);
- + ist->decoder_opts = filter_codec_opts(o->g->codec_opts, par->codec_id, ic, st, ist->dec);
- ist->dec_ctx = avcodec_alloc_context3(ist->dec);
- if (!ist->dec_ctx) {
- @@ -528,13 +528,13 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
- exit_program(1);
- }
- - ret = avcodec_copy_context(ist->dec_ctx, dec);
- + ret = avcodec_parameters_to_context(ist->dec_ctx, par);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
- exit_program(1);
- }
- - switch (dec->codec_type) {
- + switch (par->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- ist->resample_height = ist->dec_ctx->height;
- ist->resample_width = ist->dec_ctx->width;
- @@ -637,7 +637,7 @@ static void dump_attachment(AVStream *st, const char *filename)
- AVIOContext *out = NULL;
- AVDictionaryEntry *e;
- - if (!st->codec->extradata_size) {
- + if (!st->codecpar->extradata_size) {
- av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
- nb_input_files - 1, st->index);
- return;
- @@ -658,7 +658,7 @@ static void dump_attachment(AVStream *st, const char *filename)
- exit_program(1);
- }
- - avio_write(out, st->codec->extradata, st->codec->extradata_size);
- + avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
- avio_flush(out);
- avio_close(out);
- }
- @@ -895,14 +895,14 @@ static void choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *
- MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
- if (!codec_name) {
- - ost->st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename,
- - NULL, ost->st->codec->codec_type);
- - ost->enc = avcodec_find_encoder(ost->st->codec->codec_id);
- + ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->filename,
- + NULL, ost->st->codecpar->codec_type);
- + ost->enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
- } else if (!strcmp(codec_name, "copy"))
- ost->stream_copy = 1;
- else {
- - ost->enc = find_codec_or_die(codec_name, ost->st->codec->codec_type, 1);
- - ost->st->codec->codec_id = ost->enc->id;
- + ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
- + ost->st->codecpar->codec_id = ost->enc->id;
- }
- }
- @@ -911,8 +911,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
- OutputStream *ost;
- AVStream *st = avformat_new_stream(oc, NULL);
- int idx = oc->nb_streams - 1, ret = 0;
- - char *bsf = NULL, *next, *codec_tag = NULL;
- - AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
- + const char *bsfs = NULL;
- + char *next, *codec_tag = NULL;
- double qscale = -1;
- if (!st) {
- @@ -931,7 +931,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
- ost->file_index = nb_output_files - 1;
- ost->index = idx;
- ost->st = st;
- - st->codec->codec_type = type;
- + st->codecpar->codec_type = type;
- choose_encoder(o, oc, ost);
- ost->enc_ctx = avcodec_alloc_context3(ost->enc);
- @@ -978,21 +978,31 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
- ost->max_frames = INT64_MAX;
- MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
- - MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
- - while (bsf) {
- - if (next = strchr(bsf, ','))
- - *next++ = 0;
- - if (!(bsfc = av_bitstream_filter_init(bsf))) {
- + MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
- + while (bsfs && *bsfs) {
- + const AVBitStreamFilter *filter;
- + char *bsf;
- +
- + bsf = av_get_token(&bsfs, ",");
- + if (!bsf)
- + exit_program(1);
- +
- + filter = av_bsf_get_by_name(bsf);
- + if (!filter) {
- av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
- exit_program(1);
- }
- - if (bsfc_prev)
- - bsfc_prev->next = bsfc;
- - else
- - ost->bitstream_filters = bsfc;
- + av_freep(&bsf);
- +
- + ost->bitstream_filters = av_realloc_array(ost->bitstream_filters,
- + ost->nb_bitstream_filters + 1,
- + sizeof(*ost->bitstream_filters));
- + if (!ost->bitstream_filters)
- + exit_program(1);
- - bsfc_prev = bsfc;
- - bsf = next;
- + ost->bitstream_filters[ost->nb_bitstream_filters++] = filter;
- + if (*bsfs)
- + bsfs++;
- }
- MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
- @@ -1088,7 +1098,7 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
- else if (filter)
- return av_strdup(filter);
- - return av_strdup(st->codec->codec_type == AVMEDIA_TYPE_VIDEO ?
- + return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
- "null" : "anull");
- }
- @@ -1524,9 +1534,9 @@ static int open_output_file(OptionsContext *o, const char *filename)
- int area = 0, idx = -1;
- for (i = 0; i < nb_input_streams; i++) {
- ist = input_streams[i];
- - if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
- - ist->st->codec->width * ist->st->codec->height > area) {
- - area = ist->st->codec->width * ist->st->codec->height;
- + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
- + ist->st->codecpar->width * ist->st->codecpar->height > area) {
- + area = ist->st->codecpar->width * ist->st->codecpar->height;
- idx = i;
- }
- }
- @@ -1538,9 +1548,9 @@ static int open_output_file(OptionsContext *o, const char *filename)
- int channels = 0, idx = -1;
- for (i = 0; i < nb_input_streams; i++) {
- ist = input_streams[i];
- - if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
- - ist->st->codec->channels > channels) {
- - channels = ist->st->codec->channels;
- + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
- + ist->st->codecpar->channels > channels) {
- + channels = ist->st->codecpar->channels;
- idx = i;
- }
- }
- @@ -1550,7 +1560,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
- /* subtitles: pick first */
- if (!o->subtitle_disable && oc->oformat->subtitle_codec != AV_CODEC_ID_NONE) {
- for (i = 0; i < nb_input_streams; i++)
- - if (input_streams[i]->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
- + if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
- NEW_STREAM(subtitle, i);
- break;
- }
- @@ -1587,7 +1597,7 @@ loop_end:
- init_output_filter(ofilter, o, oc);
- } else {
- ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
- - switch (ist->st->codec->codec_type) {
- + switch (ist->st->codecpar->codec_type) {
- case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;
- case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
- case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
- @@ -1636,8 +1646,8 @@ loop_end:
- ost->stream_copy = 0;
- ost->source_index = -1;
- ost->attachment_filename = o->attachments[i];
- - ost->st->codec->extradata = attachment;
- - ost->st->codec->extradata_size = len;
- + ost->st->codecpar->extradata = attachment;
- + ost->st->codecpar->extradata_size = len;
- p = strrchr(o->attachments[i], '/');
- av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
- @@ -1838,11 +1848,10 @@ static int opt_target(void *optctx, const char *opt, const char *arg)
- int i, j, fr;
- for (j = 0; j < nb_input_files; j++) {
- for (i = 0; i < input_files[j]->nb_streams; i++) {
- - AVCodecContext *c = input_files[j]->ctx->streams[i]->codec;
- - if (c->codec_type != AVMEDIA_TYPE_VIDEO ||
- - !c->time_base.num)
- + AVStream *st = input_files[j]->ctx->streams[i];
- + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
- continue;
- - fr = c->time_base.den * 1000 / c->time_base.num;
- + fr = st->time_base.den * 1000 / st->time_base.num;
- if (fr == 25000) {
- norm = PAL;
- break;
- diff --git a/cmdutils.c b/cmdutils.c
- index e4bd74f..b3c4b62 100644
- --- a/cmdutils.c
- +++ b/cmdutils.c
- @@ -1173,10 +1173,11 @@ int show_encoders(void *optctx, const char *opt, const char *arg)
- int show_bsfs(void *optctx, const char *opt, const char *arg)
- {
- - AVBitStreamFilter *bsf = NULL;
- + const AVBitStreamFilter *bsf = NULL;
- + void *opaque = NULL;
- printf("Bitstream filters:\n");
- - while ((bsf = av_bitstream_filter_next(bsf)))
- + while ((bsf = av_bsf_next(&opaque)))
- printf("%s\n", bsf->name);
- printf("\n");
- return 0;
- @@ -1504,12 +1505,12 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
- case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
- default: av_assert0(0);
- }
- - if (type != st->codec->codec_type)
- + if (type != st->codecpar->codec_type)
- return 0;
- if (*spec++ == ':') { /* possibly followed by :index */
- int i, index = strtol(spec, NULL, 0);
- for (i = 0; i < s->nb_streams; i++)
- - if (s->streams[i]->codec->codec_type == type && index-- == 0)
- + if (s->streams[i]->codecpar->codec_type == type && index-- == 0)
- return i == st->index;
- return 0;
- }
- @@ -1565,17 +1566,17 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
- av_freep(&key);
- return ret;
- } else if (*spec == 'u') {
- - AVCodecContext *avctx = st->codec;
- + AVCodecParameters *par = st->codecpar;
- int val;
- - switch (avctx->codec_type) {
- + switch (par->codec_type) {
- case AVMEDIA_TYPE_AUDIO:
- - val = avctx->sample_rate && avctx->channels;
- - if (avctx->sample_fmt == AV_SAMPLE_FMT_NONE)
- + val = par->sample_rate && par->channels;
- + if (par->format == AV_SAMPLE_FMT_NONE)
- return 0;
- break;
- case AVMEDIA_TYPE_VIDEO:
- - val = avctx->width && avctx->height;
- - if (avctx->pix_fmt == AV_PIX_FMT_NONE)
- + val = par->width && par->height;
- + if (par->format == AV_PIX_FMT_NONE)
- return 0;
- break;
- case AVMEDIA_TYPE_UNKNOWN:
- @@ -1585,7 +1586,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
- val = 1;
- break;
- }
- - return avctx->codec_id != AV_CODEC_ID_NONE && val != 0;
- + return par->codec_id != AV_CODEC_ID_NONE && val != 0;
- } else if (!*spec) /* empty specifier, matches everything */
- return 1;
- @@ -1607,7 +1608,7 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
- codec = s->oformat ? avcodec_find_encoder(codec_id)
- : avcodec_find_decoder(codec_id);
- - switch (st->codec->codec_type) {
- + switch (st->codecpar->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- prefix = 'v';
- flags |= AV_OPT_FLAG_VIDEO_PARAM;
- @@ -1664,7 +1665,7 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
- return NULL;
- }
- for (i = 0; i < s->nb_streams; i++)
- - opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id,
- + opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
- s, s->streams[i], NULL);
- return opts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement