mirror of https://git.ffmpeg.org/ffmpeg.git
fftools/ffmpeg: attach filter framerate to frames
This way the encoder does not need to reach backward into the filter.
This commit is contained in:
parent
9630341073
commit
568d414074
|
@ -655,6 +655,8 @@ typedef struct FrameData {
|
|||
uint64_t idx;
|
||||
int64_t pts;
|
||||
AVRational tb;
|
||||
|
||||
AVRational frame_rate_filter;
|
||||
} FrameData;
|
||||
|
||||
extern InputFile **input_files;
|
||||
|
|
|
@ -217,8 +217,10 @@ int enc_open(OutputStream *ost, AVFrame *frame)
|
|||
case AVMEDIA_TYPE_VIDEO: {
|
||||
AVRational fr = ost->frame_rate;
|
||||
|
||||
if (!fr.num)
|
||||
fr = av_buffersink_get_frame_rate(ost->filter->filter);
|
||||
if (!fr.num && frame) {
|
||||
FrameData *fd = frame_data(frame);
|
||||
fr = fd->frame_rate_filter;
|
||||
}
|
||||
if (!fr.num && !ost->max_frame_rate.num) {
|
||||
fr = (AVRational){25, 1};
|
||||
av_log(ost, AV_LOG_WARNING,
|
||||
|
@ -1024,17 +1026,18 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame)
|
|||
int ret;
|
||||
Encoder *e = ost->enc;
|
||||
AVCodecContext *enc = ost->enc_ctx;
|
||||
AVRational frame_rate;
|
||||
int64_t nb_frames, nb_frames_prev, i;
|
||||
double duration = 0;
|
||||
AVFilterContext *filter = ost->filter->filter;
|
||||
|
||||
if (frame)
|
||||
if (frame) {
|
||||
FrameData *fd = frame_data(frame);
|
||||
|
||||
duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base));
|
||||
|
||||
frame_rate = av_buffersink_get_frame_rate(filter);
|
||||
if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0)
|
||||
duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base));
|
||||
if (duration <= 0 &&
|
||||
fd->frame_rate_filter.num > 0 && fd->frame_rate_filter.den > 0)
|
||||
duration = 1 / (av_q2d(fd->frame_rate_filter) * av_q2d(enc->time_base));
|
||||
}
|
||||
|
||||
video_sync_process(of, ost, frame, duration,
|
||||
&nb_frames, &nb_frames_prev);
|
||||
|
|
|
@ -1711,6 +1711,16 @@ int reap_filters(int flush)
|
|||
tb.num, tb.den);
|
||||
}
|
||||
|
||||
if (ost->type == AVMEDIA_TYPE_VIDEO) {
|
||||
FrameData *fd = frame_data(filtered_frame);
|
||||
if (!fd) {
|
||||
av_frame_unref(filtered_frame);
|
||||
report_and_exit(AVERROR(ENOMEM));
|
||||
}
|
||||
|
||||
fd->frame_rate_filter = av_buffersink_get_frame_rate(filter);
|
||||
}
|
||||
|
||||
enc_frame(ost, filtered_frame);
|
||||
av_frame_unref(filtered_frame);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue