... | ... |
@@ -191,6 +191,8 @@ static void avconv_cleanup(int ret) |
191 | 191 |
av_freep(&ost->avfilter); |
192 | 192 |
av_freep(&ost->logfile_prefix); |
193 | 193 |
|
194 |
+ avcodec_free_context(&ost->enc_ctx); |
|
195 |
+ |
|
194 | 196 |
av_freep(&output_streams[i]); |
195 | 197 |
} |
196 | 198 |
for (i = 0; i < nb_input_files; i++) { |
... | ... |
@@ -316,7 +318,7 @@ static void update_sample_fmt(AVCodecContext *dec, AVCodec *dec_codec, |
316 | 316 |
static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) |
317 | 317 |
{ |
318 | 318 |
AVBitStreamFilterContext *bsfc = ost->bitstream_filters; |
319 |
- AVCodecContext *avctx = ost->st->codec; |
|
319 |
+ AVCodecContext *avctx = ost->enc_ctx; |
|
320 | 320 |
int ret; |
321 | 321 |
|
322 | 322 |
/* |
... | ... |
@@ -394,7 +396,7 @@ static int check_recording_time(OutputStream *ost) |
394 | 394 |
OutputFile *of = output_files[ost->file_index]; |
395 | 395 |
|
396 | 396 |
if (of->recording_time != INT64_MAX && |
397 |
- av_compare_ts(ost->sync_opts - ost->first_pts, ost->st->codec->time_base, of->recording_time, |
|
397 |
+ av_compare_ts(ost->sync_opts - ost->first_pts, ost->enc_ctx->time_base, of->recording_time, |
|
398 | 398 |
AV_TIME_BASE_Q) >= 0) { |
399 | 399 |
ost->finished = 1; |
400 | 400 |
return 0; |
... | ... |
@@ -405,7 +407,7 @@ static int check_recording_time(OutputStream *ost) |
405 | 405 |
static void do_audio_out(AVFormatContext *s, OutputStream *ost, |
406 | 406 |
AVFrame *frame) |
407 | 407 |
{ |
408 |
- AVCodecContext *enc = ost->st->codec; |
|
408 |
+ AVCodecContext *enc = ost->enc_ctx; |
|
409 | 409 |
AVPacket pkt; |
410 | 410 |
int got_packet = 0; |
411 | 411 |
|
... | ... |
@@ -456,7 +458,7 @@ static void do_subtitle_out(AVFormatContext *s, |
456 | 456 |
return; |
457 | 457 |
} |
458 | 458 |
|
459 |
- enc = ost->st->codec; |
|
459 |
+ enc = ost->enc_ctx; |
|
460 | 460 |
|
461 | 461 |
if (!subtitle_out) { |
462 | 462 |
subtitle_out = av_malloc(subtitle_out_max_size); |
... | ... |
@@ -513,7 +515,7 @@ static void do_video_out(AVFormatContext *s, |
513 | 513 |
{ |
514 | 514 |
int ret, format_video_sync; |
515 | 515 |
AVPacket pkt; |
516 |
- AVCodecContext *enc = ost->st->codec; |
|
516 |
+ AVCodecContext *enc = ost->enc_ctx; |
|
517 | 517 |
|
518 | 518 |
*frame_size = 0; |
519 | 519 |
|
... | ... |
@@ -563,11 +565,11 @@ static void do_video_out(AVFormatContext *s, |
563 | 563 |
} else { |
564 | 564 |
int got_packet; |
565 | 565 |
|
566 |
- if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME) && |
|
566 |
+ if (enc->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME) && |
|
567 | 567 |
ost->top_field_first >= 0) |
568 | 568 |
in_picture->top_field_first = !!ost->top_field_first; |
569 | 569 |
|
570 |
- in_picture->quality = ost->st->codec->global_quality; |
|
570 |
+ in_picture->quality = enc->global_quality; |
|
571 | 571 |
if (!enc->me_threshold) |
572 | 572 |
in_picture->pict_type = 0; |
573 | 573 |
if (ost->forced_kf_index < ost->forced_kf_count && |
... | ... |
@@ -628,7 +630,7 @@ static void do_video_stats(OutputStream *ost, int frame_size) |
628 | 628 |
} |
629 | 629 |
} |
630 | 630 |
|
631 |
- enc = ost->st->codec; |
|
631 |
+ enc = ost->enc_ctx; |
|
632 | 632 |
if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { |
633 | 633 |
frame_number = ost->frame_number; |
634 | 634 |
fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality / (float)FF_QP2LAMBDA); |
... | ... |
@@ -666,7 +668,7 @@ static int poll_filter(OutputStream *ost) |
666 | 666 |
if (ost->enc->type == AVMEDIA_TYPE_AUDIO && |
667 | 667 |
!(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) |
668 | 668 |
ret = av_buffersink_get_samples(ost->filter->filter, filtered_frame, |
669 |
- ost->st->codec->frame_size); |
|
669 |
+ ost->enc_ctx->frame_size); |
|
670 | 670 |
else |
671 | 671 |
ret = av_buffersink_get_frame(ost->filter->filter, filtered_frame); |
672 | 672 |
|
... | ... |
@@ -677,16 +679,16 @@ static int poll_filter(OutputStream *ost) |
677 | 677 |
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; |
678 | 678 |
filtered_frame->pts = av_rescale_q(filtered_frame->pts, |
679 | 679 |
ost->filter->filter->inputs[0]->time_base, |
680 |
- ost->st->codec->time_base) - |
|
680 |
+ ost->enc_ctx->time_base) - |
|
681 | 681 |
av_rescale_q(start_time, |
682 | 682 |
AV_TIME_BASE_Q, |
683 |
- ost->st->codec->time_base); |
|
683 |
+ ost->enc_ctx->time_base); |
|
684 | 684 |
} |
685 | 685 |
|
686 | 686 |
switch (ost->filter->filter->inputs[0]->type) { |
687 | 687 |
case AVMEDIA_TYPE_VIDEO: |
688 | 688 |
if (!ost->frame_aspect_ratio) |
689 |
- ost->st->codec->sample_aspect_ratio = filtered_frame->sample_aspect_ratio; |
|
689 |
+ ost->enc_ctx->sample_aspect_ratio = filtered_frame->sample_aspect_ratio; |
|
690 | 690 |
|
691 | 691 |
do_video_out(of->ctx, ost, filtered_frame, &frame_size); |
692 | 692 |
if (vstats_filename && frame_size) |
... | ... |
@@ -728,7 +730,7 @@ static int poll_filters(void) |
728 | 728 |
if (!output_streams[i]->filter || output_streams[i]->finished) |
729 | 729 |
continue; |
730 | 730 |
|
731 |
- pts = av_rescale_q(pts, output_streams[i]->st->codec->time_base, |
|
731 |
+ pts = av_rescale_q(pts, output_streams[i]->enc_ctx->time_base, |
|
732 | 732 |
AV_TIME_BASE_Q); |
733 | 733 |
if (pts < min_pts) { |
734 | 734 |
min_pts = pts; |
... | ... |
@@ -768,12 +770,12 @@ static void print_final_stats(int64_t total_size) |
768 | 768 |
|
769 | 769 |
for (i = 0; i < nb_output_streams; i++) { |
770 | 770 |
OutputStream *ost = output_streams[i]; |
771 |
- switch (ost->st->codec->codec_type) { |
|
771 |
+ switch (ost->enc_ctx->codec_type) { |
|
772 | 772 |
case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break; |
773 | 773 |
case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break; |
774 | 774 |
default: other_size += ost->data_size; break; |
775 | 775 |
} |
776 |
- extra_size += ost->st->codec->extradata_size; |
|
776 |
+ extra_size += ost->enc_ctx->extradata_size; |
|
777 | 777 |
data_size += ost->data_size; |
778 | 778 |
} |
779 | 779 |
|
... | ... |
@@ -836,7 +838,7 @@ static void print_final_stats(int64_t total_size) |
836 | 836 |
|
837 | 837 |
for (j = 0; j < of->ctx->nb_streams; j++) { |
838 | 838 |
OutputStream *ost = output_streams[of->ost_index + j]; |
839 |
- enum AVMediaType type = ost->st->codec->codec_type; |
|
839 |
+ enum AVMediaType type = ost->enc_ctx->codec_type; |
|
840 | 840 |
|
841 | 841 |
total_size += ost->data_size; |
842 | 842 |
total_packets += ost->packets_written; |
... | ... |
@@ -910,7 +912,7 @@ static void print_report(int is_last_report, int64_t timer_start) |
910 | 910 |
for (i = 0; i < nb_output_streams; i++) { |
911 | 911 |
float q = -1; |
912 | 912 |
ost = output_streams[i]; |
913 |
- enc = ost->st->codec; |
|
913 |
+ enc = ost->enc_ctx; |
|
914 | 914 |
if (!ost->stream_copy && enc->coded_frame) |
915 | 915 |
q = enc->coded_frame->quality / (float)FF_QP2LAMBDA; |
916 | 916 |
if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { |
... | ... |
@@ -989,23 +991,23 @@ static void flush_encoders(void) |
989 | 989 |
|
990 | 990 |
for (i = 0; i < nb_output_streams; i++) { |
991 | 991 |
OutputStream *ost = output_streams[i]; |
992 |
- AVCodecContext *enc = ost->st->codec; |
|
992 |
+ AVCodecContext *enc = ost->enc_ctx; |
|
993 | 993 |
AVFormatContext *os = output_files[ost->file_index]->ctx; |
994 | 994 |
int stop_encoding = 0; |
995 | 995 |
|
996 | 996 |
if (!ost->encoding_needed) |
997 | 997 |
continue; |
998 | 998 |
|
999 |
- if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1) |
|
999 |
+ if (enc->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1) |
|
1000 | 1000 |
continue; |
1001 |
- if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE) && enc->codec->id == AV_CODEC_ID_RAWVIDEO) |
|
1001 |
+ if (enc->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE) && enc->codec->id == AV_CODEC_ID_RAWVIDEO) |
|
1002 | 1002 |
continue; |
1003 | 1003 |
|
1004 | 1004 |
for (;;) { |
1005 | 1005 |
int (*encode)(AVCodecContext*, AVPacket*, const AVFrame*, int*) = NULL; |
1006 | 1006 |
const char *desc; |
1007 | 1007 |
|
1008 |
- switch (ost->st->codec->codec_type) { |
|
1008 |
+ switch (enc->codec_type) { |
|
1009 | 1009 |
case AVMEDIA_TYPE_AUDIO: |
1010 | 1010 |
encode = avcodec_encode_audio2; |
1011 | 1011 |
desc = "Audio"; |
... | ... |
@@ -1100,7 +1102,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p |
1100 | 1100 |
} |
1101 | 1101 |
|
1102 | 1102 |
/* force the input stream PTS */ |
1103 |
- if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) |
|
1103 |
+ if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) |
|
1104 | 1104 |
ost->sync_opts++; |
1105 | 1105 |
|
1106 | 1106 |
if (pkt->pts != AV_NOPTS_VALUE) |
... | ... |
@@ -1118,10 +1120,10 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p |
1118 | 1118 |
opkt.flags = pkt->flags; |
1119 | 1119 |
|
1120 | 1120 |
// FIXME remove the following 2 lines they shall be replaced by the bitstream filters |
1121 |
- if ( ost->st->codec->codec_id != AV_CODEC_ID_H264 |
|
1122 |
- && ost->st->codec->codec_id != AV_CODEC_ID_MPEG1VIDEO |
|
1123 |
- && ost->st->codec->codec_id != AV_CODEC_ID_MPEG2VIDEO |
|
1124 |
- && ost->st->codec->codec_id != AV_CODEC_ID_VC1 |
|
1121 |
+ if ( ost->enc_ctx->codec_id != AV_CODEC_ID_H264 |
|
1122 |
+ && ost->enc_ctx->codec_id != AV_CODEC_ID_MPEG1VIDEO |
|
1123 |
+ && ost->enc_ctx->codec_id != AV_CODEC_ID_MPEG2VIDEO |
|
1124 |
+ && ost->enc_ctx->codec_id != AV_CODEC_ID_VC1 |
|
1125 | 1125 |
) { |
1126 | 1126 |
if (av_parser_change(ost->parser, ost->st->codec, |
1127 | 1127 |
&opkt.data, &opkt.size, |
... | ... |
@@ -1555,7 +1557,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) |
1555 | 1555 |
for (i = 0; i < nb_output_streams; i++) { |
1556 | 1556 |
OutputStream *ost = output_streams[i]; |
1557 | 1557 |
if (ost->source_index == ist_index) { |
1558 |
- update_sample_fmt(ist->dec_ctx, codec, ost->st->codec); |
|
1558 |
+ update_sample_fmt(ist->dec_ctx, codec, ost->enc_ctx); |
|
1559 | 1559 |
break; |
1560 | 1560 |
} |
1561 | 1561 |
} |
... | ... |
@@ -1602,7 +1604,7 @@ static InputStream *get_input_stream(OutputStream *ost) |
1602 | 1602 |
int i; |
1603 | 1603 |
|
1604 | 1604 |
for (i = 0; i < fg->nb_inputs; i++) |
1605 |
- if (fg->inputs[i]->ist->dec_ctx->codec_type == ost->st->codec->codec_type) |
|
1605 |
+ if (fg->inputs[i]->ist->dec_ctx->codec_type == ost->enc_ctx->codec_type) |
|
1606 | 1606 |
return fg->inputs[i]->ist; |
1607 | 1607 |
} |
1608 | 1608 |
|
... | ... |
@@ -1711,7 +1713,7 @@ static int transcode_init(void) |
1711 | 1711 |
if (ost->attachment_filename) |
1712 | 1712 |
continue; |
1713 | 1713 |
|
1714 |
- enc_ctx = ost->st->codec; |
|
1714 |
+ enc_ctx = ost->enc_ctx; |
|
1715 | 1715 |
|
1716 | 1716 |
if (ist) { |
1717 | 1717 |
dec_ctx = ist->dec_ctx; |
... | ... |
@@ -1893,7 +1895,7 @@ static int transcode_init(void) |
1893 | 1893 |
|
1894 | 1894 |
if (ost->forced_keyframes) |
1895 | 1895 |
parse_forced_key_frames(ost->forced_keyframes, ost, |
1896 |
- ost->st->codec); |
|
1896 |
+ ost->enc_ctx); |
|
1897 | 1897 |
break; |
1898 | 1898 |
case AVMEDIA_TYPE_SUBTITLE: |
1899 | 1899 |
enc_ctx->time_base = (AVRational){1, 1000}; |
... | ... |
@@ -1947,17 +1949,19 @@ static int transcode_init(void) |
1947 | 1947 |
if ((ist = get_input_stream(ost))) |
1948 | 1948 |
dec = ist->dec_ctx; |
1949 | 1949 |
if (dec && dec->subtitle_header) { |
1950 |
- ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); |
|
1951 |
- if (!ost->st->codec->subtitle_header) { |
|
1950 |
+ ost->enc_ctx->subtitle_header = av_malloc(dec->subtitle_header_size); |
|
1951 |
+ if (!ost->enc_ctx->subtitle_header) { |
|
1952 | 1952 |
ret = AVERROR(ENOMEM); |
1953 | 1953 |
goto dump_format; |
1954 | 1954 |
} |
1955 |
- memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); |
|
1956 |
- ost->st->codec->subtitle_header_size = dec->subtitle_header_size; |
|
1955 |
+ memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); |
|
1956 |
+ ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size; |
|
1957 | 1957 |
} |
1958 | 1958 |
if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) |
1959 | 1959 |
av_dict_set(&ost->encoder_opts, "threads", "auto", 0); |
1960 |
- if ((ret = avcodec_open2(ost->st->codec, codec, &ost->encoder_opts)) < 0) { |
|
1960 |
+ av_dict_set(&ost->encoder_opts, "side_data_only_packets", "1", 0); |
|
1961 |
+ |
|
1962 |
+ if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) { |
|
1961 | 1963 |
if (ret == AVERROR_EXPERIMENTAL) |
1962 | 1964 |
abort_codec_experimental(codec, 1); |
1963 | 1965 |
snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height", |
... | ... |
@@ -1965,11 +1969,18 @@ static int transcode_init(void) |
1965 | 1965 |
goto dump_format; |
1966 | 1966 |
} |
1967 | 1967 |
assert_avoptions(ost->encoder_opts); |
1968 |
- if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) |
|
1968 |
+ if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000) |
|
1969 | 1969 |
av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." |
1970 | 1970 |
"It takes bits/s as argument, not kbits/s\n"); |
1971 | 1971 |
} else { |
1972 |
- av_opt_set_dict(ost->st->codec, &ost->encoder_opts); |
|
1972 |
+ av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts); |
|
1973 |
+ } |
|
1974 |
+ |
|
1975 |
+ ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx); |
|
1976 |
+ if (ret < 0) { |
|
1977 |
+ av_log(NULL, AV_LOG_FATAL, |
|
1978 |
+ "Error initializing the output stream codec context.\n"); |
|
1979 |
+ exit_program(1); |
|
1973 | 1980 |
} |
1974 | 1981 |
} |
1975 | 1982 |
|
... | ... |
@@ -2505,8 +2516,7 @@ static int transcode(void) |
2505 | 2505 |
for (i = 0; i < nb_output_streams; i++) { |
2506 | 2506 |
ost = output_streams[i]; |
2507 | 2507 |
if (ost->encoding_needed) { |
2508 |
- av_freep(&ost->st->codec->stats_in); |
|
2509 |
- avcodec_close(ost->st->codec); |
|
2508 |
+ av_freep(&ost->enc_ctx->stats_in); |
|
2510 | 2509 |
} |
2511 | 2510 |
} |
2512 | 2511 |
|
... | ... |
@@ -2532,13 +2542,10 @@ static int transcode(void) |
2532 | 2532 |
for (i = 0; i < nb_output_streams; i++) { |
2533 | 2533 |
ost = output_streams[i]; |
2534 | 2534 |
if (ost) { |
2535 |
- if (ost->stream_copy) |
|
2536 |
- av_freep(&ost->st->codec->extradata); |
|
2537 | 2535 |
if (ost->logfile) { |
2538 | 2536 |
fclose(ost->logfile); |
2539 | 2537 |
ost->logfile = NULL; |
2540 | 2538 |
} |
2541 |
- av_freep(&ost->st->codec->subtitle_header); |
|
2542 | 2539 |
av_free(ost->forced_kf_pts); |
2543 | 2540 |
av_dict_free(&ost->encoder_opts); |
2544 | 2541 |
av_dict_free(&ost->resample_opts); |
... | ... |
@@ -314,6 +314,7 @@ typedef struct OutputStream { |
314 | 314 |
/* dts of the last packet sent to the muxer */ |
315 | 315 |
int64_t last_mux_dts; |
316 | 316 |
AVBitStreamFilterContext *bitstream_filters; |
317 |
+ AVCodecContext *enc_ctx; |
|
317 | 318 |
AVCodec *enc; |
318 | 319 |
int64_t max_frames; |
319 | 320 |
AVFrame *filtered_frame; |
... | ... |
@@ -39,8 +39,8 @@ |
39 | 39 |
#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name) \ |
40 | 40 |
static char *choose_ ## var ## s(OutputStream *ost) \ |
41 | 41 |
{ \ |
42 |
- if (ost->st->codec->var != none) { \ |
|
43 |
- get_name(ost->st->codec->var); \ |
|
42 |
+ if (ost->enc_ctx->var != none) { \ |
|
43 |
+ get_name(ost->enc_ctx->var); \ |
|
44 | 44 |
return av_strdup(name); \ |
45 | 45 |
} else if (ost->enc && ost->enc->supported_list) { \ |
46 | 46 |
const type *p; \ |
... | ... |
@@ -231,7 +231,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, |
231 | 231 |
char *pix_fmts; |
232 | 232 |
OutputStream *ost = ofilter->ost; |
233 | 233 |
OutputFile *of = output_files[ost->file_index]; |
234 |
- AVCodecContext *codec = ost->st->codec; |
|
234 |
+ AVCodecContext *codec = ost->enc_ctx; |
|
235 | 235 |
AVFilterContext *last_filter = out->filter_ctx; |
236 | 236 |
int pad_idx = out->pad_idx; |
237 | 237 |
int ret; |
... | ... |
@@ -319,7 +319,7 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, |
319 | 319 |
{ |
320 | 320 |
OutputStream *ost = ofilter->ost; |
321 | 321 |
OutputFile *of = output_files[ost->file_index]; |
322 |
- AVCodecContext *codec = ost->st->codec; |
|
322 |
+ AVCodecContext *codec = ost->enc_ctx; |
|
323 | 323 |
AVFilterContext *last_filter = out->filter_ctx; |
324 | 324 |
int pad_idx = out->pad_idx; |
325 | 325 |
char *sample_fmts, *sample_rates, *channel_layouts; |
... | ... |
@@ -905,6 +905,14 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e |
905 | 905 |
ost->st = st; |
906 | 906 |
st->codec->codec_type = type; |
907 | 907 |
choose_encoder(o, oc, ost); |
908 |
+ |
|
909 |
+ ost->enc_ctx = avcodec_alloc_context3(ost->enc); |
|
910 |
+ if (!ost->enc_ctx) { |
|
911 |
+ av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n"); |
|
912 |
+ exit_program(1); |
|
913 |
+ } |
|
914 |
+ ost->enc_ctx->codec_type = type; |
|
915 |
+ |
|
908 | 916 |
if (ost->enc) { |
909 | 917 |
AVIOContext *s = NULL; |
910 | 918 |
char *buf = NULL, *arg = NULL, *preset = NULL; |
... | ... |
@@ -939,9 +947,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e |
939 | 939 |
ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); |
940 | 940 |
} |
941 | 941 |
|
942 |
- avcodec_get_context_defaults3(st->codec, ost->enc); |
|
943 |
- st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy |
|
944 |
- |
|
945 | 942 |
ost->max_frames = INT64_MAX; |
946 | 943 |
MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); |
947 | 944 |
|
... | ... |
@@ -967,17 +972,17 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e |
967 | 967 |
uint32_t tag = strtol(codec_tag, &next, 0); |
968 | 968 |
if (*next) |
969 | 969 |
tag = AV_RL32(codec_tag); |
970 |
- st->codec->codec_tag = tag; |
|
970 |
+ ost->enc_ctx->codec_tag = tag; |
|
971 | 971 |
} |
972 | 972 |
|
973 | 973 |
MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); |
974 | 974 |
if (qscale >= 0) { |
975 |
- st->codec->flags |= CODEC_FLAG_QSCALE; |
|
976 |
- st->codec->global_quality = FF_QP2LAMBDA * qscale; |
|
975 |
+ ost->enc_ctx->flags |= CODEC_FLAG_QSCALE; |
|
976 |
+ ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; |
|
977 | 977 |
} |
978 | 978 |
|
979 | 979 |
if (oc->oformat->flags & AVFMT_GLOBALHEADER) |
980 |
- st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
980 |
+ ost->enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
981 | 981 |
|
982 | 982 |
av_opt_get_int(o->g->sws_opts, "sws_flags", 0, &ost->sws_flags); |
983 | 983 |
|
... | ... |
@@ -1068,7 +1073,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) |
1068 | 1068 |
|
1069 | 1069 |
ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO); |
1070 | 1070 |
st = ost->st; |
1071 |
- video_enc = st->codec; |
|
1071 |
+ video_enc = ost->enc_ctx; |
|
1072 | 1072 |
|
1073 | 1073 |
MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st); |
1074 | 1074 |
if (frame_aspect_ratio) |
... | ... |
@@ -1189,7 +1194,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc) |
1189 | 1189 |
ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO); |
1190 | 1190 |
st = ost->st; |
1191 | 1191 |
|
1192 |
- audio_enc = st->codec; |
|
1192 |
+ audio_enc = ost->enc_ctx; |
|
1193 | 1193 |
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; |
1194 | 1194 |
|
1195 | 1195 |
if (!ost->stream_copy) { |
... | ... |
@@ -1237,13 +1242,11 @@ static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *o |
1237 | 1237 |
|
1238 | 1238 |
static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc) |
1239 | 1239 |
{ |
1240 |
- AVStream *st; |
|
1241 | 1240 |
OutputStream *ost; |
1242 | 1241 |
AVCodecContext *subtitle_enc; |
1243 | 1242 |
|
1244 | 1243 |
ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE); |
1245 |
- st = ost->st; |
|
1246 |
- subtitle_enc = st->codec; |
|
1244 |
+ subtitle_enc = ost->enc_ctx; |
|
1247 | 1245 |
|
1248 | 1246 |
subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; |
1249 | 1247 |
|