fftools/ffmpeg_filter: refactor setting input timebase

Treat it analogously to stream parameters like format/dimensions/etc.
This is functionally different from previous code in 2 ways:
* for non-CFR video, the frame timebase (set by the decoder) is used
  rather than the demuxer timebase
* for sub2video, AV_TIME_BASE_Q is used, which is hardcoded by the
  subtitle decoding API

These changes should avoid unnecessary and potentially lossy timestamp
conversions from decoder timebase into the demuxer one.

Changes the timebases used in sub2video tests.
release/7.0
Anton Khirnov 11 months ago
parent ddaedde7a8
commit daca5d1241
  1. 17
      fftools/ffmpeg_filter.c
  2. 182
      tests/ref/fate/sub2video_basic
  3. 8
      tests/ref/fate/sub2video_time_limited

@ -148,6 +148,8 @@ typedef struct InputFilterPriv {
// fallback parameters to use when no input is ever sent // fallback parameters to use when no input is ever sent
struct { struct {
AVRational time_base;
int format; int format;
int width; int width;
@ -696,6 +698,8 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist)
palettes for all rectangles are identical or compatible */ palettes for all rectangles are identical or compatible */
ifp->format = AV_PIX_FMT_RGB32; ifp->format = AV_PIX_FMT_RGB32;
ifp->time_base = AV_TIME_BASE_Q;
av_log(fgp, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n", av_log(fgp, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n",
ifp->width, ifp->height); ifp->width, ifp->height);
} }
@ -1469,7 +1473,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
AVFilterContext *last_filter; AVFilterContext *last_filter;
const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
const AVPixFmtDescriptor *desc; const AVPixFmtDescriptor *desc;
InputStream *ist = ifp->ist;
AVRational fr = ifp->opts.framerate; AVRational fr = ifp->opts.framerate;
AVRational sar; AVRational sar;
AVBPrint args; AVBPrint args;
@ -1482,9 +1485,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE)
sub2video_prepare(ifp); sub2video_prepare(ifp);
ifp->time_base = (ifp->opts.flags & IFILTER_FLAG_CFR) ?
av_inv_q(ifp->opts.framerate) : ist->st->time_base;
sar = ifp->sample_aspect_ratio; sar = ifp->sample_aspect_ratio;
if(!sar.den) if(!sar.den)
sar = (AVRational){0,1}; sar = (AVRational){0,1};
@ -1575,8 +1575,6 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
char name[255]; char name[255];
int ret, pad_idx = 0; int ret, pad_idx = 0;
ifp->time_base = (AVRational){ 1, ifp->sample_rate };
av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC);
av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s", av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
ifp->time_base.num, ifp->time_base.den, ifp->time_base.num, ifp->time_base.den,
@ -1804,6 +1802,8 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec)
{ {
InputFilterPriv *ifp = ifp_from_ifilter(ifilter); InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
ifp->fallback.time_base = dec->pkt_timebase;
if (dec->codec_type == AVMEDIA_TYPE_VIDEO) { if (dec->codec_type == AVMEDIA_TYPE_VIDEO) {
ifp->fallback.format = dec->pix_fmt; ifp->fallback.format = dec->pix_fmt;
ifp->fallback.width = dec->width; ifp->fallback.width = dec->width;
@ -1835,6 +1835,10 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr
if (ret < 0) if (ret < 0)
return ret; return ret;
ifp->time_base = (ifp->type == AVMEDIA_TYPE_AUDIO) ? (AVRational){ 1, frame->sample_rate } :
(ifp->opts.flags & IFILTER_FLAG_CFR) ? av_inv_q(ifp->opts.framerate) :
frame->time_base;
ifp->format = frame->format; ifp->format = frame->format;
ifp->width = frame->width; ifp->width = frame->width;
@ -2523,6 +2527,7 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter,
ifp->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; ifp->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio;
ifp->color_space = ifp->fallback.color_space; ifp->color_space = ifp->fallback.color_space;
ifp->color_range = ifp->fallback.color_range; ifp->color_range = ifp->fallback.color_range;
ifp->time_base = ifp->fallback.time_base;
ret = av_channel_layout_copy(&ifp->ch_layout, ret = av_channel_layout_copy(&ifp->ch_layout,
&ifp->fallback.ch_layout); &ifp->fallback.ch_layout);

@ -1,95 +1,95 @@
#tb 0: 1/1000 #tb 0: 1/1000000
#media_type 0: video #media_type 0: video
#codec_id 0: rawvideo #codec_id 0: rawvideo
#dimensions 0: 720x480 #dimensions 0: 720x480
#sar 0: 0/1 #sar 0: 0/1
0, 132499, 132499, 0, 1382400, 0x00000000 0, 132499000, 132499000, 0, 1382400, 0x00000000
0, 132499, 132499, 0, 1382400, 0x8c93c2ba 0, 132499000, 132499000, 0, 1382400, 0x8c93c2ba
0, 137459, 137459, 0, 1382400, 0x00000000 0, 137459000, 137459000, 0, 1382400, 0x00000000
0, 147355, 147355, 0, 1382400, 0xb02e32ca 0, 147355000, 147355000, 0, 1382400, 0xb02e32ca
0, 152088, 152088, 0, 1382400, 0x00000000 0, 152088000, 152088000, 0, 1382400, 0x00000000
0, 180797, 180797, 0, 1382400, 0x83b71116 0, 180797000, 180797000, 0, 1382400, 0x83b71116
0, 183357, 183357, 0, 1382400, 0x00000000 0, 183357000, 183357000, 0, 1382400, 0x00000000
0, 183433, 183433, 0, 1382400, 0x85547fd1 0, 183433000, 183433000, 0, 1382400, 0x85547fd1
0, 185799, 185799, 0, 1382400, 0x00000000 0, 185799000, 185799000, 0, 1382400, 0x00000000
0, 185909, 185909, 0, 1382400, 0x00000000 0, 185909999, 185909999, 0, 1382400, 0x00000000
0, 185910, 185910, 0, 1382400, 0xb6a8f181 0, 185910000, 185910000, 0, 1382400, 0xb6a8f181
0, 188606, 188606, 0, 1382400, 0x00000000 0, 188606000, 188606000, 0, 1382400, 0x00000000
0, 188663, 188663, 0, 1382400, 0xb64d1a2c 0, 188663000, 188663000, 0, 1382400, 0xb64d1a2c
0, 189925, 189925, 0, 1382400, 0x00000000 0, 189925000, 189925000, 0, 1382400, 0x00000000
0, 190014, 190014, 0, 1382400, 0x7b37ecf3 0, 190014000, 190014000, 0, 1382400, 0x7b37ecf3
0, 191675, 191675, 0, 1382400, 0x00000000 0, 191675000, 191675000, 0, 1382400, 0x00000000
0, 199724, 199724, 0, 1382400, 0xdc025bd1 0, 199724000, 199724000, 0, 1382400, 0xdc025bd1
0, 201089, 201089, 0, 1382400, 0x00000000 0, 201089000, 201089000, 0, 1382400, 0x00000000
0, 201175, 201175, 0, 1382400, 0x688b294d 0, 201175000, 201175000, 0, 1382400, 0x688b294d
0, 202733, 202733, 0, 1382400, 0x00000000 0, 202733000, 202733000, 0, 1382400, 0x00000000
0, 202819, 202819, 0, 1382400, 0xa2b33d1b 0, 202819000, 202819000, 0, 1382400, 0xa2b33d1b
0, 204684, 204684, 0, 1382400, 0x00000000 0, 204684000, 204684000, 0, 1382400, 0x00000000
0, 204762, 204762, 0, 1382400, 0xb3e525e3 0, 204762000, 204762000, 0, 1382400, 0xb3e525e3
0, 206730, 206730, 0, 1382400, 0x00000000 0, 206730000, 206730000, 0, 1382400, 0x00000000
0, 206806, 206806, 0, 1382400, 0xaa8fbdd7 0, 206806000, 206806000, 0, 1382400, 0xaa8fbdd7
0, 208637, 208637, 0, 1382400, 0x00000000 0, 208637000, 208637000, 0, 1382400, 0x00000000
0, 208716, 208716, 0, 1382400, 0x7b7f26dd 0, 208716000, 208716000, 0, 1382400, 0x7b7f26dd
0, 209978, 209978, 0, 1382400, 0x00000000 0, 209978000, 209978000, 0, 1382400, 0x00000000
0, 210051, 210051, 0, 1382400, 0x15e2f836 0, 210051000, 210051000, 0, 1382400, 0x15e2f836
0, 211575, 211575, 0, 1382400, 0x00000000 0, 211575000, 211575000, 0, 1382400, 0x00000000
0, 211644, 211644, 0, 1382400, 0x0fee9b0c 0, 211644000, 211644000, 0, 1382400, 0x0fee9b0c
0, 214306, 214306, 0, 1382400, 0x00000000 0, 214306000, 214306000, 0, 1382400, 0x00000000
0, 214380, 214380, 0, 1382400, 0x89d62791 0, 214380000, 214380000, 0, 1382400, 0x89d62791
0, 217144, 217144, 0, 1382400, 0x00000000 0, 217144000, 217144000, 0, 1382400, 0x00000000
0, 217225, 217225, 0, 1382400, 0xa6a9fd74 0, 217225000, 217225000, 0, 1382400, 0xa6a9fd74
0, 219591, 219591, 0, 1382400, 0x00000000 0, 219591000, 219591000, 0, 1382400, 0x00000000
0, 219652, 219652, 0, 1382400, 0x7896178d 0, 219652000, 219652000, 0, 1382400, 0x7896178d
0, 221483, 221483, 0, 1382400, 0x00000000 0, 221483000, 221483000, 0, 1382400, 0x00000000
0, 223531, 223531, 0, 1382400, 0x01751a52 0, 223531000, 223531000, 0, 1382400, 0x01751a52
0, 225863, 225863, 0, 1382400, 0x00000000 0, 225863000, 225863000, 0, 1382400, 0x00000000
0, 227510, 227510, 0, 1382400, 0xa3959c6f 0, 227510000, 227510000, 0, 1382400, 0xa3959c6f
0, 230809, 230809, 0, 1382400, 0x00000000 0, 230809000, 230809000, 0, 1382400, 0x00000000
0, 230872, 230872, 0, 1382400, 0x3d3ea47b 0, 230872000, 230872000, 0, 1382400, 0x3d3ea47b
0, 233033, 233033, 0, 1382400, 0x00000000 0, 233033000, 233033000, 0, 1382400, 0x00000000
0, 233124, 233124, 0, 1382400, 0x593f8b24 0, 233124000, 233124000, 0, 1382400, 0x593f8b24
0, 237220, 237220, 0, 1382400, 0x00000000 0, 237220000, 237220000, 0, 1382400, 0x00000000
0, 237303, 237303, 0, 1382400, 0x171f05ba 0, 237303000, 237303000, 0, 1382400, 0x171f05ba
0, 240033, 240033, 0, 1382400, 0x00000000 0, 240033000, 240033000, 0, 1382400, 0x00000000
0, 240106, 240106, 0, 1382400, 0xb014cdf1 0, 240106000, 240106000, 0, 1382400, 0xb014cdf1
0, 242165, 242165, 0, 1382400, 0x00000000 0, 242165000, 242165000, 0, 1382400, 0x00000000
0, 273556, 273556, 0, 1382400, 0xd918e667 0, 273556000, 273556000, 0, 1382400, 0xd918e667
0, 275217, 275217, 0, 1382400, 0x00000000 0, 275217000, 275217000, 0, 1382400, 0x00000000
0, 295445, 295445, 0, 1382400, 0xc9406331 0, 295445000, 295445000, 0, 1382400, 0xc9406331
0, 296776, 296776, 0, 1382400, 0x00000000 0, 296776000, 296776000, 0, 1382400, 0x00000000
0, 300049, 300049, 0, 1382400, 0xaf08b10d 0, 300049000, 300049000, 0, 1382400, 0xaf08b10d
0, 301949, 301949, 0, 1382400, 0x00000000 0, 301949000, 301949000, 0, 1382400, 0x00000000
0, 302034, 302034, 0, 1382400, 0x00000000 0, 302034999, 302034999, 0, 1382400, 0x00000000
0, 302035, 302035, 0, 1382400, 0x853a9d93 0, 302035000, 302035000, 0, 1382400, 0x853a9d93
0, 303559, 303559, 0, 1382400, 0x00000000 0, 303559000, 303559000, 0, 1382400, 0x00000000
0, 304203, 304203, 0, 1382400, 0x7491a87d 0, 304203000, 304203000, 0, 1382400, 0x7491a87d
0, 305898, 305898, 0, 1382400, 0x00000000 0, 305898000, 305898000, 0, 1382400, 0x00000000
0, 305947, 305947, 0, 1382400, 0xf7383c58 0, 305947000, 305947000, 0, 1382400, 0xf7383c58
0, 307881, 307881, 0, 1382400, 0x00000000 0, 307881000, 307881000, 0, 1382400, 0x00000000
0, 307957, 307957, 0, 1382400, 0xe66be411 0, 307957000, 307957000, 0, 1382400, 0xe66be411
0, 309720, 309720, 0, 1382400, 0x00000000 0, 309720000, 309720000, 0, 1382400, 0x00000000
0, 321295, 321295, 0, 1382400, 0xd6850362 0, 321295000, 321295000, 0, 1382400, 0xd6850362
0, 323263, 323263, 0, 1382400, 0x00000000 0, 323263000, 323263000, 0, 1382400, 0x00000000
0, 323356, 323356, 0, 1382400, 0x3e1ed109 0, 323356000, 323356000, 0, 1382400, 0x3e1ed109
0, 324584, 324584, 0, 1382400, 0x00000000 0, 324584000, 324584000, 0, 1382400, 0x00000000
0, 324640, 324640, 0, 1382400, 0x39c1b7bd 0, 324640000, 324640000, 0, 1382400, 0x39c1b7bd
0, 326403, 326403, 0, 1382400, 0x00000000 0, 326403000, 326403000, 0, 1382400, 0x00000000
0, 327193, 327193, 0, 1382400, 0x35b85f2e 0, 327193000, 327193000, 0, 1382400, 0x35b85f2e
0, 328285, 328285, 0, 1382400, 0x00000000 0, 328285000, 328285000, 0, 1382400, 0x00000000
0, 328360, 328360, 0, 1382400, 0x00000000 0, 328360999, 328360999, 0, 1382400, 0x00000000
0, 328361, 328361, 0, 1382400, 0x83f103e5 0, 328361000, 328361000, 0, 1382400, 0x83f103e5
0, 329885, 329885, 0, 1382400, 0x00000000 0, 329885000, 329885000, 0, 1382400, 0x00000000
0, 329946, 329946, 0, 1382400, 0xbc1ca9b3 0, 329946000, 329946000, 0, 1382400, 0xbc1ca9b3
0, 331106, 331106, 0, 1382400, 0x00000000 0, 331106000, 331106000, 0, 1382400, 0x00000000
0, 331230, 331230, 0, 1382400, 0x94d4a51e 0, 331230000, 331230000, 0, 1382400, 0x94d4a51e
0, 332857, 332857, 0, 1382400, 0x00000000 0, 332857000, 332857000, 0, 1382400, 0x00000000
0, 332924, 332924, 0, 1382400, 0xf88cdfde 0, 332924000, 332924000, 0, 1382400, 0xf88cdfde
0, 334687, 334687, 0, 1382400, 0x00000000 0, 334687000, 334687000, 0, 1382400, 0x00000000
0, 342600, 342600, 0, 1382400, 0xdd51423b 0, 342600000, 342600000, 0, 1382400, 0xdd51423b
0, 344431, 344431, 0, 1382400, 0x00000000 0, 344431000, 344431000, 0, 1382400, 0x00000000
0, 346771, 346771, 0, 1382400, 0x08259fa4 0, 346771000, 346771000, 0, 1382400, 0x08259fa4
0, 348329, 348329, 0, 1382400, 0x00000000 0, 348329000, 348329000, 0, 1382400, 0x00000000
0, 357640, 357640, 0, 1382400, 0x1663fa34 0, 357640000, 357640000, 0, 1382400, 0x1663fa34
0, 359767, 359767, 0, 1382400, 0x00000000 0, 359767000, 359767000, 0, 1382400, 0x00000000
0, 359834, 359834, 0, 1382400, 0xda2ceb55 0, 359834000, 359834000, 0, 1382400, 0xda2ceb55
0, 361096, 361096, 0, 1382400, 0x00000000 0, 361096000, 361096000, 0, 1382400, 0x00000000

@ -1,8 +1,8 @@
#tb 0: 1/90000 #tb 0: 1/1000000
#media_type 0: video #media_type 0: video
#codec_id 0: rawvideo #codec_id 0: rawvideo
#dimensions 0: 1920x1080 #dimensions 0: 1920x1080
#sar 0: 0/1 #sar 0: 0/1
0, 6072, 6072, 0, 8294400, 0x00000000 0, 67467, 67467, 0, 8294400, 0x00000000
0, 6072, 6072, 0, 8294400, 0xa87c518f 0, 67467, 67467, 0, 8294400, 0xa87c518f
0, 36101, 36101, 0, 8294400, 0xa87c518f 0, 401132, 401132, 0, 8294400, 0xa87c518f

Loading…
Cancel
Save