Mercurial > hg > nginx-tests
annotate mp4_start_key_frame.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 2a0a6035a1af |
children |
rev | line source |
---|---|
1746
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for the mp4_start_key_frame directive. |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT http_content /; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffprobe') |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->has_daemon('ffmpeg') |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 listen 127.0.0.1:8080; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server_name localhost; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 location / { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 mp4; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location /force/ { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 mp4; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 mp4_start_key_frame on; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 alias %%TESTDIR%%/; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 EOF |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 plan(skip_all => 'no lavfi') |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 system('ffmpeg -nostdin -loglevel quiet -y ' |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 . '-pix_fmt yuv420p -g 15 -c:v libx264 ' |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 . "${\($t->testdir())}/test.mp4") == 0 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 or die "Can't create mp4 file: $!"; |
1937
2a0a6035a1af
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1746
diff
changeset
|
64 $t->run()->plan(4); |
1746
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 ############################################################################### |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 # baseline durations |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 my $test_uri = '/test.mp4'; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 is(durations($t, 2.0, 4.0), '2.00', 'start at key frame'); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 isnt(durations($t, 2.1, 4.0), '1.90', 'start off key frame'); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 # with forced start at key frame |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $test_uri = '/force/test.mp4'; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 is(durations($t, 2.0, 4.0), '2.00', 'start at key frame force'); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 is(durations($t, 2.1, 4.0), '1.90', 'start off key frame force'); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 ############################################################################### |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 sub durations { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 my ($t, $start, $end) = @_; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 my $path = $t->{_testdir} . '/frag.mp4'; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 my $uri = $test_uri; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 if (defined $start) { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $uri .= "?start=$start"; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 if (defined $end) { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 $uri .= "&end=$end"; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 } elsif (defined $end) { |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 $uri .= "?end=$end"; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 $t->write_file('frag.mp4', http_content(http_get($uri))); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my $r = `ffprobe -show_streams $path 2>/dev/null`; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 Test::Nginx::log_core('||', $r); |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 sprintf "%.2f", $r =~ /duration=(\d+\.\d+)/g; |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 } |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
be8d5213d6b9
Tests: mp4_start_key_frame tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 ############################################################################### |