Commit 6e983902 authored by Anton Khirnov's avatar Anton Khirnov

avconv: reduce overloading for InputStream.pts.

It currently has different meanings at different times (dts of the last
read packet/pts of the last decoded frame). Reduce obfuscation by
storing pts of the decoded frame in the frame itself.
parent 3101bb66
...@@ -866,11 +866,10 @@ static void choose_pixel_fmt(AVStream *st, AVCodec *codec) ...@@ -866,11 +866,10 @@ static void choose_pixel_fmt(AVStream *st, AVCodec *codec)
} }
static double static double
get_sync_ipts(const OutputStream *ost) get_sync_ipts(const OutputStream *ost, int64_t pts)
{ {
const InputStream *ist = ost->sync_ist;
OutputFile *of = &output_files[ost->file_index]; OutputFile *of = &output_files[ost->file_index];
return (double)(ist->pts - of->start_time) / AV_TIME_BASE; return (double)(pts - of->start_time) / AV_TIME_BASE;
} }
static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
...@@ -1094,7 +1093,7 @@ need_realloc: ...@@ -1094,7 +1093,7 @@ need_realloc:
} }
if (audio_sync_method) { if (audio_sync_method) {
double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts - double delta = get_sync_ipts(ost, ist->pts) * enc->sample_rate - ost->sync_opts -
av_fifo_size(ost->fifo) / (enc->channels * osize); av_fifo_size(ost->fifo) / (enc->channels * osize);
int idelta = delta * dec->sample_rate / enc->sample_rate; int idelta = delta * dec->sample_rate / enc->sample_rate;
int byte_delta = idelta * isize * dec->channels; int byte_delta = idelta * isize * dec->channels;
...@@ -1137,7 +1136,7 @@ need_realloc: ...@@ -1137,7 +1136,7 @@ need_realloc:
} }
} }
} else } else
ost->sync_opts = lrintf(get_sync_ipts(ost) * enc->sample_rate) - ost->sync_opts = lrintf(get_sync_ipts(ost, ist->pts) * enc->sample_rate) -
av_fifo_size(ost->fifo) / (enc->channels * osize); // FIXME wrong av_fifo_size(ost->fifo) / (enc->channels * osize); // FIXME wrong
if (ost->audio_resample) { if (ost->audio_resample) {
...@@ -1361,7 +1360,7 @@ static void do_video_out(AVFormatContext *s, ...@@ -1361,7 +1360,7 @@ static void do_video_out(AVFormatContext *s,
enc = ost->st->codec; enc = ost->st->codec;
sync_ipts = get_sync_ipts(ost) / av_q2d(enc->time_base); sync_ipts = get_sync_ipts(ost, in_picture->pts) / av_q2d(enc->time_base);
/* by default, we output a single frame */ /* by default, we output a single frame */
nb_frames = 1; nb_frames = 1;
...@@ -1955,7 +1954,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int ...@@ -1955,7 +1954,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
/* no picture yet */ /* no picture yet */
return ret; return ret;
} }
ist->next_dts = ist->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts, ist->next_dts = decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts,
decoded_frame->pkt_dts); decoded_frame->pkt_dts);
if (pkt->duration) if (pkt->duration)
ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q);
...@@ -2011,7 +2010,6 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int ...@@ -2011,7 +2010,6 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
ist->st->codec->pix_fmt); ist->st->codec->pix_fmt);
avfilter_copy_frame_props(fb, decoded_frame); avfilter_copy_frame_props(fb, decoded_frame);
fb->pts = ist->pts;
fb->buf->priv = buf; fb->buf->priv = buf;
fb->buf->free = filter_release_buffer; fb->buf->free = filter_release_buffer;
...@@ -2019,7 +2017,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int ...@@ -2019,7 +2017,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
av_buffersrc_buffer(ost->input_video_filter, fb); av_buffersrc_buffer(ost->input_video_filter, fb);
} else } else
av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame,
ist->pts, decoded_frame->sample_aspect_ratio); decoded_frame->pts, decoded_frame->sample_aspect_ratio);
if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) { if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) {
av_free(buffer_to_free); av_free(buffer_to_free);
...@@ -2034,7 +2032,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int ...@@ -2034,7 +2032,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
if (ost->output_video_filter) if (ost->output_video_filter)
get_filtered_video_frame(ost->output_video_filter, filtered_frame, &ost->picref, &ist_pts_tb); get_filtered_video_frame(ost->output_video_filter, filtered_frame, &ost->picref, &ist_pts_tb);
if (ost->picref) if (ost->picref)
ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); filtered_frame->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
if (ost->picref->video && !ost->frame_aspect_ratio) if (ost->picref->video && !ost->frame_aspect_ratio)
ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect; ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect;
#else #else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment