forked from shaka-project/shaka-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packager_test.py
executable file
·1980 lines (1681 loc) · 74.1 KB
/
packager_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
#
# Copyright 2014 Google Inc. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""Tests utilizing the sample packager binary."""
import filecmp
import glob
import logging
import os
import re
import shutil
import subprocess
import tempfile
import unittest
import packager_app
import test_env
_TEST_FAILURE_COMMAND_LINE_MESSAGE = """
!!! To reproduce the failure, change the output files to an !!!
!!! existing directory, e.g. output artifacts to current !!!
!!! directory by removing /tmp/something/ in the following !!!
!!! command line. !!!
The test executed the following command line:
""".strip()
class StreamDescriptor(object):
"""Basic class used to build stream descriptor commands."""
def __init__(self, input_file):
self._buffer = 'input=%s' % input_file
self._output_file_name_base = os.path.splitext(
os.path.basename(input_file))[0]
def Append(self, key, value):
self._buffer += ',%s=%s' % (key, value)
# Generate an unique |_output_file_name_base| from some of the keys.
# We do not need all the keys as it is sufficient with the below keys.
if key == 'stream':
self._output_file_name_base += '-%s' % value
elif key == 'trick_play_factor':
self._output_file_name_base += '-trick_play_factor_%d' % value
elif key == 'skip_encryption':
self._output_file_name_base += '-skip_encryption'
return self
def GetOutputFileNameBase(self, output_file_prefix):
if output_file_prefix:
return '%s-%s' % (output_file_prefix, self._output_file_name_base)
else:
return self._output_file_name_base
def __str__(self):
return self._buffer
class DiffFilesPolicy(object):
"""Class for handling files comparison.
Attributes:
_allowed_diff_files: The list of files allowed to be different.
_exact: The actual list of diff_files must match the above list exactly,
i.e. all the files in the above list must be different.
_allow_updating_golden_files: When set to false, golden files will not be
updated for this test even if updating_golden_files is requested. This
is useful for tests generating different outputs in each run, which is
often used together when _allowed_diff_files is not empty.
"""
def __init__(self,
allowed_diff_files=None,
exact=True,
allow_updating_golden_files=True):
if allowed_diff_files:
self._allowed_diff_files = allowed_diff_files
else:
self._allowed_diff_files = []
self._exact = exact
self._allow_updating_golden_files = allow_updating_golden_files
def ProcessDiff(self, out_dir, gold_dir):
"""Compare test outputs with golden files.
Args:
out_dir: The test output directory.
gold_dir: The golden directory to be compared with.
Returns:
A list of diff messages when the files do not match; An empty list
otherwise or in update mode.
"""
if test_env.options.test_update_golden_files:
if self._allow_updating_golden_files:
self._UpdateGold(out_dir, gold_dir)
return []
else:
return self._DiffDir(out_dir, gold_dir)
def _DiffDir(self, out_dir, gold_dir):
# Get a list of the files and dirs that are different between the two top
# level directories.
diff = filecmp.dircmp(out_dir, gold_dir)
# Create a list of all the details about the failure. The list will be
# joined together when sent out.
failure_messages = []
missing = diff.left_only
if missing:
failure_messages += [
'Missing %d files: %s' % (len(missing), str(missing))
]
extra = diff.right_only
if extra:
failure_messages += [
'Found %d unexpected files: %s' % (len(extra), str(extra))
]
# Produce nice diffs for each file that differs.
for diff_file in diff.diff_files:
if diff_file in self._allowed_diff_files:
continue
actual_file = os.path.join(out_dir, diff_file)
expected_file = os.path.join(gold_dir, diff_file)
output = self._GitDiff(expected_file, actual_file)
# If this is an MP4 file, get a better looking diff.
if (output and
os.path.splitext(actual_file)[1] in {'.mp4', '.m4s'}):
new_output = self._Mp4Diff(
out_dir, expected_file, actual_file)
output = new_output or output
if output:
failure_messages += [output.decode('utf8')]
if self._exact:
for diff_file in self._allowed_diff_files:
if diff_file not in diff.diff_files:
failure_messages += ['Expecting "%s" to be different' % diff_file]
return failure_messages
def _GitDiff(self, file_a, file_b):
cmd = [
'git',
'--no-pager',
'diff',
'--color=auto',
'--no-ext-diff',
'--no-index',
file_a,
file_b
]
return subprocess.check_output(cmd)
def _Mp4Diff(self, out_dir, file_a, file_b):
dump_a = os.path.join(out_dir, os.path.basename(file_a) + '.dump.expected')
dump_b = os.path.join(out_dir, os.path.basename(file_b) + '.dump.actual')
try:
cmd = ['mp4dump', '--verbosity', '2', file_a]
with open(dump_a, 'w', encoding='utf8') as f:
subprocess.check_call(cmd, stdout=f)
cmd = ['mp4dump', '--verbosity', '2', file_b]
with open(dump_b, 'w', encoding='utf8') as f:
subprocess.check_call(cmd, stdout=f)
except (OSError, subprocess.CalledProcessError):
# If the program isn't available or returns an error, just ignore it and
# use the normal diff.
return None, None
return self._GitDiff(dump_a, dump_b)
def _UpdateGold(self, out_dir, gold_dir):
if os.path.exists(gold_dir):
shutil.rmtree(gold_dir)
shutil.copytree(out_dir, gold_dir)
def _UpdateMediaInfoPaths(media_info_filepath):
# Example:
# before: media_file_name: "/tmp/tmpD1h5UC/bear-640x360-audio.mp4"
# after: media_file_name: "bear-640x360-audio.mp4"
with open(media_info_filepath, 'rb') as f:
content = f.read().decode()
regex = 'media_file_name: "(.*)"'
for path in re.findall(regex, content):
short_path = os.path.basename(path)
content = content.replace(path, short_path)
with open(media_info_filepath, 'wb') as f:
f.write(content.encode())
def _UpdateMpdTimes(mpd_filepath):
# Take a single pattern, and replace the first match with the
# given new string.
def _Replace(str_in, pattern, new):
m = re.search(pattern, str_in)
if m:
old = m.group(0)
out = str_in.replace(old, new)
logging.info('Replacing "%s" with "%s"', old, new)
else:
out = str_in
return out
with open(mpd_filepath, 'rb') as f:
content = f.read().decode()
content = _Replace(
content,
'availabilityStartTime="[^"]+"',
'availabilityStartTime="some_time"')
content = _Replace(
content,
'publishTime="[^"]+"',
'publishTime="some_time"')
with open(mpd_filepath, 'wb') as f:
f.write(content.encode())
def GetExtension(input_file_path, output_format):
if output_format in {'vtt+mp4', 'ttml+mp4'}:
return 'mp4'
elif output_format:
return output_format
# Otherwise use the same extension as the input.
ext = os.path.splitext(input_file_path)[1]
return ext[1:] # Remove the leading '.'.
def GetSegmentedExtension(base_extension):
if base_extension == 'mp4':
return 'm4s'
return base_extension
class PackagerAppTest(unittest.TestCase):
def setUp(self):
super().setUp()
self.packager = packager_app.PackagerApp()
self.tmp_dir = tempfile.mkdtemp()
self.test_data_dir = os.path.join(test_env.SRC_DIR, 'packager', 'media',
'test', 'data')
self.golden_file_dir = os.path.join(test_env.SRC_DIR, 'packager', 'app',
'test', 'testdata')
self.mpd_output = os.path.join(self.tmp_dir, 'output.mpd')
self.hls_master_playlist_output = os.path.join(self.tmp_dir, 'output.m3u8')
self.output = []
# Test variables.
self.encryption_key_id = '31323334353637383930313233343536'
if test_env.options.encryption_key:
self.encryption_key = test_env.options.encryption_key
else:
self.encryption_key = '32333435363738393021323334353637'
if test_env.options.encryption_iv:
self.encryption_iv = test_env.options.encryption_iv
else:
self.encryption_iv = '3334353637383930'
self.widevine_content_id = '3031323334353637'
self.pssh = ('0000002070737368000000001077efecc0b24d02ace33c1e52e2fb4b000'
'00000')
# TS files may have a non-zero start, which could result in the first
# segment to be less than 1 second. Set clear_lead to be less than 1
# so only the first segment is left in clear.
self.clear_lead = 0.8
def tearDown(self):
if test_env.options.remove_temp_files_after_test:
shutil.rmtree(self.tmp_dir)
super().tearDown()
def _GetStream(self,
descriptor,
language=None,
output_file_prefix=None,
output_format=None,
segmented=False,
using_time_specifier=False,
hls=False,
hls_characteristics=None,
hls_only=None,
dash_accessibilities=None,
dash_roles=None,
dash_only=None,
trick_play_factor=None,
drm_label=None,
skip_encryption=None,
bandwidth=None,
split_content_on_ad_cues=False,
test_file=None):
"""Get a stream descriptor as a string.
Create the stream descriptor as a string for the given parameters so that
it can be passed as an input parameter to the packager.
Args:
descriptor: The name of the stream in the container that should be used as
input for the output.
language: The language override for the input stream.
output_file_prefix: The output file prefix. Default to empty if not
specified.
output_format: The format for the output.
segmented: Should the output use a segmented formatted. This will affect
the output extensions and manifests.
using_time_specifier: Use $Time$ in segment name instead of using
$Number$. This flag is only relevant if segmented is True.
hls: Should the output be for an HLS manifest.
hls_characteristics: CHARACTERISTICS attribute for the HLS stream.
hls_only: If set to true, will indicate that the stream is for HLS only.
dash_accessibilities: Accessibility element for the DASH stream.
dash_roles: Role element for the DASH stream.
dash_only: If set to true, will indicate that the stream is for DASH only.
trick_play_factor: Signals the stream is to be used for a trick play
stream and which key frames to use. A trick play factor of 0 is the
same as not specifying a trick play factor.
drm_label: The drm label for the stream.
skip_encryption: If set to true, the stream will not be encrypted.
bandwidth: The expected bandwidth value that should be listed in the
manifest.
split_content_on_ad_cues: If set to true, the output file will be split
into multiple files, with a total of NumAdCues + 1 files.
test_file: The input file to use. If the input file is not specified, a
default file will be used.
Returns:
A string that makes up a single stream descriptor for input to the
packager.
"""
input_file_name = test_file or 'bear-640x360.mp4'
input_file_path = os.path.join(self.test_data_dir, input_file_name)
stream = StreamDescriptor(input_file_path)
stream.Append('stream', descriptor)
if output_format:
stream.Append('format', output_format)
if language:
stream.Append('lang', language)
if trick_play_factor:
stream.Append('trick_play_factor', trick_play_factor)
if drm_label:
stream.Append('drm_label', drm_label)
if skip_encryption:
stream.Append('skip_encryption', 1)
base_ext = GetExtension(input_file_path, output_format)
output_file_name_base = stream.GetOutputFileNameBase(output_file_prefix)
if hls:
stream.Append('playlist_name', output_file_name_base + '.m3u8')
# By default, add a iframe playlist for all HLS playlists (assuming that
# the source input is supported). iframe playlists should only be for
# videos. This check will fail for numeric descriptors, but that is an
# acceptable limitation (b/73960731).
if base_ext in ['ts', 'mp4'] and descriptor == 'video':
stream.Append('iframe_playlist_name',
output_file_name_base + '-iframe.m3u8')
if hls_characteristics:
stream.Append('hls_characteristics', hls_characteristics)
if hls_only:
stream.Append('hls_only', 1)
if dash_accessibilities:
stream.Append('dash_accessibilities', dash_accessibilities)
if dash_roles:
stream.Append('dash_roles', dash_roles)
if dash_only:
stream.Append('dash_only', 1)
requires_init_segment = segmented and base_ext not in [
'aac', 'ac3', 'ec3', 'ts', 'vtt', 'ttml',
]
output_file_path = os.path.join(self.tmp_dir, output_file_name_base)
if requires_init_segment:
init_seg = '%s-init.%s' % (output_file_path, base_ext)
stream.Append('init_segment', init_seg)
if segmented:
segment_specifier = '$Time$' if using_time_specifier else '$Number$'
segment_ext = GetSegmentedExtension(base_ext)
seg_template = '%s-%s.%s' % (output_file_path, segment_specifier,
segment_ext)
stream.Append('segment_template', seg_template)
else:
if split_content_on_ad_cues:
output_file_path += '$Number$.' + base_ext
else:
output_file_path += '.' + base_ext
stream.Append('output', output_file_path)
if bandwidth:
stream.Append('bandwidth', bandwidth)
self.output.append(output_file_path)
return str(stream)
def _GetStreams(self, streams, test_files=None, **kwargs):
# Make sure there is a valid list that we can get the length from.
test_files = test_files or []
test_files_count = len(test_files)
out = []
if test_files_count == 0:
for stream in streams:
out.append(self._GetStream(stream, **kwargs))
else:
for file_name in test_files:
for stream in streams:
out.append(self._GetStream(stream, test_file=file_name, **kwargs))
return out
def _GetFlags(self,
strip_parameter_set_nalus=True,
encryption=False,
protection_systems=None,
protection_scheme=None,
crypt_byte_block=None,
skip_byte_block=None,
vp9_subsample_encryption=True,
decryption=False,
random_iv=False,
widevine_encryption=False,
key_rotation=False,
include_pssh_in_stream=True,
dash_if_iop=True,
output_media_info=False,
output_dash=False,
output_hls=False,
hls_playlist_type=None,
time_shift_buffer_depth=0.0,
preserved_segments_outside_live_window=0,
utc_timings=None,
generate_static_live_mpd=False,
ad_cues=None,
default_language=None,
segment_duration=1.0,
use_fake_clock=True,
allow_codec_switching=False,
dash_force_segment_list=False):
flags = ['--single_threaded']
if not strip_parameter_set_nalus:
flags += ['--strip_parameter_set_nalus=false']
if widevine_encryption:
widevine_server_url = ('https://license.uat.widevine.com/cenc'
'/getcontentkey/widevine_test')
flags += [
'--enable_widevine_encryption',
'--key_server_url=' + widevine_server_url,
'--content_id=' + self.widevine_content_id,
]
elif encryption:
flags += [
'--enable_raw_key_encryption',
'--keys=label=:key_id={0}:key={1}'.format(self.encryption_key_id,
self.encryption_key),
'--clear_lead={0}'.format(self.clear_lead)
]
if not random_iv:
flags.append('--iv=' + self.encryption_iv)
if protection_systems:
flags += ['--protection_systems=' + protection_systems]
if 'FairPlay' in protection_systems:
fairplay_key_uri = ('skd://www.license.com/getkey?'
'KeyId=31323334-3536-3738-3930-313233343536')
flags += ['--hls_key_uri=' + fairplay_key_uri]
if protection_scheme:
flags += ['--protection_scheme', protection_scheme]
if crypt_byte_block is not None and skip_byte_block is not None:
flags += [
'--crypt_byte_block={0}'.format(crypt_byte_block),
'--skip_byte_block={0}'.format(skip_byte_block)
]
if not vp9_subsample_encryption:
flags += ['--vp9_subsample_encryption=false']
if decryption:
flags += [
'--enable_raw_key_decryption',
'--keys=label=:key_id={0}:key={1}'.format(self.encryption_key_id,
self.encryption_key)
]
if key_rotation:
flags.append('--crypto_period_duration=1')
if not include_pssh_in_stream:
flags.append('--mp4_include_pssh_in_stream=false')
if not dash_if_iop:
flags.append('--generate_dash_if_iop_compliant_mpd=false')
if output_media_info:
flags.append('--output_media_info')
if output_dash:
flags += ['--mpd_output', self.mpd_output]
if output_hls:
flags += ['--hls_master_playlist_output', self.hls_master_playlist_output]
if hls_playlist_type:
flags += ['--hls_playlist_type', hls_playlist_type]
if time_shift_buffer_depth != 0.0:
flags += ['--time_shift_buffer_depth={0}'.format(time_shift_buffer_depth)]
if preserved_segments_outside_live_window != 0:
flags += [
'--preserved_segments_outside_live_window={0}'.format(
preserved_segments_outside_live_window)
]
if utc_timings:
flags += ['--utc_timings', utc_timings]
if generate_static_live_mpd:
flags += ['--generate_static_live_mpd']
if allow_codec_switching:
flags += ['--allow_codec_switching']
if ad_cues:
flags += ['--ad_cues', ad_cues]
if default_language:
flags += ['--default_language', default_language]
if dash_force_segment_list:
flags += ['--dash_force_segment_list']
flags += ['--generate_sidx_in_media_segments=false']
flags.append('--segment_duration={0}'.format(segment_duration))
# Use fake clock, so output can be compared.
if use_fake_clock:
flags.append('--use_fake_clock_for_muxer')
# Override packager version string for testing.
flags += ['--test_packager_version', '<tag>-<hash>-<test>']
return flags
def _AssertStreamInfo(self, stream, info):
stream_info = self.packager.DumpStreamInfo(stream)
self.assertIn('Found 1 stream(s).', stream_info)
self.assertIn(info, stream_info)
def _Decrypt(self, file_path):
streams = [
self._GetStream(
'0', output_file_prefix='decrypted', test_file=file_path)
]
self.assertPackageSuccess(streams, self._GetFlags(decryption=True))
def _CheckTestResults(self,
test_dir,
verify_decryption=False,
diff_files_policy=DiffFilesPolicy()):
"""Check test results. Updates golden files in update mode.
Args:
test_dir: The golden directory to be compared with. It is expected to be
relative to |self.golden_file_dir|.
verify_decryption: If set to true, assumes the media files without
'skip-encryption' in name to be encrypted and tries to decrypt and
then compare these files.
diff_files_policy: Specifies DiffFiles policy and handles files
comparison.
"""
# Live mpd contains current availabilityStartTime and publishTime, which
# needs to be replaced before comparison. If this is not a live test, then
# this will be a no-op.
mpds = glob.glob(os.path.join(self.tmp_dir, '*.mpd'))
for manifest in mpds:
_UpdateMpdTimes(manifest)
# '*.media_info' outputs contain media file names, which is changing for
# every test run. These needs to be replaced for comparison.
media_infos = glob.glob(os.path.join(self.tmp_dir, '*.media_info'))
for media_info in media_infos:
_UpdateMediaInfoPaths(media_info)
if verify_decryption:
for file_name in os.listdir(self.tmp_dir):
if 'skip_encryption' in file_name:
continue
extension = os.path.splitext(file_name)[1][1:]
if extension not in ['mpd', 'm3u8', 'media_info']:
self._Decrypt(os.path.join(self.tmp_dir, file_name))
out_dir = self.tmp_dir
gold_dir = os.path.join(self.golden_file_dir, test_dir)
failure_messages = diff_files_policy.ProcessDiff(out_dir, gold_dir)
if failure_messages:
# Prepend the failure messages with the header.
failure_messages = [
_TEST_FAILURE_COMMAND_LINE_MESSAGE,
self.packager.GetCommandLine()
] + failure_messages
self.fail('\n'.join(failure_messages))
class PackagerFunctionalTest(PackagerAppTest):
def assertPackageSuccess(self, streams, flags=None):
self.assertEqual(self.packager.Package(streams, flags), 0)
def assertMpdGeneratorSuccess(self):
media_infos = glob.glob(os.path.join(self.tmp_dir, '*.media_info'))
self.assertTrue(media_infos)
flags = ['--input', ','.join(media_infos), '--output', self.mpd_output]
flags += ['--test_packager_version', '<tag>-<hash>-<test>']
self.assertEqual(self.packager.MpdGenerator(flags), 0)
def testVersion(self):
# To support python version 2, which does not have assertRegex.
if 'assertRegex' not in dir(self):
assert_regex = self.assertRegexpMatches
else:
assert_regex = self.assertRegex
assert_regex(
self.packager.Version(), '^packager(.exe)? version '
r'((?P<tag>[\w\.]+)-)?(?P<hash>[a-f\d]+)-(debug|release)[\r\n]+.*$')
def testDumpStreamInfo(self):
test_file = os.path.join(self.test_data_dir, 'bear-640x360.mp4')
stream_info = self.packager.DumpStreamInfo(test_file)
expected_stream_info = ('Found 2 stream(s).\n'
'Stream [0] type: Video\n'
' codec_string: avc1.64001e\n'
' time_scale: 30000\n'
' duration: 82082 (2.7 seconds)\n'
' is_encrypted: false\n'
' codec: H264\n'
' width: 640\n'
' height: 360\n'
' pixel_aspect_ratio: 1:1\n'
' trick_play_factor: 0\n'
' nalu_length_size: 4\n\n'
'Stream [1] type: Audio\n'
' codec_string: mp4a.40.2\n'
' time_scale: 44100\n'
' duration: 121856 (2.8 seconds)\n'
' is_encrypted: false\n'
' codec: AAC\n'
' sample_bits: 16\n'
' num_channels: 2\n'
' sampling_frequency: 44100\n'
' language: und\n')
stream_info = stream_info.replace('\r\n', '\n')
self.assertIn(expected_stream_info, stream_info,
'\nExpecting: \n %s\n\nBut seeing: \n%s' %
(expected_stream_info, stream_info))
def testFirstStream(self):
self.assertPackageSuccess(
self._GetStreams(['0']), self._GetFlags(output_dash=True))
self._CheckTestResults('first-stream')
# Probably one of the most common scenarios is to package audio and video.
def testAudioVideo(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video']), self._GetFlags(output_dash=True))
self._CheckTestResults('audio-video')
def testAudioVideoWithAccessibilitiesAndRoles(self):
streams = [
self._GetStream(
'audio',
dash_accessibilities='urn:tva:metadata:cs:AudioPurposeCS:2007=1',
dash_roles='description'),
self._GetStream('video'),
]
streams += self._GetStreams(
['text'],
test_files=['bear-english.vtt'],
dash_roles='caption')
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True))
self._CheckTestResults('audio-video-with-accessibilities-and-roles')
def testAudioVideoWithTrickPlay(self):
streams = [
self._GetStream('audio'),
self._GetStream('video'),
self._GetStream('video', trick_play_factor=1),
]
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True))
self._CheckTestResults('audio-video-with-trick-play')
def testAudioVideoWithTwoTrickPlay(self):
streams = [
self._GetStream('audio'),
self._GetStream('video'),
self._GetStream('video', trick_play_factor=1),
self._GetStream('video', trick_play_factor=2),
]
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True))
self._CheckTestResults('audio-video-with-two-trick-play')
def testAudioVideoWithTwoTrickPlayDecreasingRate(self):
streams = [
self._GetStream('audio'),
self._GetStream('video'),
self._GetStream('video', trick_play_factor=2),
self._GetStream('video', trick_play_factor=1),
]
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True))
# Since the stream descriptors are sorted in packager app, a different
# order of trick play factors gets the same mpd.
self._CheckTestResults('audio-video-with-two-trick-play')
def testDashOnlyAndHlsOnlyWithCaptions(self):
audio_video_streams = self._GetStreams(['audio', 'video'], segmented=True)
dash_text_stream = self._GetStreams(['text'],
test_files=['bear-english.vtt'],
output_format='mp4',
segmented=True,
dash_only=True)
hls_text_stream = self._GetStreams(['text'],
test_files=['bear-english.vtt'],
segmented=True,
hls_only=True)
streams = audio_video_streams + dash_text_stream + hls_text_stream
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True,
output_hls=True))
self._CheckTestResults('hls-only-dash-only-captions')
def testDashOnlyAndHlsOnly(self):
streams = [
self._GetStream('video', hls_only=True),
self._GetStream('audio', dash_only=True),
]
self.assertPackageSuccess(
streams,
self._GetFlags(output_dash=True, output_hls=True))
self._CheckTestResults('hls-only-dash-only')
def testAudioVideoWithLanguageOverride(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'], language='por', hls=True),
self._GetFlags(default_language='por', output_dash=True,
output_hls=True))
self._CheckTestResults('audio-video-with-language-override')
def testAudioVideoWithLanguageOverrideUsingMixingCode(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'], language='por', hls=True),
self._GetFlags(default_language='pt', output_dash=True,
output_hls=True))
self._CheckTestResults('audio-video-with-language-override')
def testAudioVideoWithLanguageOverrideUsingMixingCode2(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'], language='pt', hls=True),
self._GetFlags(default_language='por', output_dash=True,
output_hls=True))
self._CheckTestResults('audio-video-with-language-override')
def testAudioVideoWithLanguageOverrideUsingTwoCharacterCode(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'], language='pt', hls=True),
self._GetFlags(default_language='pt', output_dash=True,
output_hls=True))
self._CheckTestResults('audio-video-with-language-override')
def testAudioVideoWithLanguageOverrideWithSubtag(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'], language='por-BR', hls=True),
self._GetFlags(output_dash=True, output_hls=True))
self._CheckTestResults('audio-video-with-language-override-with-subtag')
def testSegmentedWebVttWithLanguageOverride(self):
streams = self._GetStreams(
['text'], language='por', dash_only=True, output_format='mp4',
test_files=['bear-english.vtt'], segmented=True)
streams += self._GetStreams(
['text'], language='por', hls_only=True,
test_files=['bear-english.vtt'], segmented=True)
flags = self._GetFlags(output_hls=True, output_dash=True)
self.assertPackageSuccess(streams, flags)
self._CheckTestResults('segmented-webvtt-with-language-override')
def testSegmentedWebVttText(self):
streams = self._GetStreams(
['text'], test_files=['bear-english.vtt'], segmented=True)
flags = self._GetFlags(output_hls=True, output_dash=True)
self.assertPackageSuccess(streams, flags)
self._CheckTestResults('segmented-webvtt-text')
def testSingleFileWebVttText(self):
streams = self._GetStreams(['text'], test_files=['bear-english.vtt'])
flags = self._GetFlags(output_hls=True, output_dash=True)
self.assertPackageSuccess(streams, flags)
self._CheckTestResults('single-file-webvtt-text')
def testSegmentedWebVttMp4(self):
streams = self._GetStreams(['text'], test_files=['bear-english.vtt'],
output_format='mp4', segmented=True)
flags = self._GetFlags(output_hls=True, output_dash=True)
self.assertPackageSuccess(streams, flags)
self._CheckTestResults('segmented-webvtt-mp4')
def testSegmentedTtmlText(self):
streams = self._GetStreams(['text'], test_files=['bear-english.vtt'],
output_format='ttml', segmented=True)
flags = self._GetFlags(output_hls=True, output_dash=True)
self.assertPackageSuccess(streams, flags)
self._CheckTestResults('segmented-ttml-text')
def testSegmentedTtmlMp4(self):
streams = self._GetStreams(['text'], test_files=['bear-english.vtt'],
output_format='ttml+mp4', segmented=True)
flags = self._GetFlags(output_hls=True, output_dash=True)
self.assertPackageSuccess(streams, flags)
self._CheckTestResults('segmented-ttml-mp4')
def testMp4TrailingMoov(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'],
test_files=['bear-640x360-trailing-moov.mp4']),
self._GetFlags(output_dash=True, output_hls=True))
self._CheckTestResults('mp4-trailing-moov')
def testVideoNonSquarePixel(self):
self.assertPackageSuccess(
self._GetStreams(
['video'],
test_files=['bear-640x360-non_square_pixel-with_pasp.mp4']),
self._GetFlags(output_dash=True, output_hls=True))
self._CheckTestResults('video-non-square-pixel')
def testAacHe(self):
self.assertPackageSuccess(
self._GetStreams(
['audio'], test_files=['bear-640x360-aac_he-silent_right.mp4']),
self._GetFlags(output_dash=True))
self._CheckTestResults('acc-he')
def testVideoAudioWebVTT(self):
audio_video_streams = self._GetStreams(['audio', 'video'])
text_stream = self._GetStreams(['text'], test_files=['bear-english.vtt'])
self.assertPackageSuccess(audio_video_streams + text_stream,
self._GetFlags(output_dash=True))
self._CheckTestResults('video-audio-webvtt')
def testVideoAudioTTML(self):
audio_video_streams = self._GetStreams(['audio', 'video'])
text_stream = self._GetStreams(['text'], test_files=['bear-english.ttml'])
self.assertPackageSuccess(audio_video_streams + text_stream,
self._GetFlags(output_dash=True))
self._CheckTestResults('video-audio-ttml')
def testVideoNoEditList(self):
stream = self._GetStream('video', test_file='bear-640x360-no_edit_list.mp4')
self.assertPackageSuccess([stream], self._GetFlags(output_dash=True))
self._CheckTestResults('video-no-edit-list')
def testAvcAacTs(self):
# Currently we only support live packaging for ts.
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'],
segmented=True,
hls=True,
test_files=['bear-640x360.ts']),
self._GetFlags(output_dash=True, output_hls=True))
self._CheckTestResults('avc-aac-ts')
def testAvcAc3Ts(self):
# Currently we only support live packaging for ts.
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'],
segmented=True,
hls=True,
test_files=['bear-640x360-ac3.ts']),
self._GetFlags(output_hls=True))
self._CheckTestResults('avc-ac3-ts')
def testAvcAc3TsToMp4(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'],
output_format='mp4',
hls=True,
test_files=['bear-640x360-ac3.ts']),
self._GetFlags(output_hls=True))
self._CheckTestResults('avc-ac3-ts-to-mp4')
def testAvcTsLivePlaylist(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'],
segmented=True,
hls=True,
test_files=['bear-640x360.ts']),
self._GetFlags(
output_hls=True,
hls_playlist_type='LIVE',
time_shift_buffer_depth=0.5))
self._CheckTestResults('avc-ts-live-playlist')
def testAvcTsLivePlaylistWithKeyRotation(self):
self.packager.Package(
self._GetStreams(['audio', 'video'],
segmented=True,
hls=True,
test_files=['bear-640x360.ts']),
self._GetFlags(
encryption=True,
key_rotation=True,
output_hls=True,
hls_playlist_type='LIVE',
time_shift_buffer_depth=0.5))
self._CheckTestResults('avc-ts-live-playlist-with-key-rotation')
def testAvcTsEventPlaylist(self):
self.assertPackageSuccess(
self._GetStreams(['audio', 'video'],
segmented=True,
hls=True,
test_files=['bear-640x360.ts']),
self._GetFlags(
output_hls=True,
hls_playlist_type='EVENT',
time_shift_buffer_depth=0.5))
self._CheckTestResults('avc-ts-event-playlist')
def testAvcTsLivePlaylistAndDashDynamicWithSegmentDeletion(self):
self.assertPackageSuccess(
self._GetStreams(
['audio'],
output_format='mp4',
segmented=True,
hls=True,
test_files=['bear-640x360.ts']),
self._GetFlags(
output_hls=True,
hls_playlist_type='LIVE',
output_dash=True,
segment_duration=0.5,
time_shift_buffer_depth=0.5,
preserved_segments_outside_live_window=1))
self._CheckTestResults(
'avc-ts-live-playlist-dash-dynamic-with-segment-deletion')
def testVp8Webm(self):
self.assertPackageSuccess(
self._GetStreams(['video'], test_files=['bear-640x360.webm']),
self._GetFlags(output_dash=True))
self._CheckTestResults('vp8-webm')