From df3412f68db7b0ea1e088a0d8e629cb47893db56 Mon Sep 17 00:00:00 2001 From: Frank Galligan Date: Tue, 12 Apr 2016 22:39:50 -0700 Subject: [PATCH] Add support for setting VP9 profile and level to sample_muxer. BUG=https://bugs.chromium.org/p/webm/issues/detail?id=1179 Change-Id: I20ffc213764c3c1c35563178b6e8e1e0031760b6 --- sample_muxer.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/sample_muxer.cc b/sample_muxer.cc index bb4b202..1835b36 100644 --- a/sample_muxer.cc +++ b/sample_muxer.cc @@ -60,6 +60,10 @@ void Usage() { printf(" -display_height Display height in pixels\n"); printf(" -stereo_mode 3D video mode\n"); printf("\n"); + printf("VP9 options:\n"); + printf(" -profile VP9 profile\n"); + printf(" -level VP9 level\n"); + printf("\n"); printf("Cues options:\n"); printf(" -output_cues_block_number >0 outputs cue block number\n"); printf(" -cues_before_clusters >0 puts Cues before Clusters\n"); @@ -172,6 +176,8 @@ int main(int argc, char* argv[]) { uint64_t display_width = 0; uint64_t display_height = 0; uint64_t stereo_mode = 0; + int vp9_profile = -1; // No profile set. + int vp9_level = -1; // No level set. metadata_files_t metadata_files; @@ -234,6 +240,10 @@ int main(int argc, char* argv[]) { display_height = strtol(argv[++i], &end, 10); } else if (!strcmp("-stereo_mode", argv[i]) && i < argc_check) { stereo_mode = strtol(argv[++i], &end, 10); + } else if (!strcmp("-profile", argv[i]) && i < argc_check) { + vp9_profile = static_cast(strtol(argv[++i], &end, 10)); + } else if (!strcmp("-level", argv[i]) && i < argc_check) { + vp9_level = static_cast(strtol(argv[++i], &end, 10)); } else if (!strcmp("-output_cues_block_number", argv[i]) && i < argc_check) { output_cues_block_number = @@ -410,6 +420,49 @@ int main(int argc, char* argv[]) { if (rate > 0.0) { video->set_frame_rate(rate); } + + if (vp9_profile >= 0 || vp9_level >= 0) { + const int kMaxVp9PrivateSize = 6; + unsigned char private_data[kMaxVp9PrivateSize]; + int private_size = 0; + if (vp9_profile >= 0) { + if (vp9_profile < 0 || vp9_profile > 3) { + printf("\n VP9 profile(%d) is not valid.\n", vp9_profile); + return EXIT_FAILURE; + } + const uint8_t kVp9ProfileId = 1; + const uint8_t kVp9ProfileIdLength = 1; + private_data[private_size++] = kVp9ProfileId; + private_data[private_size++] = kVp9ProfileIdLength; + private_data[private_size++] = vp9_profile; + } + + if (vp9_level >= 0) { + const int kNumLevels = 14; + const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40, + 41, 50, 51, 52, 60, 61, 62}; + bool level_is_valid = false; + for (int i = 0; i < kNumLevels; ++i) { + if (vp9_level == levels[i]) { + level_is_valid = true; + break; + } + } + if (!level_is_valid) { + printf("\n VP9 level(%d) is not valid.\n", vp9_level); + return EXIT_FAILURE; + } + const uint8_t kVp9LevelId = 2; + const uint8_t kVp9LevelIdLength = 1; + private_data[private_size++] = kVp9LevelId; + private_data[private_size++] = kVp9LevelIdLength; + private_data[private_size++] = vp9_level; + } + if (!video->SetCodecPrivate(private_data, private_size)) { + printf("\n Could not add video private data.\n"); + return EXIT_FAILURE; + } + } } else if (track_type == Track::kAudio && output_audio) { // Get the audio track from the parser const mkvparser::AudioTrack* const pAudioTrack =