Skip to content

Commit e5db9ec

Browse files
j0shstronk-dev
andcommitted
Fix pts overflow in fps filter
This was causing some very large segments to be produced if the input had some weird characteristics like missing timestamps. Co-authored-by: Marco van Dijk <marco@stronk.rocks>
1 parent c1eefa6 commit e5db9ec

File tree

3 files changed

+235
-1
lines changed

3 files changed

+235
-1
lines changed

data/missing-dts.ts

1.48 MB
Binary file not shown.

ffmpeg/ffmpeg_test.go

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,3 +2467,237 @@ func TestTranscode_DurationLimit(t *testing.T) {
24672467
_, err = Transcode3(pipeInput, options)
24682468
assert.Nil(t, err)
24692469
}
2470+
2471+
func TestTranscoder_LargeOutputs(t *testing.T) {
2472+
assert := assert.New(t)
2473+
2474+
// An integer overflow bug used to make this test case hang
2475+
// set a strict timeout to ensure it doesn't hang anymore
2476+
timeout := 10 * time.Second
2477+
closeCh := make(chan struct{})
2478+
go func() {
2479+
select {
2480+
case <-time.After(timeout):
2481+
assert.Fail("timed out")
2482+
os.Exit(1)
2483+
case <-closeCh:
2484+
return
2485+
}
2486+
}()
2487+
2488+
run, dir := setupTest(t)
2489+
defer os.RemoveAll(dir)
2490+
prof := P240p30fps16x9
2491+
prof.Framerate = 0 // pass through
2492+
res, err := Transcode3(&TranscodeOptionsIn{
2493+
// this input has some very strange frames with missing timestamps
2494+
Fname: "../data/missing-dts.ts",
2495+
}, []TranscodeOptions{{
2496+
Oname: dir + "/out-passthrough.ts",
2497+
Profile: prof,
2498+
AudioEncoder: ComponentOptions{Name: "drop"},
2499+
}, {
2500+
Oname: dir + "/out-30fps.ts",
2501+
Profile: P240p30fps16x9,
2502+
AudioEncoder: ComponentOptions{Name: "drop"},
2503+
}})
2504+
close(closeCh)
2505+
assert.Nil(err)
2506+
assert.Equal(120, res.Decoded.Frames)
2507+
assert.Equal(116, res.Encoded[0].Frames) // ffmpeg probably drops missing timestamp frames
2508+
assert.Equal(56, res.Encoded[1].Frames)
2509+
cmd := `
2510+
# check input properties to ensure they still have the weird timestamps
2511+
ffprobe -of csv -hide_banner -show_entries frame=pts_time,pkt_dts_time,media_type,pict_type $1/../data/missing-dts.ts 2>&1 | grep video > input.out
2512+
cat <<- 'EOF' > expected-input.out
2513+
frame,video,25994.032000,25994.033000,I,
2514+
frame,video,25994.049000,25994.049000,B,
2515+
frame,video,25994.066000,25994.066000,P,
2516+
frame,video,25994.082000,25994.083000,B,
2517+
frame,video,25994.099000,25994.099000,P,
2518+
frame,video,25994.115000,25994.116000,B,
2519+
frame,video,25994.133000,25994.133000,P,
2520+
frame,video,25994.149000,25994.149000,B,
2521+
frame,video,25994.166000,25994.166000,P,
2522+
frame,video,25994.182000,25994.183000,B,
2523+
frame,video,25994.199000,25994.199000,P,
2524+
frame,video,25994.215000,25994.216000,B,
2525+
frame,video,25994.233000,25994.233000,P,
2526+
frame,video,25994.249000,25994.249000,B,
2527+
frame,video,25994.266000,25994.266000,P,
2528+
frame,video,25994.282000,25994.283000,B,
2529+
frame,video,25994.299000,25994.299000,P,
2530+
frame,video,25994.315000,25994.316000,B,
2531+
frame,video,25994.333000,25994.333000,P,
2532+
frame,video,25994.349000,25994.349000,B,
2533+
frame,video,25994.366000,25994.366000,P,
2534+
frame,video,25994.382000,25994.383000,B,
2535+
frame,video,25994.399000,25994.399000,P,
2536+
frame,video,25994.415000,25994.416000,B,
2537+
frame,video,25994.433000,25994.433000,P,
2538+
frame,video,25994.449000,25994.449000,B,
2539+
frame,video,25994.466000,25994.466000,P,
2540+
frame,video,25994.482000,25994.483000,B,
2541+
frame,video,25994.499000,25994.499000,P,
2542+
frame,video,25994.515000,25994.516000,B,
2543+
frame,video,25994.533000,25994.533000,P,
2544+
frame,video,25994.549000,25994.549000,B,
2545+
frame,video,25994.566000,25994.566000,P,
2546+
frame,video,25994.582000,25994.583000,B,
2547+
frame,video,25994.599000,25994.599000,P,
2548+
frame,video,25994.615000,N/A,B,
2549+
frame,video,25994.633000,25994.633000,P,
2550+
frame,video,25994.649000,25994.649000,B,
2551+
frame,video,N/A,25994.666000,P,
2552+
frame,video,25994.682000,25994.683000,B,
2553+
frame,video,25994.699000,25994.699000,P,
2554+
frame,video,25994.715000,25994.716000,B,
2555+
frame,video,25994.733000,25994.733000,P,
2556+
frame,video,25994.749000,25994.749000,B,
2557+
frame,video,25994.766000,25994.766000,P,
2558+
frame,video,25994.782000,25994.783000,B,
2559+
frame,video,25994.799000,25994.799000,P,
2560+
frame,video,25994.815000,25994.816000,B,
2561+
frame,video,25994.833000,25994.833000,P,
2562+
frame,video,25994.849000,25994.849000,B,
2563+
frame,video,25994.866000,25994.866000,P,
2564+
frame,video,25994.882000,25994.883000,B,
2565+
frame,video,25994.899000,25994.899000,P,
2566+
frame,video,25994.915000,25994.916000,B,
2567+
frame,video,25994.933000,25994.933000,P,
2568+
frame,video,25994.949000,25994.949000,B,
2569+
frame,video,25994.966000,25994.966000,P,
2570+
frame,video,25994.982000,25994.983000,B,
2571+
frame,video,25994.999000,25994.999000,P,
2572+
frame,video,25995.015000,25995.016000,B,
2573+
frame,video,25995.033000,25995.033000,P,
2574+
frame,video,25995.049000,25995.049000,B,
2575+
frame,video,25995.066000,25995.066000,P,
2576+
frame,video,25995.082000,25995.083000,B,
2577+
frame,video,25995.099000,N/A,P,
2578+
frame,video,N/A,25995.116000,B,
2579+
frame,video,25995.133000,25995.133000,P,
2580+
frame,video,25995.149000,25995.149000,B,
2581+
frame,video,25995.166000,25995.166000,P,
2582+
frame,video,25995.182000,25995.183000,B,
2583+
frame,video,25995.199000,25995.199000,P,
2584+
frame,video,25995.215000,N/A,B,
2585+
frame,video,25995.233000,25995.233000,P,
2586+
frame,video,25995.249000,25995.249000,B,
2587+
frame,video,N/A,25995.266000,P,
2588+
frame,video,25995.282000,25995.283000,B,
2589+
frame,video,25995.299000,25995.299000,P,
2590+
frame,video,25995.315000,25995.316000,B,
2591+
frame,video,25995.333000,25995.333000,P,
2592+
frame,video,25995.349000,25995.349000,B,
2593+
frame,video,25995.366000,25995.366000,P,
2594+
frame,video,25995.382000,25995.383000,B,
2595+
frame,video,25995.399000,25995.399000,P,
2596+
frame,video,25995.415000,25995.416000,B,
2597+
frame,video,25995.433000,25995.433000,P,
2598+
frame,video,25995.449000,25995.449000,B,
2599+
frame,video,25995.466000,25995.466000,P,
2600+
frame,video,25995.482000,25995.483000,B,
2601+
frame,video,25995.499000,25995.499000,P,
2602+
frame,video,25995.515000,25995.516000,B,
2603+
frame,video,25995.533000,25995.533000,P,
2604+
frame,video,25995.549000,25995.549000,B,
2605+
frame,video,25995.566000,25995.566000,P,
2606+
frame,video,25995.582000,25995.583000,B,
2607+
frame,video,25995.599000,25995.599000,P,
2608+
frame,video,25995.615000,25995.616000,B,
2609+
frame,video,25995.633000,25995.633000,P,
2610+
frame,video,25995.649000,25995.649000,B,
2611+
frame,video,25995.666000,25995.666000,P,
2612+
frame,video,25995.682000,N/A,B,
2613+
frame,video,25995.699000,25995.699000,P,
2614+
frame,video,25995.715000,25995.716000,B,
2615+
frame,video,N/A,25995.733000,P,
2616+
frame,video,25995.749000,25995.749000,B,
2617+
frame,video,25995.766000,25995.766000,P,
2618+
frame,video,25995.782000,25995.783000,B,
2619+
frame,video,25995.799000,25995.799000,P,
2620+
frame,video,25995.815000,25995.816000,B,
2621+
frame,video,25995.833000,25995.833000,P,
2622+
frame,video,25995.849000,25995.849000,B,
2623+
frame,video,25995.866000,25995.866000,P,
2624+
frame,video,25995.882000,25995.883000,B,
2625+
frame,video,25995.899000,25995.899000,P,
2626+
frame,video,25995.915000,25995.916000,B,
2627+
frame,video,25995.933000,25995.933000,P,
2628+
frame,video,25995.949000,25995.949000,B,
2629+
frame,video,25995.966000,25995.966000,P,
2630+
frame,video,25995.982000,25995.983000,B,
2631+
frame,video,25995.999000,N/A,P,
2632+
frame,video,25996.016000,N/A,P,
2633+
EOF
2634+
2635+
diff -u expected-input.out input.out
2636+
2637+
2638+
# check output
2639+
ls -lha
2640+
#ffprobe -of csv -hide_banner -show_entries frame=pts_time,pkt_dts_time,media_type,pict_type out-30fps.ts
2641+
ffprobe -of csv -hide_banner -show_entries frame=pts_time,pkt_dts_time,media_type,pict_type out-30fps.ts 2>&1 | grep video > output.out
2642+
cat <<- 'EOF2' > expected-output.out
2643+
frame,video,25994.033333,25994.033333,I,
2644+
frame,video,25994.066667,25994.066667,P
2645+
frame,video,25994.100000,25994.100000,B
2646+
frame,video,25994.133333,25994.133333,P
2647+
frame,video,25994.166667,25994.166667,B
2648+
frame,video,25994.200000,25994.200000,B
2649+
frame,video,25994.233333,25994.233333,B
2650+
frame,video,25994.266667,25994.266667,P
2651+
frame,video,25994.300000,25994.300000,B
2652+
frame,video,25994.333333,25994.333333,P
2653+
frame,video,25994.366667,25994.366667,B
2654+
frame,video,25994.400000,25994.400000,B
2655+
frame,video,25994.433333,25994.433333,B
2656+
frame,video,25994.466667,25994.466667,P
2657+
frame,video,25994.500000,25994.500000,B
2658+
frame,video,25994.533333,25994.533333,B
2659+
frame,video,25994.566667,25994.566667,B
2660+
frame,video,25994.600000,25994.600000,P
2661+
frame,video,25994.666667,25994.666667,P,
2662+
frame,video,25994.700000,25994.700000,B,
2663+
frame,video,25994.733333,25994.733333,B,
2664+
frame,video,25994.766667,25994.766667,B,
2665+
frame,video,25994.800000,25994.800000,P,
2666+
frame,video,25994.833333,25994.833333,B,
2667+
frame,video,25994.866667,25994.866667,B,
2668+
frame,video,25994.900000,25994.900000,B,
2669+
frame,video,25994.933333,25994.933333,P,
2670+
frame,video,25994.966667,25994.966667,B,
2671+
frame,video,25995.000000,25995.000000,P,
2672+
frame,video,25995.033333,25995.033333,B,
2673+
frame,video,25995.066667,25995.066667,B,
2674+
frame,video,25995.133333,25995.133333,B,
2675+
frame,video,25995.166667,25995.166667,P,
2676+
frame,video,25995.200000,25995.200000,B,
2677+
frame,video,25995.266667,25995.266667,B,
2678+
frame,video,25995.300000,25995.300000,B,
2679+
frame,video,25995.333333,25995.333333,P,
2680+
frame,video,25995.366667,25995.366667,B,
2681+
frame,video,25995.400000,25995.400000,B,
2682+
frame,video,25995.433333,25995.433333,B,
2683+
frame,video,25995.466667,25995.466667,P,
2684+
frame,video,25995.500000,25995.500000,B,
2685+
frame,video,25995.533333,25995.533333,B,
2686+
frame,video,25995.566667,25995.566667,B,
2687+
frame,video,25995.600000,25995.600000,P,
2688+
frame,video,25995.633333,25995.633333,B,
2689+
frame,video,25995.666667,25995.666667,B,
2690+
frame,video,25995.733333,25995.733333,B,
2691+
frame,video,25995.766667,25995.766667,P,
2692+
frame,video,25995.800000,25995.800000,B,
2693+
frame,video,25995.833333,25995.833333,B,
2694+
frame,video,25995.866667,25995.866667,B,
2695+
frame,video,25995.900000,25995.900000,P,
2696+
frame,video,25995.933333,25995.933333,B,
2697+
frame,video,25995.966667,N/A,B,
2698+
frame,video,25996.000000,N/A,P,
2699+
EOF2
2700+
diff -u expected-output.out output.out
2701+
`
2702+
assert.True(run(cmd))
2703+
}

ffmpeg/filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ int filtergraph_write(AVFrame *inf, struct input_ctx *ictx, struct output_ctx *o
366366

367367
if (inf) {
368368
// Apply the custom pts, then reset for the next output
369-
int old_pts = inf->pts;
369+
int64_t old_pts = inf->pts;
370370
inf->pts = filter->custom_pts;
371371
ret = av_buffersrc_write_frame(filter->src_ctx, inf);
372372
inf->pts = old_pts;

0 commit comments

Comments
 (0)