2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-05-09 01:23:54 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include <iostream>
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <optional>
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <codecvt>
|
|
|
|
#include <functional>
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <absl/flags/flag.h>
|
|
|
|
#include <absl/flags/parse.h>
|
|
|
|
#include <absl/flags/usage.h>
|
|
|
|
#include <absl/flags/usage_config.h>
|
|
|
|
#include <absl/log/globals.h>
|
|
|
|
#include <absl/log/initialize.h>
|
|
|
|
#include <absl/log/log.h>
|
|
|
|
#include <absl/strings/numbers.h>
|
|
|
|
#include <absl/strings/str_format.h>
|
|
|
|
#include <absl/strings/str_split.h>
|
|
|
|
|
|
|
|
#include <packager/app/ad_cue_generator_flags.h>
|
|
|
|
#include <packager/app/crypto_flags.h>
|
|
|
|
#include <packager/app/hls_flags.h>
|
|
|
|
#include <packager/app/manifest_flags.h>
|
|
|
|
#include <packager/app/mpd_flags.h>
|
|
|
|
#include <packager/app/muxer_flags.h>
|
|
|
|
#include <packager/app/playready_key_encryption_flags.h>
|
|
|
|
#include <packager/app/protection_system_flags.h>
|
|
|
|
#include <packager/app/raw_key_encryption_flags.h>
|
|
|
|
#include <packager/app/retired_flags.h>
|
|
|
|
#include <packager/app/stream_descriptor.h>
|
|
|
|
#include <packager/app/widevine_encryption_flags.h>
|
|
|
|
#include <packager/file.h>
|
|
|
|
#include <packager/kv_pairs/kv_pairs.h>
|
|
|
|
#include <packager/tools/license_notice.h>
|
|
|
|
#include <packager/utils/string_trim_split.h>
|
|
|
|
|
|
|
|
ABSL_FLAG(bool, dump_stream_info, false, "Dump demuxed stream info.");
|
|
|
|
ABSL_FLAG(bool, licenses, false, "Dump licenses.");
|
|
|
|
ABSL_FLAG(bool, quiet, false, "When enabled, LOG(INFO) output is suppressed.");
|
|
|
|
ABSL_FLAG(bool,
|
|
|
|
use_fake_clock_for_muxer,
|
|
|
|
false,
|
|
|
|
"Set to true to use a fake clock for muxer. With this flag set, "
|
|
|
|
"creation time and modification time in outputs are set to 0. "
|
|
|
|
"Should only be used for testing.");
|
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
test_packager_version,
|
|
|
|
"",
|
|
|
|
"Packager version for testing. Should be used for testing only.");
|
|
|
|
ABSL_FLAG(bool,
|
|
|
|
single_threaded,
|
|
|
|
false,
|
|
|
|
"If enabled, only use one thread when generating content.");
|
2015-09-25 22:48:18 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-05-09 01:23:54 +00:00
|
|
|
namespace {
|
2016-05-19 21:38:15 +00:00
|
|
|
|
2014-05-09 01:23:54 +00:00
|
|
|
const char kUsage[] =
|
2016-12-08 20:07:09 +00:00
|
|
|
"%s [flags] <stream_descriptor> ...\n\n"
|
|
|
|
" stream_descriptor consists of comma separated field_name/value pairs:\n"
|
|
|
|
" field_name=value,[field_name=value,]...\n"
|
2017-04-28 23:29:02 +00:00
|
|
|
" Supported field names are as follows (names in parenthesis are alias):\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - input (in): Required input/source media file path or network stream\n"
|
|
|
|
" URL.\n"
|
|
|
|
" - stream_selector (stream): Required field with value 'audio',\n"
|
2015-11-23 23:12:04 +00:00
|
|
|
" 'video', 'text', or stream number (zero based).\n"
|
2017-04-28 23:29:02 +00:00
|
|
|
" - output (out,init_segment): Required output file (single file) or\n"
|
|
|
|
" initialization file path (multiple file).\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - segment_template (segment): Optional value which specifies the\n"
|
|
|
|
" naming pattern for the segment files, and that the stream should be\n"
|
|
|
|
" split into multiple files. Its presence should be consistent across\n"
|
|
|
|
" streams.\n"
|
|
|
|
" - bandwidth (bw): Optional value which contains a user-specified\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
" maximum bit rate for the stream, in bits/sec. If specified, this\n"
|
2017-06-21 22:50:32 +00:00
|
|
|
" value is propagated to (HLS) EXT-X-STREAM-INF:BANDWIDTH or (DASH)\n"
|
|
|
|
" Representation@bandwidth and the $Bandwidth$ template parameter for\n"
|
|
|
|
" segment names. If not specified, the bandwidth value is estimated\n"
|
|
|
|
" from content bitrate. Note that it only affects the generated\n"
|
|
|
|
" manifests/playlists; it has no effect on the media content itself.\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - language (lang): Optional value which contains a user-specified\n"
|
|
|
|
" language tag. If specified, this value overrides any language\n"
|
2017-05-22 20:31:41 +00:00
|
|
|
" metadata in the input stream.\n"
|
2015-12-21 23:10:17 +00:00
|
|
|
" - output_format (format): Optional value which specifies the format\n"
|
|
|
|
" of the output files (MP4 or WebM). If not specified, it will be\n"
|
2016-04-16 22:58:47 +00:00
|
|
|
" derived from the file extension of the output file.\n"
|
feat: Allow LIVE UDP WebVTT input (#1349)
An updated version of PR #1027
That previous PR was done using 2021 code, and there were many changes
in the codebase from there, so a rebase was needed and also some minor
tweak here and there. But it's the same code, just reimplemented on a
newer codebase.
If you want to take a look at this in action, after building shaka
packager with this PR's code included, try this commands in 3 different
simultaneous bash sessions:
1. Video UDP input: `ffmpeg -f lavfi -re -i
"testsrc=s=320x240:r=30,format=yuv420p" -c:v h264 -sc_threshold 0 -g 30
-keyint_min 30 -r 30 -a53cc 1 -b:v 150k -preset ultrafast -r 30 -f
mpegts "udp://127.0.0.1:10000?pkt_size=1316"`
2. WebVTT UDP input: `for sec in $(seq 0 9999) ; do printf
"%02d:%02d.000 --> %02d:%02d.000\ntest second ${sec}\n\n" "$(( ${sec} /
60 ))" "$(( ${sec} % 60 ))" "$(( (${sec} + 1) / 60 ))" "$(( (${sec} + 1)
% 60 ))" ; sleep 1 ; done > /dev/udp/127.0.0.1/12345`
3. shaka packager command line: `timeout 60
path/to/build/packager/packager
'in=udp://127.0.0.1:10000?timeout=8000000,stream_selector=0,init_segment=240_init.m4s,segment_template=240_$Number%09d$.m4s,bandwidth=150000'
'in=udp://127.0.0.1:12345?timeout=8000000,stream_selector=0,input_format=webvtt,format=webvtt+mp4,init_segment=text_init.m4s,segment_template=text_$Number%09d$.m4s,language=eng,dash_roles=subtitle'
--mpd_output ./manifest.mpd --segment_duration 3.2
--suggested_presentation_delay 3.2 --min_buffer_time 3.2
--minimum_update_period 3.2 --time_shift_buffer_depth 60
--preserved_segments_outside_live_window 1 --default_language=eng
--dump_stream_info 2>&1`
Note the added `input_format=webvtt` to the shaka packager command's
second selector. That's new from this PR. If you don't use that, shaka's
format autodetection will not detect the webvtt format from the input,
as explained in
https://github.com/shaka-project/shaka-packager/issues/685#issuecomment-1029407191.
Try the command without it if you want to.
Fixes #685
Fixes #1017
---------
Co-authored-by: Daniel Cantarín <canta@canta.com.ar>
2024-02-24 00:02:19 +00:00
|
|
|
" - input_format (format): Optional value which specifies the format\n"
|
|
|
|
" of the input files or streams. If not specified, it will be\n"
|
|
|
|
" autodetected, which in some cases (such as live UDP webvtt) may\n"
|
|
|
|
" fail.\n"
|
2017-05-22 20:31:41 +00:00
|
|
|
" - skip_encryption=0|1: Optional. Defaults to 0 if not specified. If\n"
|
|
|
|
" it is set to 1, no encryption of the stream will be made.\n"
|
2017-09-20 22:49:00 +00:00
|
|
|
" - drm_label: Optional value for custom DRM label, which defines the\n"
|
|
|
|
" encryption key applied to the stream. Typical values include AUDIO,\n"
|
|
|
|
" SD, HD, UHD1, UHD2. For raw key, it should be a label defined in\n"
|
|
|
|
" --keys. If not provided, the DRM label is derived from stream type\n"
|
|
|
|
" (video, audio), resolution, etc.\n"
|
|
|
|
" Note that it is case sensitive.\n"
|
2017-05-17 22:53:32 +00:00
|
|
|
" - trick_play_factor (tpf): Optional value which specifies the trick\n"
|
|
|
|
" play, a.k.a. trick mode, stream sampling rate among key frames.\n"
|
|
|
|
" If specified, the output is a trick play stream.\n"
|
2017-10-17 17:59:58 +00:00
|
|
|
" - hls_name: Used for HLS audio to set the NAME attribute for\n"
|
|
|
|
" EXT-X-MEDIA. Defaults to the base of the playlist name.\n"
|
|
|
|
" - hls_group_id: Used for HLS audio to set the GROUP-ID attribute for\n"
|
|
|
|
" EXT-X-MEDIA. Defaults to 'audio' if not specified.\n"
|
2017-12-20 20:26:23 +00:00
|
|
|
" - playlist_name: The HLS playlist file to create. Usually ends with\n"
|
|
|
|
" '.m3u8', and is relative to --hls_master_playlist_output. If\n"
|
|
|
|
" unspecified, defaults to something of the form 'stream_0.m3u8',\n"
|
2018-02-01 20:27:30 +00:00
|
|
|
" 'stream_1.m3u8', 'stream_2.m3u8', etc.\n"
|
|
|
|
" - iframe_playlist_name: The optional HLS I-Frames only playlist file\n"
|
|
|
|
" to create. Usually ends with '.m3u8', and is relative to\n"
|
|
|
|
" hls_master_playlist_output. Should only be set for video streams. If\n"
|
2018-10-10 22:30:28 +00:00
|
|
|
" unspecified, no I-Frames only playlist is created.\n"
|
|
|
|
" - hls_characteristics (charcs): Optional colon/semicolon separated\n"
|
|
|
|
" list of values for the CHARACTERISTICS attribute for EXT-X-MEDIA.\n"
|
2019-06-13 06:01:16 +00:00
|
|
|
" See CHARACTERISTICS attribute in http://bit.ly/2OOUkdB for details.\n"
|
|
|
|
" - dash_accessibilities (accessibilities): Optional semicolon separated\n"
|
|
|
|
" list of values for DASH Accessibility elements. The value should be\n"
|
|
|
|
" in the format: scheme_id_uri=value.\n"
|
|
|
|
" - dash_roles (roles): Optional semicolon separated list of values for\n"
|
|
|
|
" DASH Role elements. The value should be one of: caption, subtitle,\n"
|
2024-02-15 04:27:57 +00:00
|
|
|
" forced-subtitle, main, alternate, supplementary, commentary, \n"
|
|
|
|
" description and dub. See DASH\n"
|
|
|
|
" (ISO/IEC 23009-1) specification for details.\n"
|
|
|
|
" - forced_subtitle: Optional boolean value (0|1). If set to 1 \n"
|
|
|
|
" indicates that this stream is a Forced Narrative subtitle that \n"
|
|
|
|
" should be displayed when subtitles are otherwise off, for example \n"
|
|
|
|
" used to caption short portions of the audio that might be in a \n"
|
|
|
|
" foreign language. For DASH this will set role to forced_subtitle, \n"
|
|
|
|
" for HLS it will set FORCED=YES and AUTOSELECT=YES. \n"
|
|
|
|
" Only valid for subtitles.";
|
2015-11-05 01:49:35 +00:00
|
|
|
|
2017-09-20 22:49:00 +00:00
|
|
|
// Labels for parameters in RawKey key info.
|
|
|
|
const char kDrmLabelLabel[] = "label";
|
|
|
|
const char kKeyIdLabel[] = "key_id";
|
|
|
|
const char kKeyLabel[] = "key";
|
2020-06-26 03:37:50 +00:00
|
|
|
const char kKeyIvLabel[] = "iv";
|
2017-09-20 22:49:00 +00:00
|
|
|
|
2014-10-13 22:06:48 +00:00
|
|
|
enum ExitStatus {
|
|
|
|
kSuccess = 0,
|
|
|
|
kArgumentValidationFailed,
|
|
|
|
kPackagingFailed,
|
|
|
|
kInternalError,
|
|
|
|
};
|
2015-11-05 01:49:35 +00:00
|
|
|
|
2017-06-14 23:18:16 +00:00
|
|
|
bool GetWidevineSigner(WidevineSigner* signer) {
|
2023-12-01 17:32:19 +00:00
|
|
|
signer->signer_name = absl::GetFlag(FLAGS_signer);
|
|
|
|
if (!absl::GetFlag(FLAGS_aes_signing_key).bytes.empty()) {
|
2017-06-14 23:18:16 +00:00
|
|
|
signer->signing_key_type = WidevineSigner::SigningKeyType::kAes;
|
2023-12-01 17:32:19 +00:00
|
|
|
signer->aes.key = absl::GetFlag(FLAGS_aes_signing_key).bytes;
|
|
|
|
signer->aes.iv = absl::GetFlag(FLAGS_aes_signing_iv).bytes;
|
|
|
|
} else if (!absl::GetFlag(FLAGS_rsa_signing_key_path).empty()) {
|
2017-06-14 23:18:16 +00:00
|
|
|
signer->signing_key_type = WidevineSigner::SigningKeyType::kRsa;
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!File::ReadFileToString(
|
|
|
|
absl::GetFlag(FLAGS_rsa_signing_key_path).c_str(),
|
|
|
|
&signer->rsa.key)) {
|
|
|
|
LOG(ERROR) << "Failed to read from '"
|
|
|
|
<< absl::GetFlag(FLAGS_rsa_signing_key_path) << "'.";
|
2017-06-14 23:18:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:42:46 +00:00
|
|
|
bool GetHlsPlaylistType(const std::string& playlist_type,
|
|
|
|
HlsPlaylistType* playlist_type_enum) {
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::AsciiStrToUpper(playlist_type) == "VOD") {
|
2017-06-30 20:42:46 +00:00
|
|
|
*playlist_type_enum = HlsPlaylistType::kVod;
|
2023-12-01 17:32:19 +00:00
|
|
|
} else if (absl::AsciiStrToUpper(playlist_type) == "LIVE") {
|
2017-06-30 20:42:46 +00:00
|
|
|
*playlist_type_enum = HlsPlaylistType::kLive;
|
2023-12-01 17:32:19 +00:00
|
|
|
} else if (absl::AsciiStrToUpper(playlist_type) == "EVENT") {
|
2017-06-30 20:42:46 +00:00
|
|
|
*playlist_type_enum = HlsPlaylistType::kEvent;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unrecognized playlist type " << playlist_type;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:47:55 +00:00
|
|
|
bool GetProtectionScheme(uint32_t* protection_scheme) {
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_protection_scheme) == "cenc") {
|
2017-07-05 23:47:55 +00:00
|
|
|
*protection_scheme = EncryptionParams::kProtectionSchemeCenc;
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_protection_scheme) == "cbc1") {
|
2017-07-05 23:47:55 +00:00
|
|
|
*protection_scheme = EncryptionParams::kProtectionSchemeCbc1;
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_protection_scheme) == "cbcs") {
|
2017-07-05 23:47:55 +00:00
|
|
|
*protection_scheme = EncryptionParams::kProtectionSchemeCbcs;
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_protection_scheme) == "cens") {
|
2017-07-05 23:47:55 +00:00
|
|
|
*protection_scheme = EncryptionParams::kProtectionSchemeCens;
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
LOG(ERROR) << "Unrecognized protection_scheme "
|
|
|
|
<< absl::GetFlag(FLAGS_protection_scheme);
|
2017-07-05 23:47:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-20 22:49:00 +00:00
|
|
|
bool ParseKeys(const std::string& keys, RawKeyParams* raw_key) {
|
2023-12-01 17:32:19 +00:00
|
|
|
std::vector<std::string> keys_data = SplitAndTrimSkipEmpty(keys, ',');
|
|
|
|
|
|
|
|
for (const std::string& key_data : keys_data) {
|
|
|
|
std::vector<KVPair> string_pairs =
|
|
|
|
SplitStringIntoKeyValuePairs(key_data, '=', ':');
|
2017-09-20 22:49:00 +00:00
|
|
|
|
|
|
|
std::map<std::string, std::string> value_map;
|
|
|
|
for (const auto& string_pair : string_pairs)
|
|
|
|
value_map[string_pair.first] = string_pair.second;
|
|
|
|
const std::string drm_label = value_map[kDrmLabelLabel];
|
|
|
|
if (raw_key->key_map.find(drm_label) != raw_key->key_map.end()) {
|
|
|
|
LOG(ERROR) << "Seeing duplicated DRM label '" << drm_label << "'.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto& key_info = raw_key->key_map[drm_label];
|
|
|
|
if (value_map[kKeyIdLabel].empty() ||
|
2023-12-01 17:32:19 +00:00
|
|
|
!shaka::ValidHexStringToBytes(value_map[kKeyIdLabel],
|
|
|
|
&key_info.key_id)) {
|
2017-10-17 22:47:43 +00:00
|
|
|
LOG(ERROR) << "Empty key id or invalid hex string for key id: "
|
|
|
|
<< value_map[kKeyIdLabel];
|
2017-09-20 22:49:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (value_map[kKeyLabel].empty() ||
|
2023-12-01 17:32:19 +00:00
|
|
|
!shaka::ValidHexStringToBytes(value_map[kKeyLabel], &key_info.key)) {
|
2017-10-17 22:47:43 +00:00
|
|
|
LOG(ERROR) << "Empty key or invalid hex string for key: "
|
|
|
|
<< value_map[kKeyLabel];
|
2017-09-20 22:49:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-06-26 03:37:50 +00:00
|
|
|
if (!value_map[kKeyIvLabel].empty()) {
|
|
|
|
if (!raw_key->iv.empty()) {
|
|
|
|
LOG(ERROR) << "IV already specified with --iv";
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!shaka::ValidHexStringToBytes(value_map[kKeyIvLabel], &key_info.iv)) {
|
2020-06-26 03:37:50 +00:00
|
|
|
LOG(ERROR) << "Empty IV or invalid hex string for IV: "
|
|
|
|
<< value_map[kKeyIvLabel];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-09-20 22:49:00 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetRawKeyParams(RawKeyParams* raw_key) {
|
2023-12-01 17:32:19 +00:00
|
|
|
raw_key->iv = absl::GetFlag(FLAGS_iv).bytes;
|
|
|
|
raw_key->pssh = absl::GetFlag(FLAGS_pssh).bytes;
|
|
|
|
if (!absl::GetFlag(FLAGS_keys).empty()) {
|
|
|
|
if (!ParseKeys(absl::GetFlag(FLAGS_keys), raw_key)) {
|
|
|
|
LOG(ERROR) << "Failed to parse --keys " << absl::GetFlag(FLAGS_keys);
|
2017-09-20 22:49:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// An empty StreamLabel specifies the default key info.
|
|
|
|
RawKeyParams::KeyInfo& key_info = raw_key->key_map[""];
|
2023-12-01 17:32:19 +00:00
|
|
|
key_info.key_id = absl::GetFlag(FLAGS_key_id).bytes;
|
|
|
|
key_info.key = absl::GetFlag(FLAGS_key).bytes;
|
2017-09-20 22:49:00 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:45:51 +00:00
|
|
|
bool ParseAdCues(const std::string& ad_cues, std::vector<Cuepoint>* cuepoints) {
|
|
|
|
// Track if optional field is supplied consistently across all cue points.
|
|
|
|
size_t duration_count = 0;
|
2023-12-01 17:32:19 +00:00
|
|
|
std::vector<std::string> ad_cues_vec = SplitAndTrimSkipEmpty(ad_cues, ';');
|
2017-11-18 01:45:51 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
for (const std::string& ad_cue : ad_cues_vec) {
|
2017-11-18 01:45:51 +00:00
|
|
|
Cuepoint cuepoint;
|
2023-12-01 17:32:19 +00:00
|
|
|
std::vector<std::string> split_ad_cue = SplitAndTrimSkipEmpty(ad_cue, ',');
|
|
|
|
|
2017-11-18 01:45:51 +00:00
|
|
|
if (split_ad_cue.size() > 2) {
|
|
|
|
LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues
|
|
|
|
<< " Each ad cue must contain no more than 2 components.";
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!absl::SimpleAtod(split_ad_cue.front(),
|
|
|
|
&cuepoint.start_time_in_seconds)) {
|
2017-11-18 01:45:51 +00:00
|
|
|
LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues
|
|
|
|
<< " Start time component must be of type double.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (split_ad_cue.size() > 1) {
|
|
|
|
duration_count++;
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!absl::SimpleAtod(split_ad_cue[1], &cuepoint.duration_in_seconds)) {
|
2017-11-18 01:45:51 +00:00
|
|
|
LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues
|
|
|
|
<< " Duration component must be of type double.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cuepoints->push_back(cuepoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duration_count > 0 && duration_count != cuepoints->size()) {
|
|
|
|
LOG(ERROR) << "Failed to parse --ad_cues " << ad_cues
|
|
|
|
<< " Duration component is optional. However if it is supplied,"
|
|
|
|
<< " it must be supplied consistently across all cuepoints.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-29 18:45:57 +00:00
|
|
|
bool ParseProtectionSystems(const std::string& protection_systems_str,
|
|
|
|
ProtectionSystem* protection_systems) {
|
|
|
|
*protection_systems = ProtectionSystem::kNone;
|
2018-08-06 23:12:19 +00:00
|
|
|
|
2020-05-29 18:45:57 +00:00
|
|
|
std::map<std::string, ProtectionSystem> mapping = {
|
|
|
|
{"common", ProtectionSystem::kCommon},
|
|
|
|
{"commonsystem", ProtectionSystem::kCommon},
|
|
|
|
{"fairplay", ProtectionSystem::kFairPlay},
|
|
|
|
{"marlin", ProtectionSystem::kMarlin},
|
|
|
|
{"playready", ProtectionSystem::kPlayReady},
|
|
|
|
{"widevine", ProtectionSystem::kWidevine},
|
2018-08-06 23:12:19 +00:00
|
|
|
};
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::vector<std::string> protection_systems_vec =
|
|
|
|
SplitAndTrimSkipEmpty(absl::AsciiStrToLower(protection_systems_str), ',');
|
|
|
|
|
|
|
|
for (const std::string& protection_system : protection_systems_vec) {
|
2018-08-06 23:12:19 +00:00
|
|
|
auto iter = mapping.find(protection_system);
|
|
|
|
if (iter == mapping.end()) {
|
|
|
|
LOG(ERROR) << "Seeing unrecognized protection system: "
|
|
|
|
<< protection_system;
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-29 18:45:57 +00:00
|
|
|
*protection_systems |= iter->second;
|
2018-08-06 23:12:19 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<PackagingParams> GetPackagingParams() {
|
2017-05-22 20:31:41 +00:00
|
|
|
PackagingParams packaging_params;
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
packaging_params.temp_dir = absl::GetFlag(FLAGS_temp_dir);
|
|
|
|
packaging_params.single_threaded = absl::GetFlag(FLAGS_single_threaded);
|
2018-02-07 21:46:11 +00:00
|
|
|
|
2017-11-18 01:45:51 +00:00
|
|
|
AdCueGeneratorParams& ad_cue_generator_params =
|
|
|
|
packaging_params.ad_cue_generator_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!ParseAdCues(absl::GetFlag(FLAGS_ad_cues),
|
|
|
|
&ad_cue_generator_params.cue_points)) {
|
|
|
|
return std::nullopt;
|
2017-11-18 01:45:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
ChunkingParams& chunking_params = packaging_params.chunking_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
chunking_params.segment_duration_in_seconds =
|
|
|
|
absl::GetFlag(FLAGS_segment_duration);
|
|
|
|
chunking_params.subsegment_duration_in_seconds =
|
|
|
|
absl::GetFlag(FLAGS_fragment_duration);
|
|
|
|
chunking_params.low_latency_dash_mode =
|
|
|
|
absl::GetFlag(FLAGS_low_latency_dash_mode);
|
|
|
|
chunking_params.segment_sap_aligned =
|
|
|
|
absl::GetFlag(FLAGS_segment_sap_aligned);
|
|
|
|
chunking_params.subsegment_sap_aligned =
|
|
|
|
absl::GetFlag(FLAGS_fragment_sap_aligned);
|
2014-05-09 01:23:54 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
int num_key_providers = 0;
|
|
|
|
EncryptionParams& encryption_params = packaging_params.encryption_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_enable_widevine_encryption)) {
|
2017-05-22 20:31:41 +00:00
|
|
|
encryption_params.key_provider = KeyProvider::kWidevine;
|
|
|
|
++num_key_providers;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_enable_playready_encryption)) {
|
2018-04-20 18:06:36 +00:00
|
|
|
encryption_params.key_provider = KeyProvider::kPlayReady;
|
2017-05-22 20:31:41 +00:00
|
|
|
++num_key_providers;
|
2015-11-05 01:49:35 +00:00
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_enable_raw_key_encryption)) {
|
2017-05-22 20:31:41 +00:00
|
|
|
encryption_params.key_provider = KeyProvider::kRawKey;
|
|
|
|
++num_key_providers;
|
2015-11-05 01:49:35 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (num_key_providers > 1) {
|
|
|
|
LOG(ERROR) << "Only one of --enable_widevine_encryption, "
|
|
|
|
"--enable_playready_encryption, "
|
2017-10-17 23:03:08 +00:00
|
|
|
"--enable_raw_key_encryption can be enabled.";
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2015-11-05 01:49:35 +00:00
|
|
|
}
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!ParseProtectionSystems(absl::GetFlag(FLAGS_protection_systems),
|
2018-08-10 20:31:17 +00:00
|
|
|
&encryption_params.protection_systems)) {
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2018-08-06 23:12:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
if (encryption_params.key_provider != KeyProvider::kNone) {
|
2023-12-01 17:32:19 +00:00
|
|
|
encryption_params.clear_lead_in_seconds = absl::GetFlag(FLAGS_clear_lead);
|
2017-07-05 23:47:55 +00:00
|
|
|
if (!GetProtectionScheme(&encryption_params.protection_scheme))
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
|
|
|
encryption_params.crypt_byte_block = absl::GetFlag(FLAGS_crypt_byte_block);
|
|
|
|
encryption_params.skip_byte_block = absl::GetFlag(FLAGS_skip_byte_block);
|
2020-02-10 08:31:45 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
encryption_params.crypto_period_duration_in_seconds =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_crypto_period_duration);
|
|
|
|
encryption_params.vp9_subsample_encryption =
|
|
|
|
absl::GetFlag(FLAGS_vp9_subsample_encryption);
|
2017-05-22 20:31:41 +00:00
|
|
|
encryption_params.stream_label_func = std::bind(
|
2023-12-01 17:32:19 +00:00
|
|
|
&Packager::DefaultStreamLabelFunction,
|
|
|
|
absl::GetFlag(FLAGS_max_sd_pixels), absl::GetFlag(FLAGS_max_hd_pixels),
|
|
|
|
absl::GetFlag(FLAGS_max_uhd1_pixels), std::placeholders::_1);
|
2020-06-09 20:50:55 +00:00
|
|
|
encryption_params.playready_extra_header_data =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_playready_extra_header_data);
|
2015-10-28 17:23:08 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
switch (encryption_params.key_provider) {
|
|
|
|
case KeyProvider::kWidevine: {
|
|
|
|
WidevineEncryptionParams& widevine = encryption_params.widevine;
|
2023-12-01 17:32:19 +00:00
|
|
|
widevine.key_server_url = absl::GetFlag(FLAGS_key_server_url);
|
2017-05-22 20:31:41 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
widevine.content_id = absl::GetFlag(FLAGS_content_id).bytes;
|
|
|
|
widevine.policy = absl::GetFlag(FLAGS_policy);
|
|
|
|
widevine.group_id = absl::GetFlag(FLAGS_group_id).bytes;
|
|
|
|
widevine.enable_entitlement_license =
|
|
|
|
absl::GetFlag(FLAGS_enable_entitlement_license);
|
2017-06-14 23:18:16 +00:00
|
|
|
if (!GetWidevineSigner(&widevine.signer))
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2017-03-21 23:14:46 +00:00
|
|
|
}
|
2018-04-20 18:06:36 +00:00
|
|
|
case KeyProvider::kPlayReady: {
|
|
|
|
PlayReadyEncryptionParams& playready = encryption_params.playready;
|
2023-12-01 17:32:19 +00:00
|
|
|
playready.key_server_url = absl::GetFlag(FLAGS_playready_server_url);
|
|
|
|
playready.program_identifier = absl::GetFlag(FLAGS_program_identifier);
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2017-03-11 02:49:55 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kRawKey: {
|
2017-09-20 22:49:00 +00:00
|
|
|
if (!GetRawKeyParams(&encryption_params.raw_key))
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kNone:
|
|
|
|
break;
|
2014-06-11 00:20:00 +00:00
|
|
|
}
|
2014-06-26 17:42:12 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
num_key_providers = 0;
|
|
|
|
DecryptionParams& decryption_params = packaging_params.decryption_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_enable_widevine_decryption)) {
|
2017-05-22 20:31:41 +00:00
|
|
|
decryption_params.key_provider = KeyProvider::kWidevine;
|
|
|
|
++num_key_providers;
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (absl::GetFlag(FLAGS_enable_raw_key_decryption)) {
|
2017-05-22 20:31:41 +00:00
|
|
|
decryption_params.key_provider = KeyProvider::kRawKey;
|
|
|
|
++num_key_providers;
|
2017-01-07 02:40:37 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
if (num_key_providers > 1) {
|
|
|
|
LOG(ERROR) << "Only one of --enable_widevine_decryption, "
|
2017-10-17 23:03:08 +00:00
|
|
|
"--enable_raw_key_decryption can be enabled.";
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
switch (decryption_params.key_provider) {
|
|
|
|
case KeyProvider::kWidevine: {
|
|
|
|
WidevineDecryptionParams& widevine = decryption_params.widevine;
|
2023-12-01 17:32:19 +00:00
|
|
|
widevine.key_server_url = absl::GetFlag(FLAGS_key_server_url);
|
2017-06-14 23:18:16 +00:00
|
|
|
if (!GetWidevineSigner(&widevine.signer))
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2015-08-04 22:26:15 +00:00
|
|
|
}
|
2017-05-22 20:31:41 +00:00
|
|
|
case KeyProvider::kRawKey: {
|
2017-09-20 22:49:00 +00:00
|
|
|
if (!GetRawKeyParams(&decryption_params.raw_key))
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2014-05-22 19:39:30 +00:00
|
|
|
}
|
2018-04-20 18:06:36 +00:00
|
|
|
case KeyProvider::kPlayReady:
|
2017-06-14 23:18:16 +00:00
|
|
|
case KeyProvider::kNone:
|
2017-05-22 20:31:41 +00:00
|
|
|
break;
|
2014-05-22 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
Mp4OutputParams& mp4_params = packaging_params.mp4_output_params;
|
2018-06-15 18:59:02 +00:00
|
|
|
mp4_params.generate_sidx_in_media_segments =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_generate_sidx_in_media_segments);
|
|
|
|
mp4_params.include_pssh_in_stream =
|
|
|
|
absl::GetFlag(FLAGS_mp4_include_pssh_in_stream);
|
|
|
|
mp4_params.low_latency_dash_mode = absl::GetFlag(FLAGS_low_latency_dash_mode);
|
2017-05-22 20:31:41 +00:00
|
|
|
|
2018-07-03 23:52:05 +00:00
|
|
|
packaging_params.transport_stream_timestamp_offset_ms =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_transport_stream_timestamp_offset_ms);
|
2024-02-08 18:39:50 +00:00
|
|
|
packaging_params.default_text_zero_bias_ms =
|
|
|
|
absl::GetFlag(FLAGS_default_text_zero_bias_ms);
|
2018-07-03 23:52:05 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
packaging_params.output_media_info = absl::GetFlag(FLAGS_output_media_info);
|
2017-05-22 20:31:41 +00:00
|
|
|
|
|
|
|
MpdParams& mpd_params = packaging_params.mpd_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
mpd_params.mpd_output = absl::GetFlag(FLAGS_mpd_output);
|
|
|
|
|
|
|
|
std::vector<std::string> base_urls =
|
|
|
|
SplitAndTrimSkipEmpty(absl::GetFlag(FLAGS_base_urls), ',');
|
|
|
|
|
|
|
|
mpd_params.base_urls = base_urls;
|
|
|
|
mpd_params.min_buffer_time = absl::GetFlag(FLAGS_min_buffer_time);
|
|
|
|
mpd_params.minimum_update_period = absl::GetFlag(FLAGS_minimum_update_period);
|
|
|
|
mpd_params.suggested_presentation_delay =
|
|
|
|
absl::GetFlag(FLAGS_suggested_presentation_delay);
|
|
|
|
mpd_params.time_shift_buffer_depth =
|
|
|
|
absl::GetFlag(FLAGS_time_shift_buffer_depth);
|
2018-05-01 17:47:06 +00:00
|
|
|
mpd_params.preserved_segments_outside_live_window =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_preserved_segments_outside_live_window);
|
|
|
|
mpd_params.use_segment_list = absl::GetFlag(FLAGS_dash_force_segment_list);
|
2018-03-17 01:37:53 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!absl::GetFlag(FLAGS_utc_timings).empty()) {
|
|
|
|
std::vector<KVPair> pairs = SplitStringIntoKeyValuePairs(
|
|
|
|
absl::GetFlag(FLAGS_utc_timings), '=', ',');
|
|
|
|
if (pairs.empty()) {
|
2018-03-17 01:37:53 +00:00
|
|
|
LOG(ERROR) << "Invalid --utc_timings scheme_id_uri/value pairs.";
|
2023-12-01 17:32:19 +00:00
|
|
|
return std::nullopt;
|
2018-03-17 01:37:53 +00:00
|
|
|
}
|
|
|
|
for (const auto& string_pair : pairs) {
|
|
|
|
mpd_params.utc_timings.push_back({string_pair.first, string_pair.second});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
mpd_params.default_language = absl::GetFlag(FLAGS_default_language);
|
|
|
|
mpd_params.default_text_language = absl::GetFlag(FLAGS_default_text_language);
|
|
|
|
mpd_params.generate_static_live_mpd =
|
|
|
|
absl::GetFlag(FLAGS_generate_static_live_mpd);
|
2018-03-17 01:37:53 +00:00
|
|
|
mpd_params.generate_dash_if_iop_compliant_mpd =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_generate_dash_if_iop_compliant_mpd);
|
2017-09-25 19:18:50 +00:00
|
|
|
mpd_params.allow_approximate_segment_timeline =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_allow_approximate_segment_timeline);
|
|
|
|
mpd_params.allow_codec_switching = absl::GetFlag(FLAGS_allow_codec_switching);
|
|
|
|
mpd_params.include_mspr_pro =
|
|
|
|
absl::GetFlag(FLAGS_include_mspr_pro_for_playready);
|
|
|
|
mpd_params.low_latency_dash_mode = absl::GetFlag(FLAGS_low_latency_dash_mode);
|
2017-05-22 20:31:41 +00:00
|
|
|
|
|
|
|
HlsParams& hls_params = packaging_params.hls_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!GetHlsPlaylistType(absl::GetFlag(FLAGS_hls_playlist_type),
|
|
|
|
&hls_params.playlist_type)) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
hls_params.master_playlist_output =
|
|
|
|
absl::GetFlag(FLAGS_hls_master_playlist_output);
|
|
|
|
hls_params.base_url = absl::GetFlag(FLAGS_hls_base_url);
|
|
|
|
hls_params.key_uri = absl::GetFlag(FLAGS_hls_key_uri);
|
|
|
|
hls_params.time_shift_buffer_depth =
|
|
|
|
absl::GetFlag(FLAGS_time_shift_buffer_depth);
|
2018-05-01 17:47:06 +00:00
|
|
|
hls_params.preserved_segments_outside_live_window =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::GetFlag(FLAGS_preserved_segments_outside_live_window);
|
|
|
|
hls_params.default_language = absl::GetFlag(FLAGS_default_language);
|
|
|
|
hls_params.default_text_language = absl::GetFlag(FLAGS_default_text_language);
|
|
|
|
hls_params.media_sequence_number =
|
|
|
|
absl::GetFlag(FLAGS_hls_media_sequence_number);
|
2024-02-15 20:06:06 +00:00
|
|
|
hls_params.start_time_offset = absl::GetFlag(FLAGS_hls_start_time_offset);
|
2017-05-22 20:31:41 +00:00
|
|
|
|
2017-05-23 02:41:26 +00:00
|
|
|
TestParams& test_params = packaging_params.test_params;
|
2023-12-01 17:32:19 +00:00
|
|
|
test_params.dump_stream_info = absl::GetFlag(FLAGS_dump_stream_info);
|
|
|
|
test_params.inject_fake_clock = absl::GetFlag(FLAGS_use_fake_clock_for_muxer);
|
|
|
|
if (!absl::GetFlag(FLAGS_test_packager_version).empty())
|
|
|
|
test_params.injected_library_version =
|
|
|
|
absl::GetFlag(FLAGS_test_packager_version);
|
2017-05-23 02:41:26 +00:00
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
return packaging_params;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 05:17:54 +00:00
|
|
|
int PackagerMain(int argc, char** argv) {
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::FlagsUsageConfig flag_config;
|
|
|
|
flag_config.version_string = []() -> std::string {
|
|
|
|
return "packager version " + shaka::Packager::GetLibraryVersion() + "\n";
|
|
|
|
};
|
|
|
|
flag_config.contains_help_flags =
|
|
|
|
[](absl::string_view flag_file_name) -> bool { return true; };
|
|
|
|
absl::SetFlagsUsageConfig(flag_config);
|
|
|
|
|
|
|
|
auto usage = absl::StrFormat(kUsage, argv[0]);
|
|
|
|
absl::SetProgramUsageMessage(usage);
|
|
|
|
|
|
|
|
auto remaining_args = absl::ParseCommandLine(argc, argv);
|
|
|
|
if (absl::GetFlag(FLAGS_licenses)) {
|
2018-03-24 01:08:00 +00:00
|
|
|
for (const char* line : kLicenseNotice)
|
|
|
|
std::cout << line << std::endl;
|
|
|
|
return kSuccess;
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
|
|
|
|
if (remaining_args.size() < 2) {
|
|
|
|
std::cerr << "Usage: " << absl::ProgramUsageMessage();
|
2015-12-21 23:10:17 +00:00
|
|
|
return kSuccess;
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
|
|
|
|
if (absl::GetFlag(FLAGS_quiet)) {
|
|
|
|
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kWarning);
|
|
|
|
}
|
|
|
|
|
|
|
|
absl::InitializeLog();
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2017-10-17 23:03:08 +00:00
|
|
|
if (!ValidateWidevineCryptoFlags() || !ValidateRawKeyCryptoFlags() ||
|
2023-12-01 17:32:19 +00:00
|
|
|
!ValidatePRCryptoFlags() || !ValidateCryptoFlags() ||
|
|
|
|
!ValidateRetiredFlags()) {
|
2014-10-13 22:06:48 +00:00
|
|
|
return kArgumentValidationFailed;
|
2017-01-05 17:32:17 +00:00
|
|
|
}
|
2014-10-13 22:06:48 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::optional<PackagingParams> packaging_params = GetPackagingParams();
|
2017-05-22 20:31:41 +00:00
|
|
|
if (!packaging_params)
|
|
|
|
return kArgumentValidationFailed;
|
|
|
|
|
|
|
|
std::vector<StreamDescriptor> stream_descriptors;
|
2023-12-01 17:32:19 +00:00
|
|
|
for (size_t i = 1; i < remaining_args.size(); ++i) {
|
|
|
|
std::optional<StreamDescriptor> stream_descriptor =
|
|
|
|
ParseStreamDescriptor(remaining_args[i]);
|
2017-05-22 20:31:41 +00:00
|
|
|
if (!stream_descriptor)
|
2014-10-13 22:06:48 +00:00
|
|
|
return kArgumentValidationFailed;
|
2017-05-22 20:31:41 +00:00
|
|
|
stream_descriptors.push_back(stream_descriptor.value());
|
|
|
|
}
|
2024-02-14 17:21:11 +00:00
|
|
|
|
|
|
|
if (absl::GetFlag(FLAGS_force_cl_index)) {
|
|
|
|
int index = 0;
|
|
|
|
for (auto& descriptor : stream_descriptors) {
|
|
|
|
descriptor.index = index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-13 22:16:08 +00:00
|
|
|
Packager packager;
|
2017-06-29 22:23:53 +00:00
|
|
|
Status status =
|
2017-05-22 20:31:41 +00:00
|
|
|
packager.Initialize(packaging_params.value(), stream_descriptors);
|
|
|
|
if (!status.ok()) {
|
|
|
|
LOG(ERROR) << "Failed to initialize packager: " << status.ToString();
|
|
|
|
return kArgumentValidationFailed;
|
|
|
|
}
|
|
|
|
status = packager.Run();
|
|
|
|
if (!status.ok()) {
|
|
|
|
LOG(ERROR) << "Packaging Error: " << status.ToString();
|
|
|
|
return kPackagingFailed;
|
2014-06-27 23:07:36 +00:00
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
if (!absl::GetFlag(FLAGS_quiet))
|
2019-10-08 05:56:42 +00:00
|
|
|
printf("Packaging completed successfully.\n");
|
2017-05-22 20:31:41 +00:00
|
|
|
return kSuccess;
|
2014-10-03 05:17:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
} // namespace
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-10-03 05:17:54 +00:00
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Windows wmain, which converts wide character arguments to UTF-8.
|
|
|
|
int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) {
|
2022-06-02 16:40:34 +00:00
|
|
|
std::unique_ptr<char*[], std::function<void(char**)>> utf8_argv(
|
2016-08-14 22:28:21 +00:00
|
|
|
new char*[argc], [argc](char** utf8_args) {
|
|
|
|
// TODO(tinskip): This leaks, but if this code is enabled, it crashes.
|
|
|
|
// Figure out why. I suspect gflags does something funny with the
|
|
|
|
// argument array.
|
|
|
|
// for (int idx = 0; idx < argc; ++idx)
|
|
|
|
// delete[] utf8_args[idx];
|
|
|
|
delete[] utf8_args;
|
|
|
|
});
|
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
2023-12-01 17:32:19 +00:00
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
for (int idx = 0; idx < argc; ++idx) {
|
|
|
|
std::string utf8_arg(converter.to_bytes(argv[idx]));
|
|
|
|
utf8_arg += '\0';
|
|
|
|
utf8_argv[idx] = new char[utf8_arg.size()];
|
|
|
|
memcpy(utf8_argv[idx], &utf8_arg[0], utf8_arg.size());
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
|
|
|
|
// Because we just converted wide character args into UTF8, and because
|
|
|
|
// std::filesystem::u8path is used to interpret all std::string paths as
|
|
|
|
// UTF8, we should set the locale to UTF8 as well, for the transition point
|
|
|
|
// to C library functions like fopen to work correctly with non-ASCII paths.
|
|
|
|
std::setlocale(LC_ALL, ".UTF8");
|
|
|
|
|
2017-05-22 20:31:41 +00:00
|
|
|
return shaka::PackagerMain(argc, utf8_argv.get());
|
2016-08-14 22:28:21 +00:00
|
|
|
}
|
|
|
|
#else
|
2014-10-03 05:17:54 +00:00
|
|
|
int main(int argc, char** argv) {
|
2017-05-22 20:31:41 +00:00
|
|
|
return shaka::PackagerMain(argc, argv);
|
2014-05-09 01:23:54 +00:00
|
|
|
}
|
2016-08-14 22:28:21 +00:00
|
|
|
#endif // defined(OS_WIN)
|