mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
ffmpeg: use buffersink accessors.
This commit is contained in:
parent
dbe9dbed31
commit
d9b311d44c
46
ffmpeg.c
46
ffmpeg.c
@ -1014,6 +1014,7 @@ static void do_video_out(OutputFile *of,
|
|||||||
AVPacket pkt;
|
AVPacket pkt;
|
||||||
AVCodecContext *enc = ost->enc_ctx;
|
AVCodecContext *enc = ost->enc_ctx;
|
||||||
AVCodecParameters *mux_par = ost->st->codecpar;
|
AVCodecParameters *mux_par = ost->st->codecpar;
|
||||||
|
AVRational frame_rate;
|
||||||
int nb_frames, nb0_frames, i;
|
int nb_frames, nb0_frames, i;
|
||||||
double delta, delta0;
|
double delta, delta0;
|
||||||
double duration = 0;
|
double duration = 0;
|
||||||
@ -1024,9 +1025,9 @@ static void do_video_out(OutputFile *of,
|
|||||||
if (ost->source_index >= 0)
|
if (ost->source_index >= 0)
|
||||||
ist = input_streams[ost->source_index];
|
ist = input_streams[ost->source_index];
|
||||||
|
|
||||||
if (filter->inputs[0]->frame_rate.num > 0 &&
|
frame_rate = av_buffersink_get_frame_rate(filter);
|
||||||
filter->inputs[0]->frame_rate.den > 0)
|
if (frame_rate.num > 0 && frame_rate.den > 0)
|
||||||
duration = 1/(av_q2d(filter->inputs[0]->frame_rate) * av_q2d(enc->time_base));
|
duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
|
||||||
|
|
||||||
if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
|
if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num)
|
||||||
duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
|
duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base)));
|
||||||
@ -1416,7 +1417,7 @@ static int reap_filters(int flush)
|
|||||||
av_log(NULL, AV_LOG_WARNING,
|
av_log(NULL, AV_LOG_WARNING,
|
||||||
"Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
|
"Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret));
|
||||||
} else if (flush && ret == AVERROR_EOF) {
|
} else if (flush && ret == AVERROR_EOF) {
|
||||||
if (filter->inputs[0]->type == AVMEDIA_TYPE_VIDEO)
|
if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO)
|
||||||
do_video_out(of, ost, NULL, AV_NOPTS_VALUE);
|
do_video_out(of, ost, NULL, AV_NOPTS_VALUE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1427,25 +1428,26 @@ static int reap_filters(int flush)
|
|||||||
}
|
}
|
||||||
if (filtered_frame->pts != AV_NOPTS_VALUE) {
|
if (filtered_frame->pts != AV_NOPTS_VALUE) {
|
||||||
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
|
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
|
||||||
|
AVRational filter_tb = av_buffersink_get_time_base(filter);
|
||||||
AVRational tb = enc->time_base;
|
AVRational tb = enc->time_base;
|
||||||
int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
|
int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
|
||||||
|
|
||||||
tb.den <<= extra_bits;
|
tb.den <<= extra_bits;
|
||||||
float_pts =
|
float_pts =
|
||||||
av_rescale_q(filtered_frame->pts, filter->inputs[0]->time_base, tb) -
|
av_rescale_q(filtered_frame->pts, filter_tb, tb) -
|
||||||
av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
|
av_rescale_q(start_time, AV_TIME_BASE_Q, tb);
|
||||||
float_pts /= 1 << extra_bits;
|
float_pts /= 1 << extra_bits;
|
||||||
// avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers
|
// avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers
|
||||||
float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
|
float_pts += FFSIGN(float_pts) * 1.0 / (1<<17);
|
||||||
|
|
||||||
filtered_frame->pts =
|
filtered_frame->pts =
|
||||||
av_rescale_q(filtered_frame->pts, filter->inputs[0]->time_base, enc->time_base) -
|
av_rescale_q(filtered_frame->pts, filter_tb, enc->time_base) -
|
||||||
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
|
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
|
||||||
}
|
}
|
||||||
//if (ost->source_index >= 0)
|
//if (ost->source_index >= 0)
|
||||||
// *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold
|
// *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold
|
||||||
|
|
||||||
switch (filter->inputs[0]->type) {
|
switch (av_buffersink_get_type(filter)) {
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
if (!ost->frame_aspect_ratio.num)
|
if (!ost->frame_aspect_ratio.num)
|
||||||
enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;
|
enc->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;
|
||||||
@ -3142,19 +3144,19 @@ static int init_output_stream_encode(OutputStream *ost)
|
|||||||
|
|
||||||
switch (enc_ctx->codec_type) {
|
switch (enc_ctx->codec_type) {
|
||||||
case AVMEDIA_TYPE_AUDIO:
|
case AVMEDIA_TYPE_AUDIO:
|
||||||
enc_ctx->sample_fmt = ost->filter->filter->inputs[0]->format;
|
enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter);
|
||||||
if (dec_ctx)
|
if (dec_ctx)
|
||||||
enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
|
enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
|
||||||
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
|
av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3);
|
||||||
enc_ctx->sample_rate = ost->filter->filter->inputs[0]->sample_rate;
|
enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter);
|
||||||
enc_ctx->channel_layout = ost->filter->filter->inputs[0]->channel_layout;
|
enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter);
|
||||||
enc_ctx->channels = avfilter_link_get_channels(ost->filter->filter->inputs[0]);
|
enc_ctx->channels = av_buffersink_get_channels(ost->filter->filter);
|
||||||
enc_ctx->time_base = (AVRational){ 1, enc_ctx->sample_rate };
|
enc_ctx->time_base = (AVRational){ 1, enc_ctx->sample_rate };
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
enc_ctx->time_base = av_inv_q(ost->frame_rate);
|
enc_ctx->time_base = av_inv_q(ost->frame_rate);
|
||||||
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
|
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
|
||||||
enc_ctx->time_base = ost->filter->filter->inputs[0]->time_base;
|
enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
|
||||||
if ( av_q2d(enc_ctx->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH
|
if ( av_q2d(enc_ctx->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH
|
||||||
&& (video_sync_method == VSYNC_CFR || video_sync_method == VSYNC_VSCFR || (video_sync_method == VSYNC_AUTO && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){
|
&& (video_sync_method == VSYNC_CFR || video_sync_method == VSYNC_VSCFR || (video_sync_method == VSYNC_AUTO && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){
|
||||||
av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not efficiently supporting it.\n"
|
av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not efficiently supporting it.\n"
|
||||||
@ -3165,27 +3167,27 @@ static int init_output_stream_encode(OutputStream *ost)
|
|||||||
AV_TIME_BASE_Q,
|
AV_TIME_BASE_Q,
|
||||||
enc_ctx->time_base);
|
enc_ctx->time_base);
|
||||||
|
|
||||||
enc_ctx->width = ost->filter->filter->inputs[0]->w;
|
enc_ctx->width = av_buffersink_get_w(ost->filter->filter);
|
||||||
enc_ctx->height = ost->filter->filter->inputs[0]->h;
|
enc_ctx->height = av_buffersink_get_h(ost->filter->filter);
|
||||||
enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =
|
enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =
|
||||||
ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option
|
ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option
|
||||||
av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) :
|
av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) :
|
||||||
ost->filter->filter->inputs[0]->sample_aspect_ratio;
|
av_buffersink_get_sample_aspect_ratio(ost->filter->filter);
|
||||||
if (!strncmp(ost->enc->name, "libx264", 7) &&
|
if (!strncmp(ost->enc->name, "libx264", 7) &&
|
||||||
enc_ctx->pix_fmt == AV_PIX_FMT_NONE &&
|
enc_ctx->pix_fmt == AV_PIX_FMT_NONE &&
|
||||||
ost->filter->filter->inputs[0]->format != AV_PIX_FMT_YUV420P)
|
av_buffersink_get_format(ost->filter->filter) != AV_PIX_FMT_YUV420P)
|
||||||
av_log(NULL, AV_LOG_WARNING,
|
av_log(NULL, AV_LOG_WARNING,
|
||||||
"No pixel format specified, %s for H.264 encoding chosen.\n"
|
"No pixel format specified, %s for H.264 encoding chosen.\n"
|
||||||
"Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
|
"Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
|
||||||
av_get_pix_fmt_name(ost->filter->filter->inputs[0]->format));
|
av_get_pix_fmt_name(av_buffersink_get_format(ost->filter->filter)));
|
||||||
if (!strncmp(ost->enc->name, "mpeg2video", 10) &&
|
if (!strncmp(ost->enc->name, "mpeg2video", 10) &&
|
||||||
enc_ctx->pix_fmt == AV_PIX_FMT_NONE &&
|
enc_ctx->pix_fmt == AV_PIX_FMT_NONE &&
|
||||||
ost->filter->filter->inputs[0]->format != AV_PIX_FMT_YUV420P)
|
av_buffersink_get_format(ost->filter->filter) != AV_PIX_FMT_YUV420P)
|
||||||
av_log(NULL, AV_LOG_WARNING,
|
av_log(NULL, AV_LOG_WARNING,
|
||||||
"No pixel format specified, %s for MPEG-2 encoding chosen.\n"
|
"No pixel format specified, %s for MPEG-2 encoding chosen.\n"
|
||||||
"Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
|
"Use -pix_fmt yuv420p for compatibility with outdated media players.\n",
|
||||||
av_get_pix_fmt_name(ost->filter->filter->inputs[0]->format));
|
av_get_pix_fmt_name(av_buffersink_get_format(ost->filter->filter)));
|
||||||
enc_ctx->pix_fmt = ost->filter->filter->inputs[0]->format;
|
enc_ctx->pix_fmt = av_buffersink_get_format(ost->filter->filter);
|
||||||
if (dec_ctx)
|
if (dec_ctx)
|
||||||
enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
|
enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample,
|
||||||
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
|
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
|
||||||
@ -3268,8 +3270,8 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
|
|||||||
!av_dict_get(ost->encoder_opts, "ab", NULL, 0))
|
!av_dict_get(ost->encoder_opts, "ab", NULL, 0))
|
||||||
av_dict_set(&ost->encoder_opts, "b", "128000", 0);
|
av_dict_set(&ost->encoder_opts, "b", "128000", 0);
|
||||||
|
|
||||||
if (ost->filter && ost->filter->filter->inputs[0]->hw_frames_ctx) {
|
if (ost->filter && av_buffersink_get_hw_frames_ctx(ost->filter->filter)) {
|
||||||
ost->enc_ctx->hw_frames_ctx = av_buffer_ref(ost->filter->filter->inputs[0]->hw_frames_ctx);
|
ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter));
|
||||||
if (!ost->enc_ctx->hw_frames_ctx)
|
if (!ost->enc_ctx->hw_frames_ctx)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
@ -1079,15 +1079,15 @@ int configure_filtergraph(FilterGraph *fg)
|
|||||||
* make sure they stay the same if the filtergraph is reconfigured later */
|
* make sure they stay the same if the filtergraph is reconfigured later */
|
||||||
for (i = 0; i < fg->nb_outputs; i++) {
|
for (i = 0; i < fg->nb_outputs; i++) {
|
||||||
OutputFilter *ofilter = fg->outputs[i];
|
OutputFilter *ofilter = fg->outputs[i];
|
||||||
AVFilterLink *link = ofilter->filter->inputs[0];
|
AVFilterContext *sink = ofilter->filter;
|
||||||
|
|
||||||
ofilter->format = link->format;
|
ofilter->format = av_buffersink_get_format(sink);
|
||||||
|
|
||||||
ofilter->width = link->w;
|
ofilter->width = av_buffersink_get_w(sink);
|
||||||
ofilter->height = link->h;
|
ofilter->height = av_buffersink_get_h(sink);
|
||||||
|
|
||||||
ofilter->sample_rate = link->sample_rate;
|
ofilter->sample_rate = av_buffersink_get_sample_rate(sink);
|
||||||
ofilter->channel_layout = link->channel_layout;
|
ofilter->channel_layout = av_buffersink_get_channel_layout(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
fg->reconfiguration = 1;
|
fg->reconfiguration = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user