MCPcopy Create free account
hub / github.com/byhook/ffmpeg4android / init_output_stream

Function init_output_stream

ffmpeg-single-cmd/src/main/cpp/ffmpeg_mod.c:3411–3592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3409}
3410
3411static int init_output_stream(OutputStream *ost, char *error, int error_len)
3412{
3413 int ret = 0;
3414
3415 if (ost->encoding_needed) {
3416 AVCodec *codec = ost->enc;
3417 AVCodecContext *dec = NULL;
3418 InputStream *ist;
3419
3420 ret = init_output_stream_encode(ost);
3421 if (ret < 0)
3422 return ret;
3423
3424 if ((ist = get_input_stream(ost)))
3425 dec = ist->dec_ctx;
3426 if (dec && dec->subtitle_header) {
3427 /* ASS code assumes this buffer is null terminated so add extra byte. */
3428 ost->enc_ctx->subtitle_header = av_mallocz(dec->subtitle_header_size + 1);
3429 if (!ost->enc_ctx->subtitle_header)
3430 return AVERROR(ENOMEM);
3431 memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);
3432 ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size;
3433 }
3434 if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
3435 av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
3436 if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
3437 !codec->defaults &&
3438 !av_dict_get(ost->encoder_opts, "b", NULL, 0) &&
3439 !av_dict_get(ost->encoder_opts, "ab", NULL, 0))
3440 av_dict_set(&ost->encoder_opts, "b", "128000", 0);
3441
3442 if (ost->filter && av_buffersink_get_hw_frames_ctx(ost->filter->filter) &&
3443 ((AVHWFramesContext*)av_buffersink_get_hw_frames_ctx(ost->filter->filter)->data)->format ==
3444 av_buffersink_get_format(ost->filter->filter)) {
3445 ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter));
3446 if (!ost->enc_ctx->hw_frames_ctx)
3447 return AVERROR(ENOMEM);
3448 }
3449
3450 if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
3451 if (ret == AVERROR_EXPERIMENTAL)
3452 abort_codec_experimental(codec, 1);
3453 snprintf(error, error_len,
3454 "Error while opening encoder for output stream #%d:%d - "
3455 "maybe incorrect parameters such as bit_rate, rate, width or height",
3456 ost->file_index, ost->index);
3457 return ret;
3458 }
3459 if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
3460 !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
3461 av_buffersink_set_frame_size(ost->filter->filter,
3462 ost->enc_ctx->frame_size);
3463 assert_avoptions(ost->encoder_opts);
3464 if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000)
3465 av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
3466 " It takes bits/s as argument, not kbits/s\n");
3467
3468 ret = avcodec_parameters_from_context(ost->st->codecpar, ost->enc_ctx);

Callers 3

reap_filtersFunction · 0.85
flush_encodersFunction · 0.85
transcode_initFunction · 0.85

Calls 8

get_input_streamFunction · 0.85
abort_codec_experimentalFunction · 0.85
assert_avoptionsFunction · 0.85
exit_programFunction · 0.85
init_output_bsfsFunction · 0.85
check_init_output_fileFunction · 0.85

Tested by

no test coverage detected