Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 1 | // Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style license |
| 4 | // that can be found in the LICENSE file in the root of the source |
| 5 | // tree. An additional intellectual property rights grant can be found |
| 6 | // in the file PATENTS. All contributing project authors may |
| 7 | // be found in the AUTHORS file in the root of the source tree. |
| 8 | // |
| 9 | // This sample application demonstrates how to use the Matroska parser |
| 10 | // library, which allows clients to handle a Matroska format file. |
Tom Finegan | e020ffd | 2016-03-09 13:55:40 -0800 | [diff] [blame] | 11 | #include <cstdio> |
| 12 | #include <cstdlib> |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 13 | #include <memory> |
Tom Finegan | e020ffd | 2016-03-09 13:55:40 -0800 | [diff] [blame] | 14 | #include <new> |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 15 | |
Tom Finegan | 504e0f2 | 2016-03-21 11:20:48 -0700 | [diff] [blame] | 16 | #include "mkvparser/mkvparser.h" |
| 17 | #include "mkvparser/mkvreader.h" |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 18 | |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 19 | namespace { |
| 20 | const wchar_t* utf8towcs(const char* str) { |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 21 | if (str == NULL) |
| 22 | return NULL; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 23 | |
| 24 | // TODO: this probably requires that the locale be |
| 25 | // configured somehow: |
| 26 | |
| 27 | const size_t size = mbstowcs(NULL, str, 0); |
| 28 | |
James Zern | 82b7e5f | 2015-08-14 10:57:48 -0700 | [diff] [blame] | 29 | if (size == 0 || size == static_cast<size_t>(-1)) |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 30 | return NULL; |
| 31 | |
James Zern | 04d7809 | 2015-08-13 23:06:41 -0700 | [diff] [blame] | 32 | wchar_t* const val = new (std::nothrow) wchar_t[size + 1]; |
| 33 | if (val == NULL) |
| 34 | return NULL; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 35 | |
| 36 | mbstowcs(val, str, size); |
| 37 | val[size] = L'\0'; |
| 38 | |
| 39 | return val; |
| 40 | } |
| 41 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 42 | bool InputHasCues(const mkvparser::Segment* const segment) { |
| 43 | const mkvparser::Cues* const cues = segment->GetCues(); |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 44 | if (cues == NULL) |
| 45 | return false; |
| 46 | |
| 47 | while (!cues->DoneParsing()) |
| 48 | cues->LoadCuePoint(); |
| 49 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 50 | const mkvparser::CuePoint* const cue_point = cues->GetFirst(); |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 51 | if (cue_point == NULL) |
| 52 | return false; |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 57 | bool MasteringMetadataValuePresent(double value) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 58 | return value != mkvparser::MasteringMetadata::kValueNotPresent; |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | bool ColourValuePresent(long long value) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 62 | return value != mkvparser::Colour::kValueNotPresent; |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 63 | } |
| 64 | } // namespace |
| 65 | |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 66 | int main(int argc, char* argv[]) { |
| 67 | if (argc == 1) { |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 68 | printf("Mkv Parser Sample Application\n"); |
| 69 | printf(" Usage: %s <input file> \n", argv[0]); |
| 70 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 73 | mkvparser::MkvReader reader; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 74 | |
| 75 | if (reader.Open(argv[1])) { |
| 76 | printf("\n Filename is invalid or error while opening.\n"); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 77 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | int maj, min, build, rev; |
| 81 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 82 | mkvparser::GetVersion(maj, min, build, rev); |
Tom Finegan | 58711e8 | 2016-08-24 12:03:08 -0700 | [diff] [blame] | 83 | printf("\t\t libwebm version: %d.%d.%d.%d\n", maj, min, build, rev); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 84 | |
| 85 | long long pos = 0; |
| 86 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 87 | mkvparser::EBMLHeader ebmlHeader; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 88 | |
Tom Finegan | 714f3c4 | 2015-09-04 10:18:20 -0700 | [diff] [blame] | 89 | long long ret = ebmlHeader.Parse(&reader, pos); |
| 90 | if (ret < 0) { |
| 91 | printf("\n EBMLHeader::Parse() failed."); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 92 | return EXIT_FAILURE; |
Tom Finegan | 714f3c4 | 2015-09-04 10:18:20 -0700 | [diff] [blame] | 93 | } |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 94 | |
| 95 | printf("\t\t\t EBML Header\n"); |
| 96 | printf("\t\tEBML Version\t\t: %lld\n", ebmlHeader.m_version); |
| 97 | printf("\t\tEBML MaxIDLength\t: %lld\n", ebmlHeader.m_maxIdLength); |
| 98 | printf("\t\tEBML MaxSizeLength\t: %lld\n", ebmlHeader.m_maxSizeLength); |
| 99 | printf("\t\tDoc Type\t\t: %s\n", ebmlHeader.m_docType); |
| 100 | printf("\t\tPos\t\t\t: %lld\n", pos); |
| 101 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 102 | typedef mkvparser::Segment seg_t; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 103 | seg_t* pSegment_; |
| 104 | |
Tom Finegan | 714f3c4 | 2015-09-04 10:18:20 -0700 | [diff] [blame] | 105 | ret = seg_t::CreateInstance(&reader, pos, pSegment_); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 106 | if (ret) { |
| 107 | printf("\n Segment::CreateInstance() failed."); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 108 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Lisa Velden | d707c67 | 2018-01-22 11:41:20 +0100 | [diff] [blame] | 111 | const std::unique_ptr<seg_t> pSegment(pSegment_); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 112 | |
| 113 | ret = pSegment->Load(); |
| 114 | if (ret < 0) { |
| 115 | printf("\n Segment::Load() failed."); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 116 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 119 | const mkvparser::SegmentInfo* const pSegmentInfo = pSegment->GetInfo(); |
James Zern | d9bdade | 2015-08-21 16:56:32 -0700 | [diff] [blame] | 120 | if (pSegmentInfo == NULL) { |
| 121 | printf("\n Segment::GetInfo() failed."); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 122 | return EXIT_FAILURE; |
James Zern | d9bdade | 2015-08-21 16:56:32 -0700 | [diff] [blame] | 123 | } |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 124 | |
| 125 | const long long timeCodeScale = pSegmentInfo->GetTimeCodeScale(); |
| 126 | const long long duration_ns = pSegmentInfo->GetDuration(); |
| 127 | |
| 128 | const char* const pTitle_ = pSegmentInfo->GetTitleAsUTF8(); |
| 129 | const wchar_t* const pTitle = utf8towcs(pTitle_); |
| 130 | |
| 131 | const char* const pMuxingApp_ = pSegmentInfo->GetMuxingAppAsUTF8(); |
| 132 | const wchar_t* const pMuxingApp = utf8towcs(pMuxingApp_); |
| 133 | |
| 134 | const char* const pWritingApp_ = pSegmentInfo->GetWritingAppAsUTF8(); |
| 135 | const wchar_t* const pWritingApp = utf8towcs(pWritingApp_); |
| 136 | |
| 137 | printf("\n"); |
| 138 | printf("\t\t\t Segment Info\n"); |
| 139 | printf("\t\tTimeCodeScale\t\t: %lld \n", timeCodeScale); |
| 140 | printf("\t\tDuration\t\t: %lld\n", duration_ns); |
| 141 | |
| 142 | const double duration_sec = double(duration_ns) / 1000000000; |
| 143 | printf("\t\tDuration(secs)\t\t: %7.3lf\n", duration_sec); |
| 144 | |
| 145 | if (pTitle == NULL) |
| 146 | printf("\t\tTrack Name\t\t: NULL\n"); |
| 147 | else { |
| 148 | printf("\t\tTrack Name\t\t: %ls\n", pTitle); |
| 149 | delete[] pTitle; |
| 150 | } |
| 151 | |
| 152 | if (pMuxingApp == NULL) |
| 153 | printf("\t\tMuxing App\t\t: NULL\n"); |
| 154 | else { |
| 155 | printf("\t\tMuxing App\t\t: %ls\n", pMuxingApp); |
| 156 | delete[] pMuxingApp; |
| 157 | } |
| 158 | |
| 159 | if (pWritingApp == NULL) |
| 160 | printf("\t\tWriting App\t\t: NULL\n"); |
| 161 | else { |
| 162 | printf("\t\tWriting App\t\t: %ls\n", pWritingApp); |
| 163 | delete[] pWritingApp; |
| 164 | } |
| 165 | |
| 166 | // pos of segment payload |
| 167 | printf("\t\tPosition(Segment)\t: %lld\n", pSegment->m_start); |
| 168 | |
| 169 | // size of segment payload |
| 170 | printf("\t\tSize(Segment)\t\t: %lld\n", pSegment->m_size); |
| 171 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 172 | const mkvparser::Tracks* pTracks = pSegment->GetTracks(); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 173 | |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 174 | unsigned long track_num = 0; |
| 175 | const unsigned long num_tracks = pTracks->GetTracksCount(); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 176 | |
| 177 | printf("\n\t\t\t Track Info\n"); |
| 178 | |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 179 | while (track_num != num_tracks) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 180 | const mkvparser::Track* const pTrack = |
Tom Finegan | e64bf75 | 2016-03-18 09:32:52 -0700 | [diff] [blame] | 181 | pTracks->GetTrackByIndex(track_num++); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 182 | |
Vignesh Venkatasubramanian | 867f189 | 2014-04-14 12:05:21 -0700 | [diff] [blame] | 183 | if (pTrack == NULL) |
| 184 | continue; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 185 | |
| 186 | const long trackType = pTrack->GetType(); |
| 187 | const long trackNumber = pTrack->GetNumber(); |
| 188 | const unsigned long long trackUid = pTrack->GetUid(); |
| 189 | const wchar_t* const pTrackName = utf8towcs(pTrack->GetNameAsUTF8()); |
| 190 | |
| 191 | printf("\t\tTrack Type\t\t: %ld\n", trackType); |
| 192 | printf("\t\tTrack Number\t\t: %ld\n", trackNumber); |
| 193 | printf("\t\tTrack Uid\t\t: %lld\n", trackUid); |
| 194 | |
| 195 | if (pTrackName == NULL) |
| 196 | printf("\t\tTrack Name\t\t: NULL\n"); |
| 197 | else { |
| 198 | printf("\t\tTrack Name\t\t: %ls \n", pTrackName); |
| 199 | delete[] pTrackName; |
| 200 | } |
| 201 | |
| 202 | const char* const pCodecId = pTrack->GetCodecId(); |
| 203 | |
| 204 | if (pCodecId == NULL) |
| 205 | printf("\t\tCodec Id\t\t: NULL\n"); |
| 206 | else |
| 207 | printf("\t\tCodec Id\t\t: %s\n", pCodecId); |
| 208 | |
Tom Finegan | fa182de | 2016-08-26 21:06:51 -0700 | [diff] [blame] | 209 | size_t codec_private_size = 0; |
| 210 | if (pTrack->GetCodecPrivate(codec_private_size)) { |
| 211 | printf("\t\tCodec private length: %u bytes\n", |
| 212 | static_cast<unsigned int>(codec_private_size)); |
| 213 | } |
| 214 | |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 215 | const char* const pCodecName_ = pTrack->GetCodecNameAsUTF8(); |
| 216 | const wchar_t* const pCodecName = utf8towcs(pCodecName_); |
| 217 | |
| 218 | if (pCodecName == NULL) |
| 219 | printf("\t\tCodec Name\t\t: NULL\n"); |
| 220 | else { |
| 221 | printf("\t\tCodec Name\t\t: %ls\n", pCodecName); |
| 222 | delete[] pCodecName; |
| 223 | } |
| 224 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 225 | if (trackType == mkvparser::Track::kVideo) { |
| 226 | const mkvparser::VideoTrack* const pVideoTrack = |
| 227 | static_cast<const mkvparser::VideoTrack*>(pTrack); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 228 | |
| 229 | const long long width = pVideoTrack->GetWidth(); |
| 230 | printf("\t\tVideo Width\t\t: %lld\n", width); |
| 231 | |
| 232 | const long long height = pVideoTrack->GetHeight(); |
| 233 | printf("\t\tVideo Height\t\t: %lld\n", height); |
| 234 | |
| 235 | const double rate = pVideoTrack->GetFrameRate(); |
| 236 | printf("\t\tVideo Rate\t\t: %f\n", rate); |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 237 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 238 | const mkvparser::Colour* const colour = pVideoTrack->GetColour(); |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 239 | if (colour) { |
| 240 | printf("\t\tVideo Colour:\n"); |
Tom Finegan | f2fc28e | 2016-02-18 10:08:11 -0800 | [diff] [blame] | 241 | if (ColourValuePresent(colour->matrix_coefficients)) |
| 242 | printf("\t\t\tMatrixCoefficients: %lld\n", |
| 243 | colour->matrix_coefficients); |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 244 | if (ColourValuePresent(colour->bits_per_channel)) |
| 245 | printf("\t\t\tBitsPerChannel: %lld\n", colour->bits_per_channel); |
Tom Finegan | d7fc382 | 2016-02-12 11:28:30 -0800 | [diff] [blame] | 246 | if (ColourValuePresent(colour->chroma_subsampling_horz)) |
| 247 | printf("\t\t\tChromaSubsamplingHorz: %lld\n", |
| 248 | colour->chroma_subsampling_horz); |
| 249 | if (ColourValuePresent(colour->chroma_subsampling_vert)) |
| 250 | printf("\t\t\tChromaSubsamplingVert: %lld\n", |
| 251 | colour->chroma_subsampling_vert); |
| 252 | if (ColourValuePresent(colour->cb_subsampling_horz)) |
| 253 | printf("\t\t\tCbSubsamplingHorz: %lld\n", |
| 254 | colour->cb_subsampling_horz); |
| 255 | if (ColourValuePresent(colour->cb_subsampling_vert)) |
| 256 | printf("\t\t\tCbSubsamplingVert: %lld\n", |
| 257 | colour->cb_subsampling_vert); |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 258 | if (ColourValuePresent(colour->chroma_siting_horz)) |
| 259 | printf("\t\t\tChromaSitingHorz: %lld\n", colour->chroma_siting_horz); |
| 260 | if (ColourValuePresent(colour->chroma_siting_vert)) |
| 261 | printf("\t\t\tChromaSitingVert: %lld\n", colour->chroma_siting_vert); |
| 262 | if (ColourValuePresent(colour->range)) |
| 263 | printf("\t\t\tRange: %lld\n", colour->range); |
Tom Finegan | 2d09128 | 2016-02-18 12:02:18 -0800 | [diff] [blame] | 264 | if (ColourValuePresent(colour->transfer_characteristics)) |
| 265 | printf("\t\t\tTransferCharacteristics: %lld\n", |
| 266 | colour->transfer_characteristics); |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 267 | if (ColourValuePresent(colour->primaries)) |
| 268 | printf("\t\t\tPrimaries: %lld\n", colour->primaries); |
| 269 | if (ColourValuePresent(colour->max_cll)) |
| 270 | printf("\t\t\tMaxCLL: %lld\n", colour->max_cll); |
| 271 | if (ColourValuePresent(colour->max_fall)) |
| 272 | printf("\t\t\tMaxFALL: %lld\n", colour->max_fall); |
| 273 | if (colour->mastering_metadata) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 274 | const mkvparser::MasteringMetadata* const mm = |
Tom Finegan | 99981ee | 2016-02-12 09:19:37 -0800 | [diff] [blame] | 275 | colour->mastering_metadata; |
| 276 | printf("\t\t\tMastering Metadata:\n"); |
| 277 | if (MasteringMetadataValuePresent(mm->luminance_max)) |
| 278 | printf("\t\t\t\tLuminanceMax: %f\n", mm->luminance_max); |
| 279 | if (MasteringMetadataValuePresent(mm->luminance_min)) |
| 280 | printf("\t\t\t\tLuminanceMin: %f\n", mm->luminance_min); |
| 281 | if (mm->r) { |
| 282 | printf("\t\t\t\t\tPrimaryRChromaticityX: %f\n", mm->r->x); |
| 283 | printf("\t\t\t\t\tPrimaryRChromaticityY: %f\n", mm->r->y); |
| 284 | } |
| 285 | if (mm->g) { |
| 286 | printf("\t\t\t\t\tPrimaryGChromaticityX: %f\n", mm->g->x); |
| 287 | printf("\t\t\t\t\tPrimaryGChromaticityY: %f\n", mm->g->y); |
| 288 | } |
| 289 | if (mm->b) { |
| 290 | printf("\t\t\t\t\tPrimaryBChromaticityX: %f\n", mm->b->x); |
| 291 | printf("\t\t\t\t\tPrimaryBChromaticityY: %f\n", mm->b->y); |
| 292 | } |
| 293 | if (mm->white_point) { |
| 294 | printf("\t\t\t\t\tWhitePointChromaticityX: %f\n", |
| 295 | mm->white_point->x); |
| 296 | printf("\t\t\t\t\tWhitePointChromaticityY: %f\n", |
| 297 | mm->white_point->y); |
| 298 | } |
| 299 | } |
| 300 | } |
Tom Finegan | 9a3f2b5 | 2016-08-26 21:07:06 -0700 | [diff] [blame] | 301 | |
| 302 | const mkvparser::Projection* const projection = |
| 303 | pVideoTrack->GetProjection(); |
| 304 | if (projection) { |
| 305 | printf("\t\tVideo Projection:\n"); |
| 306 | if (projection->type != mkvparser::Projection::kTypeNotPresent) |
| 307 | printf("\t\t\tProjectionType: %d\n", |
| 308 | static_cast<int>(projection->type)); |
| 309 | if (projection->private_data) { |
| 310 | printf("\t\t\tProjectionPrivate: %u bytes\n", |
| 311 | static_cast<unsigned int>(projection->private_data_length)); |
| 312 | } |
| 313 | if (projection->pose_yaw != mkvparser::Projection::kValueNotPresent) |
| 314 | printf("\t\t\tProjectionPoseYaw: %f\n", projection->pose_yaw); |
| 315 | if (projection->pose_pitch != mkvparser::Projection::kValueNotPresent) |
| 316 | printf("\t\t\tProjectionPosePitch: %f\n", projection->pose_pitch); |
| 317 | if (projection->pose_roll != mkvparser::Projection::kValueNotPresent) |
| 318 | printf("\t\t\tProjectionPosePitch: %f\n", projection->pose_roll); |
| 319 | } |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 322 | if (trackType == mkvparser::Track::kAudio) { |
| 323 | const mkvparser::AudioTrack* const pAudioTrack = |
| 324 | static_cast<const mkvparser::AudioTrack*>(pTrack); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 325 | |
| 326 | const long long channels = pAudioTrack->GetChannels(); |
| 327 | printf("\t\tAudio Channels\t\t: %lld\n", channels); |
| 328 | |
| 329 | const long long bitDepth = pAudioTrack->GetBitDepth(); |
| 330 | printf("\t\tAudio BitDepth\t\t: %lld\n", bitDepth); |
| 331 | |
| 332 | const double sampleRate = pAudioTrack->GetSamplingRate(); |
| 333 | printf("\t\tAddio Sample Rate\t: %.3f\n", sampleRate); |
| 334 | |
| 335 | const long long codecDelay = pAudioTrack->GetCodecDelay(); |
| 336 | printf("\t\tAudio Codec Delay\t\t: %lld\n", codecDelay); |
| 337 | |
| 338 | const long long seekPreRoll = pAudioTrack->GetSeekPreRoll(); |
| 339 | printf("\t\tAudio Seek Pre Roll\t\t: %lld\n", seekPreRoll); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | printf("\n\n\t\t\t Cluster Info\n"); |
| 344 | const unsigned long clusterCount = pSegment->GetCount(); |
| 345 | |
| 346 | printf("\t\tCluster Count\t: %ld\n\n", clusterCount); |
| 347 | |
| 348 | if (clusterCount == 0) { |
| 349 | printf("\t\tSegment has no clusters.\n"); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 350 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 353 | const mkvparser::Cluster* pCluster = pSegment->GetFirst(); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 354 | |
Vignesh Venkatasubramanian | 5d91edf | 2016-05-13 10:41:16 -0700 | [diff] [blame] | 355 | while (pCluster != NULL && !pCluster->EOS()) { |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 356 | const long long timeCode = pCluster->GetTimeCode(); |
| 357 | printf("\t\tCluster Time Code\t: %lld\n", timeCode); |
| 358 | |
| 359 | const long long time_ns = pCluster->GetTime(); |
| 360 | printf("\t\tCluster Time (ns)\t: %lld\n", time_ns); |
| 361 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 362 | const mkvparser::BlockEntry* pBlockEntry; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 363 | |
| 364 | long status = pCluster->GetFirst(pBlockEntry); |
| 365 | |
| 366 | if (status < 0) // error |
| 367 | { |
| 368 | printf("\t\tError parsing first block of cluster\n"); |
| 369 | fflush(stdout); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 370 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Vignesh Venkatasubramanian | 5d91edf | 2016-05-13 10:41:16 -0700 | [diff] [blame] | 373 | while (pBlockEntry != NULL && !pBlockEntry->EOS()) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 374 | const mkvparser::Block* const pBlock = pBlockEntry->GetBlock(); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 375 | const long long trackNum = pBlock->GetTrackNumber(); |
| 376 | const unsigned long tn = static_cast<unsigned long>(trackNum); |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 377 | const mkvparser::Track* const pTrack = pTracks->GetTrackByNumber(tn); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 378 | |
| 379 | if (pTrack == NULL) |
| 380 | printf("\t\t\tBlock\t\t:UNKNOWN TRACK TYPE\n"); |
| 381 | else { |
| 382 | const long long trackType = pTrack->GetType(); |
| 383 | const int frameCount = pBlock->GetFrameCount(); |
| 384 | const long long time_ns = pBlock->GetTime(pCluster); |
| 385 | const long long discard_padding = pBlock->GetDiscardPadding(); |
| 386 | |
| 387 | printf("\t\t\tBlock\t\t:%s,%s,%15lld,%lld\n", |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 388 | (trackType == mkvparser::Track::kVideo) ? "V" : "A", |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 389 | pBlock->IsKey() ? "I" : "P", time_ns, discard_padding); |
| 390 | |
| 391 | for (int i = 0; i < frameCount; ++i) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 392 | const mkvparser::Block::Frame& theFrame = pBlock->GetFrame(i); |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 393 | const long size = theFrame.len; |
| 394 | const long long offset = theFrame.pos; |
| 395 | printf("\t\t\t %15ld,%15llx\n", size, offset); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | status = pCluster->GetNext(pBlockEntry, pBlockEntry); |
| 400 | |
| 401 | if (status < 0) { |
| 402 | printf("\t\t\tError parsing next block of cluster\n"); |
| 403 | fflush(stdout); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 404 | return EXIT_FAILURE; |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | pCluster = pSegment->GetNext(pCluster); |
| 409 | } |
| 410 | |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 411 | if (InputHasCues(pSegment.get())) { |
| 412 | // Walk them. |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 413 | const mkvparser::Cues* const cues = pSegment->GetCues(); |
| 414 | const mkvparser::CuePoint* cue = cues->GetFirst(); |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 415 | int cue_point_num = 1; |
| 416 | |
| 417 | printf("\t\tCues\n"); |
| 418 | do { |
Leonel Togniolli | d3a44cd | 2015-04-09 03:48:38 +0100 | [diff] [blame] | 419 | for (track_num = 0; track_num < num_tracks; ++track_num) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 420 | const mkvparser::Track* const track = |
Leonel Togniolli | d3a44cd | 2015-04-09 03:48:38 +0100 | [diff] [blame] | 421 | pTracks->GetTrackByIndex(track_num); |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 422 | const mkvparser::CuePoint::TrackPosition* const track_pos = |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 423 | cue->Find(track); |
| 424 | |
| 425 | if (track_pos != NULL) { |
| 426 | const char track_type = |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 427 | (track->GetType() == mkvparser::Track::kVideo) ? 'V' : 'A'; |
Vignesh Venkatasubramanian | 867f189 | 2014-04-14 12:05:21 -0700 | [diff] [blame] | 428 | printf( |
| 429 | "\t\t\tCue Point %4d Track %3lu(%c) Time %14lld " |
| 430 | "Block %4lld Pos %8llx\n", |
Leonel Togniolli | d3a44cd | 2015-04-09 03:48:38 +0100 | [diff] [blame] | 431 | cue_point_num, track->GetNumber(), track_type, |
Vignesh Venkatasubramanian | 867f189 | 2014-04-14 12:05:21 -0700 | [diff] [blame] | 432 | cue->GetTime(pSegment.get()), track_pos->m_block, |
| 433 | track_pos->m_pos); |
Tom Finegan | 5440f20 | 2014-01-23 15:19:32 -0800 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
| 437 | cue = cues->GetNext(cue); |
| 438 | ++cue_point_num; |
| 439 | } while (cue != NULL); |
| 440 | } |
| 441 | |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 442 | const mkvparser::Tags* const tags = pSegment->GetTags(); |
Francisco Facioni | b6de61a | 2015-07-14 14:18:09 -0300 | [diff] [blame] | 443 | if (tags && tags->GetTagCount() > 0) { |
| 444 | printf("\t\tTags\n"); |
| 445 | for (int i = 0; i < tags->GetTagCount(); ++i) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 446 | const mkvparser::Tags::Tag* const tag = tags->GetTag(i); |
Francisco Facioni | b6de61a | 2015-07-14 14:18:09 -0300 | [diff] [blame] | 447 | printf("\t\t\tTag\n"); |
| 448 | for (int j = 0; j < tag->GetSimpleTagCount(); j++) { |
Tom Finegan | cbe5c40 | 2016-03-21 12:16:30 -0700 | [diff] [blame] | 449 | const mkvparser::Tags::SimpleTag* const simple_tag = |
Francisco Facioni | b6de61a | 2015-07-14 14:18:09 -0300 | [diff] [blame] | 450 | tag->GetSimpleTag(j); |
| 451 | printf("\t\t\t\tSimple Tag \"%s\" Value \"%s\"\n", |
| 452 | simple_tag->GetTagName(), simple_tag->GetTagString()); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
Tom Finegan | 5c14a3f | 2014-01-23 10:57:06 -0800 | [diff] [blame] | 457 | fflush(stdout); |
Tom Finegan | 0ba80bc | 2016-03-29 09:02:52 -0700 | [diff] [blame] | 458 | return EXIT_SUCCESS; |
James Zern | 04d7809 | 2015-08-13 23:06:41 -0700 | [diff] [blame] | 459 | } |