aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-04-23 20:34:59 +0200
committerAnton Khirnov <anton@khirnov.net>2013-05-03 09:57:13 +0200
commitb4a5a292274f904f404f40f826c51e6fc9cfb8fe (patch)
tree1cf4de6cb5af7516f7c1ccfc5a6d9b819dc32d12
parente3b225a4fe0ff1e64a220b757c6f0a5cf9258521 (diff)
downloadffmpeg-b4a5a292274f904f404f40f826c51e6fc9cfb8fe.tar.gz
avconv: improve -re implementation
Integrate the code in the packet reading function, instead of inserting sleeps in many places. This is simpler to follow and should work better.
-rw-r--r--avconv.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/avconv.c b/avconv.c
index 3b4d2f674d..9dbff46420 100644
--- a/avconv.c
+++ b/avconv.c
@@ -1037,16 +1037,6 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
ost->st->codec->frame_number++;
}
-static void rate_emu_sleep(InputStream *ist)
-{
- if (input_files[ist->file_index]->rate_emu) {
- int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
- int64_t now = av_gettime() - ist->start;
- if (pts > now)
- av_usleep(pts - now);
- }
-}
-
int guess_input_channel_layout(InputStream *ist)
{
AVCodecContext *dec = ist->st->codec;
@@ -1095,8 +1085,6 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
pkt->pts = AV_NOPTS_VALUE;
}
- rate_emu_sleep(ist);
-
resample_changed = ist->resample_sample_fmt != decoded_frame->format ||
ist->resample_channels != avctx->channels ||
ist->resample_channel_layout != decoded_frame->channel_layout ||
@@ -1190,8 +1178,6 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);
#endif
- rate_emu_sleep(ist);
-
if (ist->st->sample_aspect_ratio.num)
decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
@@ -1251,8 +1237,6 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
if (!*got_output)
return ret;
- rate_emu_sleep(ist);
-
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
@@ -1340,7 +1324,6 @@ static int output_packet(InputStream *ist, const AVPacket *pkt)
/* handle stream copy */
if (!ist->decoding_needed) {
- rate_emu_sleep(ist);
ist->last_dts = ist->next_dts;
switch (ist->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
@@ -2047,6 +2030,17 @@ static int get_input_packet_mt(InputFile *f, AVPacket *pkt)
static int get_input_packet(InputFile *f, AVPacket *pkt)
{
+ if (f->rate_emu) {
+ int i;
+ for (i = 0; i < f->nb_streams; i++) {
+ InputStream *ist = input_streams[f->ist_index + i];
+ int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
+ int64_t now = av_gettime() - ist->start;
+ if (pts > now)
+ return AVERROR(EAGAIN);
+ }
+ }
+
#if HAVE_PTHREADS
if (nb_input_files > 1)
return get_input_packet_mt(f, pkt);