History

fftools/sync_queue: use timebase from input frames/packets

They are always properly set now. Avoid a separate timebase-setting call, which duplicates the knowledge of the timebase being used.

Anton Khirnov committed 3 years ago

Commit 090950f1 parent 87e9f5a4 files · +22 −29Browse files

Unified · Split

4 files
  1. fftools/ffmpeg.c +0 −3
  2. fftools/ffmpeg_mux.c +0 −3
  3. fftools/sync_queue.c +22 −17
  4. fftools/sync_queue.h +0 −6
fftools/ffmpeg.c+0−3
@@ -3194,9 +3194,6 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) · 3193 unmodified lines
31943194 if (ost->bitexact)
31953195 enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
31963196
3197− if (ost->sq_idx_encode >= 0)
3198− sq_set_tb(of->sq_encode, ost->sq_idx_encode, enc_ctx->time_base);
3199−
32003197 ost->mux_timebase = enc_ctx->time_base;
32013198
32023199 return 0;
fftools/ffmpeg_mux.c+0−3
@@ -586,9 +586,6 @@ int of_stream_init(OutputFile *of, OutputStream *ost) · 585 unmodified lines
586586 MuxStream *ms = ms_from_ost(ost);
587587 int ret;
588588
589− if (ost->sq_idx_mux >= 0)
590− sq_set_tb(mux->sq_mux, ost->sq_idx_mux, ost->mux_timebase);
591−
592589 /* initialize bitstream filters for the output stream
593590 * needs to be done here, because the codec id for streamcopy is not
594591 * known until now */
fftools/sync_queue.c+22−17
@@ -84,6 +84,26 @@ static int frame_null(const SyncQueue *sq, SyncQueueFrame frame) · 83 unmodified lines
8484 return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL);
8585 }
8686
87+static void tb_update(const SyncQueue *sq, SyncQueueStream *st,
88+ const SyncQueueFrame frame)
89+{
90+ AVRational tb = (sq->type == SYNC_QUEUE_PACKETS) ?
91+ frame.p->time_base : frame.f->time_base;
92+
93+ av_assert0(tb.num > 0 && tb.den > 0);
94+
95+ if (tb.num == st->tb.num && tb.den == st->tb.den)
96+ return;
97+
98+ // timebase should not change after the first frame
99+ av_assert0(!av_fifo_can_read(st->fifo));
100+
101+ if (st->head_ts != AV_NOPTS_VALUE)
102+ st->head_ts = av_rescale_q(st->head_ts, st->tb, tb);
103+
104+ st->tb = tb;
105+}
106+
87107 static void finish_stream(SyncQueue *sq, unsigned int stream_idx)
88108 {
89109 SyncQueueStream *st = &sq->streams[stream_idx];
@@ -241,8 +261,6 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) · 151 unmodified lines
241261 av_assert0(stream_idx < sq->nb_streams);
242262 st = &sq->streams[stream_idx];
243263
244− av_assert0(st->tb.num > 0 && st->tb.den > 0);
245−
246264 if (frame_null(sq, frame)) {
247265 finish_stream(sq, stream_idx);
248266 return 0;
@@ -250,6 +268,8 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) · 1 unmodified line
250268 if (st->finished)
251269 return AVERROR_EOF;
252270
271+ tb_update(sq, st, frame);
272+
253273 ret = objpool_get(sq->pool, (void**)&dst);
254274 if (ret < 0)
255275 return ret;
@@ -375,21 +395,6 @@ int sq_add_stream(SyncQueue *sq, int limiting) · 119 unmodified lines
375395 return sq->nb_streams++;
376396 }
377397
378−void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb)
379−{
380− SyncQueueStream *st;
381−
382− av_assert0(stream_idx < sq->nb_streams);
383− st = &sq->streams[stream_idx];
384−
385− av_assert0(!av_fifo_can_read(st->fifo));
386−
387− if (st->head_ts != AV_NOPTS_VALUE)
388− st->head_ts = av_rescale_q(st->head_ts, st->tb, tb);
389−
390− st->tb = tb;
391−}
392−
393398 void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames)
394399 {
395400 SyncQueueStream *st;
fftools/sync_queue.h+0−6
@@ -59,12 +59,6 @@ void sq_free(SyncQueue **sq); · 58 unmodified lines
5959 */
6060 int sq_add_stream(SyncQueue *sq, int limiting);
6161
62−/**
63− * Set the timebase for the stream with index stream_idx. Should be called
64− * before sending any frames for this stream.
65− */
66−void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb);
67−
6862 /**
6963 * Limit the number of output frames for stream with index stream_idx
7064 * to max_frames.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t