Lines Matching defs:ost

570         OutputStream *ost = output_streams[i];
572 if (!ost)
575 av_bsf_free(&ost->bsf_ctx);
577 av_frame_free(&ost->filtered_frame);
578 av_frame_free(&ost->last_frame);
579 av_packet_free(&ost->pkt);
580 av_dict_free(&ost->encoder_opts);
582 av_freep(&ost->forced_keyframes);
583 av_expr_free(ost->forced_keyframes_pexpr);
584 av_freep(&ost->avfilter);
585 av_freep(&ost->logfile_prefix);
587 av_freep(&ost->audio_channels_map);
588 ost->audio_channels_mapped = 0;
590 av_dict_free(&ost->sws_dict);
591 av_dict_free(&ost->swr_opts);
593 avcodec_free_context(&ost->enc_ctx);
594 avcodec_parameters_free(&ost->ref_par);
596 if (ost->muxing_queue) {
598 while (av_fifo_read(ost->muxing_queue, &pkt, 1) >= 0)
600 av_fifo_freep2(&ost->muxing_queue);
702 static void close_output_stream(OutputStream *ost)
704 OutputFile *of = output_files[ost->file_index];
705 AVRational time_base = ost->stream_copy ? ost->mux_timebase : ost->enc_ctx->time_base;
707 ost->finished |= ENCODER_FINISHED;
709 int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, time_base, AV_TIME_BASE_Q);
726 OutputStream *ost, int eof)
731 if (ost->bsf_ctx) {
732 ret = av_bsf_send_packet(ost->bsf_ctx, eof ? NULL : pkt);
735 while ((ret = av_bsf_receive_packet(ost->bsf_ctx, pkt)) >= 0)
736 of_write_packet(of, pkt, ost, 0);
740 of_write_packet(of, pkt, ost, 0);
745 "packet for stream #%d:%d.\n", ost->file_index, ost->index);
751 static int check_recording_time(OutputStream *ost)
753 OutputFile *of = output_files[ost->file_index];
756 av_compare_ts(ost->sync_opts - ost->first_pts, ost->enc_ctx->time_base, of->recording_time,
758 close_output_stream(ost);
764 static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
768 AVCodecContext *enc = ost->enc_ctx;
770 !enc || !ost->filter || !ost->filter->graph->graph)
774 AVFilterContext *filter = ost->filter->filter;
808 static int init_output_stream(OutputStream *ost, AVFrame *frame,
811 static int init_output_stream_wrapper(OutputStream *ost, AVFrame *frame,
817 if (ost->initialized)
820 ret = init_output_stream(ost, frame, error, sizeof(error));
823 ost->file_index, ost->index, error);
837 static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
841 AVCodecContext *enc = ost->enc_ctx;
845 ost->quality = sd ? AV_RL32(sd) : -1;
846 ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE;
848 for (int i = 0; i<FF_ARRAY_ELEMS(ost->error); i++) {
850 ost->error[i] = AV_RL64(sd + 8 + 8*i);
852 ost->error[i] = -1;
867 frame_number = ost->packets_encoded;
870 ost->quality / (float)FF_QP2LAMBDA);
872 fprintf(vstats_file, "out= %2d st= %2d frame= %5"PRId64" q= %2.1f ", ost->file_index, ost->index, frame_number,
873 ost->quality / (float)FF_QP2LAMBDA);
876 if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
877 fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0)));
881 ti1 = pkt->dts * av_q2d(ost->mux_timebase);
886 avg_bitrate = (double)(ost->data_size * 8) / ti1 / 1000.0;
888 (double)ost->data_size / 1024, ti1, bitrate, avg_bitrate);
889 fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(ost->pict_type));
892 static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
894 AVCodecContext *enc = ost->enc_ctx;
895 AVPacket *pkt = ost->pkt;
901 ost->frames_encoded++;
924 ost->file_index, ost->index);
927 if ((ret >= 0 || ret == AVERROR_EOF) && ost->logfile && enc->stats_out)
928 fprintf(ost->logfile, "%s", enc->stats_out);
934 output_packet(of, pkt, ost, 1);
951 av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase);
964 update_video_stats(ost, pkt, !!vstats_filename);
966 ost->packets_encoded++;
968 output_packet(of, pkt, ost, 0);
974 static void do_audio_out(OutputFile *of, OutputStream *ost,
979 adjust_frame_pts_to_encoder_tb(of, ost, frame);
981 if (!check_recording_time(ost))
985 frame->pts = ost->sync_opts;
986 ost->sync_opts = frame->pts + frame->nb_samples;
987 ost->samples_encoded += frame->nb_samples;
989 ret = encode_frame(of, ost, frame);
995 OutputStream *ost,
1001 AVPacket *pkt = ost->pkt;
1011 enc = ost->enc_ctx;
1031 if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE)
1032 pts -= output_files[ost->file_index]->start_time;
1036 ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base);
1037 if (!check_recording_time(ost))
1048 ost->frames_encoded++;
1062 pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase);
1063 pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);
1068 pkt->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);
1070 pkt->pts += av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase);
1073 output_packet(of, pkt, ost, 0);
1079 OutputStream *ost,
1083 AVCodecContext *enc = ost->enc_ctx;
1090 AVFilterContext *filter = ost->filter->filter;
1092 init_output_stream_wrapper(ost, next_picture, 1);
1093 sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture);
1095 if (ost->source_index >= 0)
1096 ist = input_streams[ost->source_index];
1102 if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
1103 duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
1105 if (!ost->filters_script &&
1106 !ost->filters &&
1116 nb0_frames = nb_frames = mid_pred(ost->last_nb0_frames[0],
1117 ost->last_nb0_frames[1],
1118 ost->last_nb0_frames[2]);
1120 delta0 = sync_ipts - ost->sync_opts; // delta0 is the "drift" between the input frame (next_picture) and where it would fall in the output.
1129 ost->vsync_method != VSYNC_PASSTHROUGH &&
1130 ost->vsync_method != VSYNC_DROP) {
1135 sync_ipts = ost->sync_opts;
1140 switch (ost->vsync_method) {
1142 if (ost->frame_number == 0 && delta0 >= 0.5) {
1146 ost->sync_opts = llrint(sync_ipts);
1150 if (frame_drop_threshold && delta < frame_drop_threshold && ost->frame_number) {
1164 ost->sync_opts = llrint(sync_ipts);
1168 ost->sync_opts = llrint(sync_ipts);
1180 nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number);
1183 memmove(ost->last_nb0_frames + 1,
1184 ost->last_nb0_frames,
1185 sizeof(ost->last_nb0_frames[0]) * (FF_ARRAY_ELEMS(ost->last_nb0_frames) - 1));
1186 ost->last_nb0_frames[0] = nb0_frames;
1188 if (nb0_frames == 0 && ost->last_dropped) {
1192 ost->frame_number, ost->st->index, ost->last_frame->pts);
1194 if (nb_frames > (nb0_frames && ost->last_dropped) + (nb_frames > nb0_frames)) {
1200 nb_frames_dup += nb_frames - (nb0_frames && ost->last_dropped) - (nb_frames > nb0_frames);
1207 ost->last_dropped = nb_frames == nb0_frames && next_picture;
1208 ost->dropped_keyframe = ost->last_dropped && next_picture && next_picture->key_frame;
1216 if (i < nb0_frames && ost->last_frame->buf[0]) {
1217 in_picture = ost->last_frame;
1224 in_picture->pts = ost->sync_opts;
1226 if (!check_recording_time(ost))
1232 if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE &&
1234 ost->forced_kf_ref_pts = in_picture->pts;
1237 (in_picture->pts - ost->forced_kf_ref_pts) * av_q2d(enc->time_base) : NAN;
1238 if (ost->forced_kf_index < ost->forced_kf_count &&
1239 in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
1240 ost->forced_kf_index++;
1242 } else if (ost->forced_keyframes_pexpr) {
1244 ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
1245 res = av_expr_eval(ost->forced_keyframes_pexpr,
1246 ost->forced_keyframes_expr_const_values, NULL);
1248 ost->forced_keyframes_expr_const_values[FKF_N],
1249 ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
1250 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
1251 ost->forced_keyframes_expr_const_values[FKF_T],
1252 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
1256 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
1257 ost->forced_keyframes_expr_const_values[FKF_N];
1258 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
1259 ost->forced_keyframes_expr_const_values[FKF_T];
1260 ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
1263 ost->forced_keyframes_expr_const_values[FKF_N] += 1;
1264 } else if ( ost->forced_keyframes
1265 && !strncmp(ost->forced_keyframes, "source", 6)
1269 } else if ( ost->forced_keyframes
1270 && !strncmp(ost->forced_keyframes, "source_no_drop", 14)
1272 forced_keyframe = (in_picture->key_frame == 1) || ost->dropped_keyframe;
1273 ost->dropped_keyframe = 0;
1281 ret = encode_frame(of, ost, in_picture);
1285 ost->sync_opts++;
1286 ost->frame_number++;
1289 av_frame_unref(ost->last_frame);
1291 av_frame_move_ref(ost->last_frame, next_picture);
1294 static void finish_output_stream(OutputStream *ost)
1296 OutputFile *of = output_files[ost->file_index];
1297 AVRational time_base = ost->stream_copy ? ost->mux_timebase : ost->enc_ctx->time_base;
1299 ost->finished = ENCODER_FINISHED | MUXER_FINISHED;
1302 int64_t end = av_rescale_q(ost->sync_opts - ost->first_pts, time_base, AV_TIME_BASE_Q);
1320 OutputStream *ost = output_streams[i];
1321 OutputFile *of = output_files[ost->file_index];
1323 AVCodecContext *enc = ost->enc_ctx;
1326 if (!ost->filter || !ost->filter->graph->graph)
1328 filter = ost->filter->filter;
1340 init_output_stream_wrapper(ost, NULL, 1);
1342 filtered_frame = ost->filtered_frame;
1353 do_video_out(of, ost, NULL);
1357 if (ost->finished) {
1364 if (!ost->frame_aspect_ratio.num)
1367 do_video_out(of, ost, filtered_frame);
1376 do_audio_out(of, ost, filtered_frame);
1400 OutputStream *ost = output_streams[i];
1401 switch (ost->enc_ctx->codec_type) {
1402 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
1403 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
1404 case AVMEDIA_TYPE_SUBTITLE: subtitle_size += ost->data_size; break;
1405 default: other_size += ost->data_size; break;
1407 extra_size += ost->enc_ctx->extradata_size;
1408 data_size += ost->data_size;
1409 if ( (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
1472 OutputStream *ost = output_streams[of->ost_index + j];
1473 enum AVMediaType type = ost->enc_ctx->codec_type;
1475 total_size += ost->data_size;
1476 total_packets += ost->packets_written;
1480 if (ost->encoding_needed) {
1482 ost->frames_encoded);
1484 av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
1489 ost->packets_written, ost->data_size);
1510 OutputStream *ost;
1553 ost = output_streams[i];
1554 enc = ost->enc_ctx;
1555 if (!ost->stream_copy)
1556 q = ost->quality / (float) FF_QP2LAMBDA;
1561 ost->file_index, ost->index, q);
1565 int64_t frame_number = ost->frame_number;
1573 ost->file_index, ost->index, q);
1585 if ((enc->flags & AV_CODEC_FLAG_PSNR) && (ost->pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) {
1597 error = ost->error[j];
1607 ost->file_index, ost->index, type[j] | 32, p);
1612 ost->file_index, ost->index, p);
1617 if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) {
1618 pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
1619 ost->st->time_base, AV_TIME_BASE_Q));
1629 nb_frames_drop += ost->last_dropped;
1740 OutputStream *ost = output_streams[i];
1741 AVCodecContext *enc = ost->enc_ctx;
1742 OutputFile *of = output_files[ost->file_index];
1744 if (!ost->encoding_needed)
1749 if (!ost->initialized) {
1750 FilterGraph *fg = ost->filter->graph;
1754 ost->file_index, ost->st->index);
1756 if (ost->filter && !fg->graph) {
1776 finish_output_stream(ost);
1779 init_output_stream_wrapper(ost, NULL, 1);
1785 ret = encode_frame(of, ost, NULL);
1792 * Check whether a packet from ist should be written into ost at this time
1794 static int check_output_constraints(InputStream *ist, OutputStream *ost)
1796 OutputFile *of = output_files[ost->file_index];
1799 if (ost->source_index != ist_index)
1802 if (ost->finished & MUXER_FINISHED)
1811 static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
1813 OutputFile *of = output_files[ost->file_index];
1816 int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
1817 AVPacket *opkt = ost->pkt;
1822 output_packet(of, opkt, ost, 1);
1826 if (!ost->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) &&
1827 !ost->copy_initial_nonkeyframes)
1830 if (!ost->streamcopy_started && !ost->copy_prior_start) {
1842 close_output_stream(ost);
1853 close_output_stream(ost);
1862 opkt->pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time;
1865 opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase);
1866 } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
1872 &ist->filter_in_rescale_delta_last, ost->mux_timebase);
1876 opkt->dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
1879 opkt->duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase);
1881 ost->sync_opts += opkt->duration;
1883 output_packet(of, opkt, ost, 0);
1885 ost->streamcopy_started = 1;
2333 OutputStream *ost = output_streams[i];
2335 if (!check_output_constraints(ist, ost) || !ost->encoding_needed
2336 || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
2339 do_subtitle_out(output_files[ost->file_index], ost, &subtitle);
2541 OutputStream *ost = output_streams[i];
2543 if (!check_output_constraints(ist, ost) || ost->encoding_needed)
2546 do_streamcopy(ist, ost, pkt);
2666 static InputStream *get_input_stream(OutputStream *ost)
2668 if (ost->source_index >= 0)
2669 return input_streams[ost->source_index];
2678 static int init_output_bsfs(OutputStream *ost)
2680 AVBSFContext *ctx = ost->bsf_ctx;
2686 ret = avcodec_parameters_copy(ctx->par_in, ost->st->codecpar);
2690 ctx->time_base_in = ost->st->time_base;
2699 ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
2702 ost->st->time_base = ctx->time_base_out;
2707 static int init_output_stream_streamcopy(OutputStream *ost)
2709 OutputFile *of = output_files[ost->file_index];
2710 InputStream *ist = get_input_stream(ost);
2711 AVCodecParameters *par_dst = ost->st->codecpar;
2712 AVCodecParameters *par_src = ost->ref_par;
2717 av_assert0(ist && !ost->filter);
2719 ret = avcodec_parameters_to_context(ost->enc_ctx, ist->st->codecpar);
2721 ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);
2728 ret = avcodec_parameters_from_context(par_src, ost->enc_ctx);
2749 if (!ost->frame_rate.num)
2750 ost->frame_rate = ist->framerate;
2752 if (ost->frame_rate.num)
2753 ost->st->avg_frame_rate = ost->frame_rate;
2755 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
2757 ret = avformat_transfer_internal_stream_timing_info(of->format, ost->st, ist->st, copy_tb);
2762 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
2763 if (ost->frame_rate.num)
2764 ost->st->time_base = av_inv_q(ost->frame_rate);
2766 ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
2770 if (ost->st->duration <= 0 && ist->st->duration > 0)
2771 ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
2778 dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size);
2785 if (ost->rotate_overridden) {
2786 uint8_t *sd = av_stream_new_side_data(ost->st, AV_PKT_DATA_DISPLAYMATRIX,
2789 av_display_rotation_set((int32_t *)sd, -ost->rotate_override_value);
2804 if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
2806 av_mul_q(ost->frame_aspect_ratio,
2815 ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
2816 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
2817 ost->st->r_frame_rate = ist->st->r_frame_rate;
2821 ost->mux_timebase = ist->st->time_base;
2826 static void set_encoder_id(OutputFile *of, OutputStream *ost)
2833 int codec_flags = ost->enc_ctx->flags;
2835 if (av_dict_get(ost->st->metadata, "encoder", NULL, 0))
2845 e = av_dict_get(ost->encoder_opts, "flags", NULL, 0);
2847 const AVOption *o = av_opt_find(ost->enc_ctx, "flags", NULL, 0, 0);
2850 av_opt_eval_flags(ost->enc_ctx, o, e->value, &codec_flags);
2853 encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(ost->enc->name) + 2;
2862 av_strlcat(encoder_string, ost->enc->name, encoder_string_len);
2863 av_dict_set(&ost->st->metadata, "encoder", encoder_string,
2867 static void parse_forced_key_frames(char *kf, OutputStream *ost,
2893 AVFormatContext *avf = output_files[ost->file_index]->ctx;
2926 ost->forced_kf_count = size;
2927 ost->forced_kf_pts = pts;
2930 static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
2932 InputStream *ist = get_input_stream(ost);
2933 AVCodecContext *enc_ctx = ost->enc_ctx;
2936 if (ost->enc_timebase.num > 0) {
2937 enc_ctx->time_base = ost->enc_timebase;
2941 if (ost->enc_timebase.num < 0) {
2947 oc = output_files[ost->file_index]->ctx;
2954 static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
2956 InputStream *ist = get_input_stream(ost);
2957 AVCodecContext *enc_ctx = ost->enc_ctx;
2959 OutputFile *of = output_files[ost->file_index];
2963 set_encoder_id(output_files[ost->file_index], ost);
2970 if (!ost->frame_rate.num)
2971 ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter);
2972 if (ist && !ost->frame_rate.num && !ost->max_frame_rate.num) {
2973 ost->frame_rate = (AVRational){25, 1};
2979 ost->file_index, ost->index);
2982 if (ost->max_frame_rate.num &&
2983 (av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) ||
2984 !ost->frame_rate.den))
2985 ost->frame_rate = ost->max_frame_rate;
2987 if (ost->enc->supported_framerates && !ost->force_fps) {
2988 int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
2989 ost->frame_rate = ost->enc->supported_framerates[idx];
2993 av_reduce(&ost->frame_rate.num, &ost->frame_rate.den,
2994 ost->frame_rate.num, ost->frame_rate.den, 65535);
3000 enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter);
3001 enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter);
3002 ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout);
3006 if (ost->bits_per_raw_sample)
3007 enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
3008 else if (dec_ctx && ost->filter->graph->is_meta)
3012 init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
3016 init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
3019 enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
3020 if ( av_q2d(enc_ctx->time_base) < 0.001 && ost->vsync_method != VSYNC_PASSTHROUGH
3021 && (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR ||
3022 (ost->vsync_method == VSYNC_AUTO && !(of->format->flags & AVFMT_VARIABLE_FPS)))){
3028 enc_ctx->width = av_buffersink_get_w(ost->filter->filter);
3029 enc_ctx->height = av_buffersink_get_h(ost->filter->filter);
3030 enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =
3031 ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option
3032 av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) :
3033 av_buffersink_get_sample_aspect_ratio(ost->filter->filter);
3035 enc_ctx->pix_fmt = av_buffersink_get_format(ost->filter->filter);
3037 if (ost->bits_per_raw_sample)
3038 enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
3039 else if (dec_ctx && ost->filter->graph->is_meta)
3051 enc_ctx->framerate = ost->frame_rate;
3053 ost->st->avg_frame_rate = ost->frame_rate;
3058 ost->top_field_first >= 0)
3059 frame->top_field_first = !!ost->top_field_first;
3071 if (ost->top_field_first == 0) {
3073 } else if (ost->top_field_first == 1) {
3077 if (ost->forced_keyframes) {
3078 if (!strncmp(ost->forced_keyframes, "expr:", 5)) {
3079 ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5,
3083 "Invalid force_key_frames expression '%s'\n", ost->forced_keyframes+5);
3086 ost->forced_keyframes_expr_const_values[FKF_N] = 0;
3087 ost->forced_keyframes_expr_const_values[FKF_N_FORCED] = 0;
3088 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = NAN;
3089 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = NAN;
3093 } else if(strncmp(ost->forced_keyframes, "source", 6)) {
3094 parse_forced_key_frames(ost->forced_keyframes, ost, ost->enc_ctx);
3101 enc_ctx->width = input_streams[ost->source_index]->st->codecpar->width;
3102 enc_ctx->height = input_streams[ost->source_index]->st->codecpar->height;
3112 ost->mux_timebase = enc_ctx->time_base;
3117 static int init_output_stream(OutputStream *ost, AVFrame *frame,
3122 if (ost->encoding_needed) {
3123 const AVCodec *codec = ost->enc;
3127 ret = init_output_stream_encode(ost, frame);
3131 if ((ist = get_input_stream(ost)))
3135 ost->enc_ctx->subtitle_header = av_mallocz(dec->subtitle_header_size + 1);
3136 if (!ost->enc_ctx->subtitle_header)
3138 memcpy(ost->enc_ctx->subtitle_header, dec->subtitle_header, dec->subtitle_header_size);
3139 ost->enc_ctx->subtitle_header_size = dec->subtitle_header_size;
3141 if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
3142 av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
3144 ret = hw_device_setup_for_encode(ost);
3148 ost->file_index, ost->index, av_err2str(ret));
3152 if (ist && ist->dec->type == AVMEDIA_TYPE_SUBTITLE && ost->enc->type == AVMEDIA_TYPE_SUBTITLE) {
3157 avcodec_descriptor_get(ost->enc_ctx->codec_id);
3170 if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
3176 ost->file_index, ost->index);
3179 if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
3180 !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
3181 av_buffersink_set_frame_size(ost->filter->filter,
3182 ost->enc_ctx->frame_size);
3183 assert_avoptions(ost->encoder_opts);
3184 if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 &&
3185 ost->enc_ctx->codec_id != AV_CODEC_ID_CODEC2 /* don't complain about 700 bit/s modes */)
3189 ret = avcodec_parameters_from_context(ost->st->codecpar, ost->enc_ctx);
3196 if (ost->enc_ctx->nb_coded_side_data) {
3199 for (i = 0; i < ost->enc_ctx->nb_coded_side_data; i++) {
3200 const AVPacketSideData *sd_src = &ost->enc_ctx->coded_side_data[i];
3203 dst_data = av_stream_new_side_data(ost->st, sd_src->type, sd_src->size);
3222 uint8_t *dst = av_stream_new_side_data(ost->st, sd->type, sd->size);
3233 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
3234 ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1});
3237 if (ost->st->duration <= 0 && ist && ist->st->duration > 0)
3238 ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
3239 } else if (ost->stream_copy) {
3240 ret = init_output_stream_streamcopy(ost);
3248 ret = init_output_bsfs(ost);
3252 ost->initialized = 1;
3254 ret = of_check_init(output_files[ost->file_index]);
3280 OutputStream *ost;
3288 if (!ofilter->ost || ofilter->ost->source_index >= 0)
3295 ofilter->ost->source_index = k;
3311 ost = output_streams[i];
3312 avcodec_close(ost->enc_ctx);
3382 ost = output_streams[i];
3384 if (ost->attachment_filename) {
3387 ost->attachment_filename, ost->file_index, ost->index);
3391 if (ost->filter && !filtergraph_is_simple(ost->filter->graph)) {
3393 av_log(NULL, AV_LOG_INFO, " %s", ost->filter->name);
3395 av_log(NULL, AV_LOG_INFO, " (graph %d)", ost->filter->graph->index);
3397 av_log(NULL, AV_LOG_INFO, " -> Stream #%d:%d (%s)\n", ost->file_index,
3398 ost->index, ost->enc ? ost->enc->name : "?");
3403 input_streams[ost->source_index]->file_index,
3404 input_streams[ost->source_index]->st->index,
3405 ost->file_index,
3406 ost->index);
3407 if (ost->sync_ist != input_streams[ost->source_index])
3409 ost->sync_ist->file_index,
3410 ost->sync_ist->st->index);
3411 if (ost->stream_copy)
3414 const AVCodec *in_codec = input_streams[ost->source_index]->dec;
3415 const AVCodec *out_codec = ost->enc;
3463 OutputStream *ost = output_streams[i];
3464 OutputFile *of = output_files[ost->file_index];
3465 AVFormatContext *os = output_files[ost->file_index]->ctx;
3467 if (ost->finished ||
3470 if (ost->frame_number >= ost->max_frames) {
3495 OutputStream *ost = output_streams[i];
3496 int64_t opts = ost->last_mux_dts == AV_NOPTS_VALUE ? INT64_MIN :
3497 av_rescale_q(ost->last_mux_dts, ost->st->time_base,
3499 if (ost->last_mux_dts == AV_NOPTS_VALUE)
3502 ost->st->index, ost->st->id, ost->initialized, ost->inputs_done, ost->finished);
3504 if (!ost->initialized && !ost->inputs_done)
3505 return ost->unavailable ? NULL : ost;
3507 if (!ost->finished && opts < opts_min) {
3509 ost_min = ost->unavailable ? NULL : ost;
3620 OutputStream *ost = output_streams[i];
3621 ost->enc_ctx->debug = debug;
3961 OutputStream *ost = output_streams[j];
3963 if (ost->source_index == ifile->ist_index + i &&
3964 (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE))
3965 finish_output_stream(ost);
4206 close_output_stream(graph->outputs[i]->ost);
4227 graph->outputs[i]->ost->unavailable = 1;
4239 OutputStream *ost;
4243 ost = choose_output();
4244 if (!ost) {
4254 if (ost->filter && !ost->filter->graph->graph) {
4255 if (ifilter_has_all_input_formats(ost->filter->graph)) {
4256 ret = configure_filtergraph(ost->filter->graph);
4264 if (ost->filter && ost->filter->graph->graph) {
4286 if (av_buffersink_get_type(ost->filter->filter) == AVMEDIA_TYPE_AUDIO)
4287 init_output_stream_wrapper(ost, NULL, 1);
4289 if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0)
4293 } else if (ost->filter) {
4295 for (i = 0; i < ost->filter->graph->nb_inputs; i++) {
4296 InputFilter *ifilter = ost->filter->graph->inputs[i];
4303 ost->inputs_done = 1;
4307 av_assert0(ost->source_index >= 0);
4308 ist = input_streams[ost->source_index];
4314 ost->unavailable = 1;
4331 OutputStream *ost;
4413 ost = output_streams[i];
4414 if (ost->encoding_needed) {
4415 av_freep(&ost->enc_ctx->stats_in);
4417 total_packets_written += ost->packets_written;
4418 if (!ost->packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM)) {
4451 ost = output_streams[i];
4452 if (ost) {
4453 if (ost->logfile) {
4454 if (fclose(ost->logfile))
4458 ost->logfile = NULL;
4460 av_freep(&ost->forced_kf_pts);
4461 av_freep(&ost->apad);
4462 av_freep(&ost->disposition);
4463 av_dict_free(&ost->encoder_opts);
4464 av_dict_free(&ost->sws_dict);
4465 av_dict_free(&ost->swr_opts);