Mercurial > hg > nginx-tests
annotate mp4.t @ 1542:451e787aad76
Tests: reworked libgd version detection.
The "libgd-config" binary is deprecated in recent versions and may not exist
or have unexpected output. More, it may not present within older versions,
as well, if installed separately, which previously broke test assumptions.
The fix is change the fallback to skip tests. In addition, recent Perl GD
module (2.57) started to export libgd version, which is now also consulted.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 13 Jan 2020 18:15:35 +0300 |
parents | 1220f0055135 |
children | 809d67d48d21 |
rev | line source |
---|---|
384 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for mp4 module. | |
7 # Ensures that requested stream duration is given with sane accuracy. | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
389
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffprobe') |
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
27 ->has_daemon('ffmpeg') |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
384 | 29 |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
384 | 42 server_name localhost; |
43 | |
44 location / { | |
45 mp4; | |
46 } | |
47 } | |
48 } | |
49 | |
50 EOF | |
51 | |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
52 plan(skip_all => 'no lavfi') |
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
53 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
1268
1923461981c9
Tests: prevent broken terminal after tc[gs]etattr ffmpeg race.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
54 system('ffmpeg -nostdin -loglevel quiet -y ' |
384 | 55 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
56 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' | |
57 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' | |
58 . "${\($t->testdir())}/test.mp4") == 0 | |
59 or die "Can't create mp4 file: $!"; | |
1268
1923461981c9
Tests: prevent broken terminal after tc[gs]etattr ffmpeg race.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
60 system('ffmpeg -nostdin -loglevel quiet -y ' |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
61 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
62 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
63 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
64 . '-movflags +faststart ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
65 . "${\($t->testdir())}/no_mdat.mp4") == 0 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
66 or die "Can't create mp4 file: $!"; |
384 | 67 |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
68 $t->run()->plan(26); |
384 | 69 |
70 ############################################################################### | |
71 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
72 my $test_uri = '/test.mp4'; |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
73 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
74 again: |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
75 |
384 | 76 is(durations($t, 0.0), '10.0 20.0', 'start zero'); |
77 is(durations($t, 2), '8.0 18.0', 'start integer'); | |
78 is(durations($t, 7.1), '2.9 12.9', 'start float'); | |
79 | |
80 is(durations($t, 6, 9), '3.0 3.0', 'start end integer'); | |
81 is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float'); | |
82 | |
83 is(durations($t, undef, 9), '9.0 9.0', 'end integer'); | |
84 is(durations($t, undef, 5.6), '5.6 5.6', 'end float'); | |
85 | |
86 # invalid range results in ignoring end argument | |
87 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
88 like(http_head("$test_uri?start=1&end=1"), qr/200 OK/, 'zero range'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
89 like(http_head("$test_uri?start=1&end=0"), qr/200 OK/, 'negative range'); |
384 | 90 |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
91 # start/end values exceeding track/file duration |
384 | 92 |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
93 unlike(http_head("$test_uri?end=11"), qr!HTTP/1.1 500!, |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
94 'end beyond short track'); |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
95 unlike(http_head("$test_uri?end=21"), qr!HTTP/1.1 500!, 'end beyond EOF'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
96 unlike(http_head("$test_uri?start=11"), qr!HTTP/1.1 500!, |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
97 'start beyond short track'); |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
98 like(http_head("$test_uri?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
99 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
100 $test_uri = '/no_mdat.mp4', goto again unless $test_uri eq '/no_mdat.mp4'; |
384 | 101 |
102 ############################################################################### | |
103 | |
104 sub durations { | |
105 my ($t, $start, $end) = @_; | |
106 my $path = $t->{_testdir} . '/frag.mp4'; | |
107 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
108 my $uri = $test_uri; |
384 | 109 if (defined $start) { |
110 $uri .= "?start=$start"; | |
111 if (defined $end) { | |
112 $uri .= "&end=$end"; | |
113 } | |
114 | |
115 } elsif (defined $end) { | |
116 $uri .= "?end=$end"; | |
117 } | |
118 | |
119 $t->write_file('frag.mp4', Test::Nginx::http_content(http_get($uri))); | |
120 | |
121 my $r = `ffprobe -show_streams $path 2>/dev/null`; | |
122 Test::Nginx::log_core('||', $r); | |
123 sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g; | |
124 } | |
125 | |
126 ############################################################################### |