| 1 | /***************************************************************** |
| 2 | | |
| 3 | | AP4 - MP4 File Info |
| 4 | | |
| 5 | | Copyright 2002-2015 Axiomatic Systems, LLC |
| 6 | | |
| 7 | | |
| 8 | | This file is part of Bento4/AP4 (MP4 Atom Processing Library). |
| 9 | | |
| 10 | | Unless you have obtained Bento4 under a difference license, |
| 11 | | this version of Bento4 is Bento4|GPL. |
| 12 | | Bento4|GPL is free software; you can redistribute it and/or modify |
| 13 | | it under the terms of the GNU General Public License as published by |
| 14 | | the Free Software Foundation; either version 2, or (at your option) |
| 15 | | any later version. |
| 16 | | |
| 17 | | Bento4|GPL is distributed in the hope that it will be useful, |
| 18 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | | GNU General Public License for more details. |
| 21 | | |
| 22 | | You should have received a copy of the GNU General Public License |
| 23 | | along with Bento4|GPL; see the file COPYING. If not, write to the |
| 24 | | Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
| 25 | | 02111-1307, USA. |
| 26 | | |
| 27 | ****************************************************************/ |
| 28 | |
| 29 | /*---------------------------------------------------------------------- |
| 30 | | includes |
| 31 | +---------------------------------------------------------------------*/ |
| 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | |
| 35 | #include "Ap4.h" |
| 36 | #include "Ap4BitStream.h" |
| 37 | #include "Ap4Mp4AudioInfo.h" |
| 38 | #include "Ap4HevcParser.h" |
| 39 | |
| 40 | /*---------------------------------------------------------------------- |
| 41 | | constants |
| 42 | +---------------------------------------------------------------------*/ |
| 43 | #define BANNER "MP4 File Info - Version 1.3.4\n"\ |
| 44 | "(Bento4 Version " AP4_VERSION_STRING ")\n"\ |
| 45 | "(c) 2002-2017 Axiomatic Systems, LLC" |
| 46 | |
| 47 | /*---------------------------------------------------------------------- |
| 48 | | globals |
| 49 | +---------------------------------------------------------------------*/ |
| 50 | typedef struct { |
| 51 | AP4_UI64 sample_count; |
| 52 | AP4_UI64 duration; |
| 53 | double bitrate; |
| 54 | } MediaInfo; |
| 55 | |
| 56 | typedef enum { |
| 57 | TEXT_FORMAT, |
| 58 | JSON_FORMAT |
| 59 | } OutputFormat; |
| 60 | |
| 61 | struct Options { |
| 62 | OutputFormat format; |
| 63 | } Options; |
| 64 | |
| 65 | /*---------------------------------------------------------------------- |
| 66 | | PrintUsageAndExit |
| 67 | +---------------------------------------------------------------------*/ |
| 68 | static void |
| 69 | PrintUsageAndExit() |
| 70 | { |
| 71 | fprintf(stderr, |
| 72 | BANNER |
| 73 | "\n\nusage: mp4info [options] <input>\n" |
| 74 | "Options:\n" |
| 75 | " --verbose: show extended information when available\n" |
| 76 | " --format <format>: display the information in this format.\n" |
| 77 | " <format> is: text (default) or json\n" |
| 78 | " --show-layout: show sample layout\n" |
| 79 | " --show-samples: show sample details\n" |
| 80 | " --show-sample-data: show sample data\n" |
| 81 | " --fast: skip some details that are slow to compute\n"); |
| 82 | exit(1); |
| 83 | } |
| 84 | |
| 85 | /*---------------------------------------------------------------------- |
| 86 | | ShowPayload |
| 87 | +---------------------------------------------------------------------*/ |
| 88 | static void |
| 89 | ShowPayload(AP4_Atom& atom, bool ascii = false) |
| 90 | { |
| 91 | AP4_UI64 payload_size = atom.GetSize()-8; |
| 92 | if (payload_size <= 1024) { |
| 93 | AP4_MemoryByteStream* payload = new AP4_MemoryByteStream(); |
| 94 | atom.Write(*payload); |
| 95 | if (ascii) { |
| 96 | // ascii |
| 97 | payload->WriteUI08(0); // terminate with a NULL character |
| 98 | printf("%s", (const char*)payload->GetData()+atom.GetHeaderSize()); |
| 99 | } else { |
| 100 | // hex |
| 101 | for (unsigned int i=0; i<payload_size; i++) { |
| 102 | printf("%02x", (unsigned char)payload->GetData()[atom.GetHeaderSize()+i]); |
| 103 | } |
| 104 | } |
| 105 | payload->Release(); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /*---------------------------------------------------------------------- |
| 110 | | ShowData |
| 111 | +---------------------------------------------------------------------*/ |
| 112 | static void |
| 113 | ShowData(const AP4_DataBuffer& data) |
| 114 | { |
| 115 | for (unsigned int i=0; i<data.GetDataSize(); i++) { |
| 116 | printf("%02x", (unsigned char)data.GetData()[i]); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /*---------------------------------------------------------------------- |
| 121 | | ShowProtectionSchemeInfo_Text |
| 122 | +---------------------------------------------------------------------*/ |
| 123 | static void |
| 124 | ShowProtectionSchemeInfo_Text(AP4_UI32 scheme_type, AP4_ContainerAtom& schi, bool verbose) |
| 125 | { |
| 126 | if (scheme_type == AP4_PROTECTION_SCHEME_TYPE_IAEC) { |
| 127 | printf(" iAEC Scheme Info:\n"); |
| 128 | AP4_IkmsAtom* ikms = AP4_DYNAMIC_CAST(AP4_IkmsAtom, schi.FindChild("iKMS")); |
| 129 | if (ikms) { |
| 130 | printf(" KMS URI: %s\n", ikms->GetKmsUri().GetChars()); |
| 131 | } |
| 132 | AP4_IsfmAtom* isfm = AP4_DYNAMIC_CAST(AP4_IsfmAtom, schi.FindChild("iSFM")); |
| 133 | if (isfm) { |
| 134 | printf(" Selective Encryption: %s\n", isfm->GetSelectiveEncryption()?"yes":"no"); |
| 135 | printf(" Key Indicator Length: %d\n", isfm->GetKeyIndicatorLength()); |
| 136 | printf(" IV Length: %d\n", isfm->GetIvLength()); |
| 137 | } |
| 138 | AP4_IsltAtom* islt = AP4_DYNAMIC_CAST(AP4_IsltAtom, schi.FindChild("iSLT")); |
| 139 | if (islt) { |
| 140 | printf(" Salt: "); |
| 141 | for (unsigned int i=0; i<8; i++) { |
| 142 | printf("%02x",islt->GetSalt()[i]); |
| 143 | } |
| 144 | printf("\n"); |
| 145 | } |
| 146 | } else if (scheme_type == AP4_PROTECTION_SCHEME_TYPE_OMA) { |
| 147 | printf(" odkm Scheme Info:\n"); |
| 148 | AP4_OdafAtom* odaf = AP4_DYNAMIC_CAST(AP4_OdafAtom, schi.FindChild("odkm/odaf")); |
| 149 | if (odaf) { |
| 150 | printf(" Selective Encryption: %s\n", odaf->GetSelectiveEncryption()?"yes":"no"); |
| 151 | printf(" Key Indicator Length: %d\n", odaf->GetKeyIndicatorLength()); |
| 152 | printf(" IV Length: %d\n", odaf->GetIvLength()); |
| 153 | } |
| 154 | AP4_OhdrAtom* ohdr = AP4_DYNAMIC_CAST(AP4_OhdrAtom, schi.FindChild("odkm/ohdr")); |
| 155 | if (ohdr) { |
| 156 | const char* encryption_method = ""; |
| 157 | switch (ohdr->GetEncryptionMethod()) { |
| 158 | case AP4_OMA_DCF_ENCRYPTION_METHOD_NULL: encryption_method = "NULL"; break; |
| 159 | case AP4_OMA_DCF_ENCRYPTION_METHOD_AES_CTR: encryption_method = "AES-CTR"; break; |
| 160 | case AP4_OMA_DCF_ENCRYPTION_METHOD_AES_CBC: encryption_method = "AES-CBC"; break; |
| 161 | default: encryption_method = "UNKNOWN"; break; |
| 162 | } |
| 163 | printf(" Encryption Method: %s\n", encryption_method); |
| 164 | printf(" Content ID: %s\n", ohdr->GetContentId().GetChars()); |
| 165 | printf(" Rights Issuer URL: %s\n", ohdr->GetRightsIssuerUrl().GetChars()); |
| 166 | |
| 167 | const AP4_DataBuffer& headers = ohdr->GetTextualHeaders(); |
| 168 | AP4_Size data_len = headers.GetDataSize(); |
| 169 | if (data_len) { |
| 170 | AP4_Byte* textual_headers_string; |
| 171 | AP4_Byte* curr; |
| 172 | AP4_DataBuffer output_buffer; |
| 173 | output_buffer.SetDataSize(data_len+1); |
| 174 | AP4_CopyMemory(output_buffer.UseData(), headers.GetData(), data_len); |
| 175 | curr = textual_headers_string = output_buffer.UseData(); |
| 176 | textual_headers_string[data_len] = '\0'; |
| 177 | while(curr < textual_headers_string+data_len) { |
| 178 | if ('\0' == *curr) { |
| 179 | *curr = '\n'; |
| 180 | } |
| 181 | curr++; |
| 182 | } |
| 183 | printf(" Textual Headers: \n%s\n", (const char*)textual_headers_string); |
| 184 | } |
| 185 | } |
| 186 | } else if (scheme_type == AP4_PROTECTION_SCHEME_TYPE_ITUNES) { |
| 187 | printf(" itun Scheme Info:\n"); |
| 188 | AP4_Atom* name = schi.FindChild("name"); |
| 189 | if (name) { |
| 190 | printf(" Name: "); |
| 191 | ShowPayload(*name, true); |
| 192 | printf("\n"); |
| 193 | } |
| 194 | AP4_Atom* user = schi.FindChild("user"); |
| 195 | if (user) { |
| 196 | printf(" User ID: "); |
| 197 | ShowPayload(*user); |
| 198 | printf("\n"); |
| 199 | } |
| 200 | AP4_Atom* key = schi.FindChild("key "); |
| 201 | if (key) { |
| 202 | printf(" Key ID: "); |
| 203 | ShowPayload(*key); |
| 204 | printf("\n"); |
| 205 | } |
| 206 | AP4_Atom* iviv = schi.FindChild("iviv"); |
| 207 | if (iviv) { |
| 208 | printf(" IV: "); |
| 209 | ShowPayload(*iviv); |
| 210 | printf("\n"); |
| 211 | } |
| 212 | } else if (scheme_type == AP4_PROTECTION_SCHEME_TYPE_MARLIN_ACBC || |
| 213 | scheme_type == AP4_PROTECTION_SCHEME_TYPE_MARLIN_ACGK) { |
| 214 | printf(" Marlin IPMP ACBC/ACGK Scheme Info:\n"); |
| 215 | AP4_NullTerminatedStringAtom* octopus_id = AP4_DYNAMIC_CAST(AP4_NullTerminatedStringAtom, schi.FindChild("8id ")); |
| 216 | if (octopus_id) { |
| 217 | printf(" Content ID: %s\n", octopus_id->GetValue().GetChars()); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if (verbose) { |
| 222 | printf(" Protection System Details:\n"); |
| 223 | AP4_ByteStream* output = NULL; |
| 224 | AP4_FileByteStream::Create("-stdout", AP4_FileByteStream::STREAM_MODE_WRITE, output); |
| 225 | AP4_PrintInspector inspector(*output, 4); |
| 226 | schi.Inspect(inspector); |
| 227 | output->Release(); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | /*---------------------------------------------------------------------- |
| 232 | | ShowProtectionSchemeInfo_Json |
| 233 | +---------------------------------------------------------------------*/ |
| 234 | static void |
| 235 | ShowProtectionSchemeInfo_Json(AP4_UI32 /* scheme_type */, AP4_ContainerAtom& /* schi */, bool /* verbose */) |
| 236 | { |
| 237 | // not implemented yet |
| 238 | } |
| 239 | |
| 240 | /*---------------------------------------------------------------------- |
| 241 | | ShowProtectedSampleDescription_Text |
| 242 | +---------------------------------------------------------------------*/ |
| 243 | static void |
| 244 | ShowProtectedSampleDescription_Text(AP4_ProtectedSampleDescription& desc, bool verbose) |
| 245 | { |
| 246 | printf(" [ENCRYPTED]\n"); |
| 247 | char coding[5]; |
| 248 | AP4_FormatFourChars(coding, desc.GetFormat()); |
| 249 | printf(" Coding: %s\n", coding); |
| 250 | AP4_UI32 st = desc.GetSchemeType(); |
| 251 | printf(" Scheme Type: %c%c%c%c\n", |
| 252 | (char)((st>>24) & 0xFF), |
| 253 | (char)((st>>16) & 0xFF), |
| 254 | (char)((st>> 8) & 0xFF), |
| 255 | (char)((st ) & 0xFF)); |
| 256 | printf(" Scheme Version: %d\n", desc.GetSchemeVersion()); |
| 257 | printf(" Scheme URI: %s\n", desc.GetSchemeUri().GetChars()); |
| 258 | AP4_ProtectionSchemeInfo* scheme_info = desc.GetSchemeInfo(); |
| 259 | if (scheme_info == NULL) return; |
| 260 | AP4_ContainerAtom* schi = scheme_info->GetSchiAtom(); |
| 261 | if (schi == NULL) return; |
| 262 | ShowProtectionSchemeInfo_Text(desc.GetSchemeType(), *schi, verbose); |
| 263 | } |
| 264 | |
| 265 | /*---------------------------------------------------------------------- |
| 266 | | ShowProtectedSampleDescription_Json |
| 267 | +---------------------------------------------------------------------*/ |
| 268 | static void |
| 269 | ShowProtectedSampleDescription_Json(AP4_ProtectedSampleDescription& desc, bool verbose) |
| 270 | { |
| 271 | printf("\"protection\":{\n"); |
| 272 | char coding[5]; |
| 273 | AP4_FormatFourChars(coding, desc.GetFormat()); |
| 274 | printf("\"coding\":\"%s\",\n", coding); |
| 275 | AP4_UI32 st = desc.GetSchemeType(); |
| 276 | printf("\"scheme_type\":\"%c%c%c%c\",\n", |
| 277 | (char)((st>>24) & 0xFF), |
| 278 | (char)((st>>16) & 0xFF), |
| 279 | (char)((st>> 8) & 0xFF), |
| 280 | (char)((st ) & 0xFF)); |
| 281 | printf("\"scheme_version\":%d,\n", desc.GetSchemeVersion()); |
| 282 | printf("\"scheme_uri\":\"%s\"", desc.GetSchemeUri().GetChars()); |
| 283 | AP4_ProtectionSchemeInfo* scheme_info = desc.GetSchemeInfo(); |
| 284 | if (scheme_info) { |
| 285 | AP4_ContainerAtom* schi = scheme_info->GetSchiAtom(); |
| 286 | if (schi) { |
| 287 | ShowProtectionSchemeInfo_Json(desc.GetSchemeType(), *schi, verbose); |
| 288 | } |
| 289 | } |
| 290 | printf("}"); |
| 291 | } |
| 292 | |
| 293 | /*---------------------------------------------------------------------- |
| 294 | | ShowMpegAudioSampleDescription |
| 295 | +---------------------------------------------------------------------*/ |
| 296 | static void |
| 297 | ShowMpegAudioSampleDescription(AP4_MpegAudioSampleDescription& mpeg_audio_desc) |
| 298 | { |
| 299 | AP4_MpegAudioSampleDescription::Mpeg4AudioObjectType object_type = |
| 300 | mpeg_audio_desc.GetMpeg4AudioObjectType(); |
| 301 | const char* object_type_string = AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectTypeString(object_type); |
| 302 | |
| 303 | switch (Options.format) { |
| 304 | case TEXT_FORMAT: |
| 305 | printf(" MPEG-4 Audio Object Type: %d (%s)\n", object_type, object_type_string); |
| 306 | break; |
| 307 | |
| 308 | case JSON_FORMAT: |
| 309 | printf("\"mpeg_4_audio_object_type\":%d,\n", object_type); |
| 310 | printf("\"mpeg_4_audio_object_type_name\":\"%s\"", object_type_string); |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | // Decoder Specific Info |
| 315 | const AP4_DataBuffer& dsi = mpeg_audio_desc.GetDecoderInfo(); |
| 316 | if (dsi.GetDataSize()) { |
| 317 | AP4_Mp4AudioDecoderConfig dec_config; |
| 318 | AP4_Result result = dec_config.Parse(dsi.GetData(), dsi.GetDataSize()); |
| 319 | if (AP4_SUCCEEDED(result)) { |
| 320 | switch (Options.format) { |
| 321 | case TEXT_FORMAT: |
| 322 | printf(" MPEG-4 Audio Decoder Config:\n"); |
| 323 | printf(" Sampling Frequency: %d\n", dec_config.m_SamplingFrequency); |
| 324 | printf(" Channels: %d\n", dec_config.m_ChannelCount); |
| 325 | if (dec_config.m_Extension.m_ObjectType) { |
| 326 | object_type_string = AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectTypeString( |
| 327 | dec_config.m_Extension.m_ObjectType); |
| 328 | |
| 329 | printf(" Extension:\n"); |
| 330 | printf(" Object Type: %s\n", object_type_string); |
| 331 | printf(" SBR Present: %s\n", dec_config.m_Extension.m_SbrPresent?"yes":"no"); |
| 332 | printf(" PS Present: %s\n", dec_config.m_Extension.m_PsPresent?"yes":"no"); |
| 333 | printf(" Sampling Frequency: %d\n", dec_config.m_Extension.m_SamplingFrequency); |
| 334 | } |
| 335 | break; |
| 336 | |
| 337 | case JSON_FORMAT: |
| 338 | printf(",\n"); |
| 339 | printf("\"mpeg_4_audio_decoder_config\":{\n"); |
| 340 | printf(" \"sampling_frequency\":%d,\n", dec_config.m_SamplingFrequency); |
| 341 | printf(" \"channels\":%d\n", dec_config.m_ChannelCount); |
| 342 | if (dec_config.m_Extension.m_ObjectType) { |
| 343 | object_type_string = AP4_MpegAudioSampleDescription::GetMpeg4AudioObjectTypeString( |
| 344 | dec_config.m_Extension.m_ObjectType); |
| 345 | |
| 346 | printf(",\n"); |
| 347 | printf(" \"extension\":{\n"); |
| 348 | printf(" \"object_type\":%d,\n", dec_config.m_Extension.m_ObjectType); |
| 349 | printf(" \"object_type_name\":\"%s\",\n", object_type_string); |
| 350 | printf(" \"sbr_present\":%s,\n", dec_config.m_Extension.m_SbrPresent?"true":"false"); |
| 351 | printf(" \"ps_present\":%s,\n", dec_config.m_Extension.m_PsPresent?"true":"false"); |
| 352 | printf(" \"sampling_frequency\":%d\n", dec_config.m_Extension.m_SamplingFrequency); |
| 353 | printf(" }\n"); |
| 354 | } |
| 355 | printf("}"); |
| 356 | break; |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /*---------------------------------------------------------------------- |
| 363 | | ShowSampleDescription_Text |
| 364 | +---------------------------------------------------------------------*/ |
| 365 | static void |
| 366 | ShowSampleDescription_Text(AP4_SampleDescription& description, bool verbose) |
| 367 | { |
| 368 | AP4_SampleDescription* desc = &description; |
| 369 | if (desc->GetType() == AP4_SampleDescription::TYPE_PROTECTED) { |
| 370 | AP4_ProtectedSampleDescription* prot_desc = AP4_DYNAMIC_CAST(AP4_ProtectedSampleDescription, desc); |
| 371 | if (prot_desc) { |
| 372 | ShowProtectedSampleDescription_Text(*prot_desc, verbose); |
| 373 | desc = prot_desc->GetOriginalSampleDescription(); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | if (verbose) { |
| 378 | printf(" Bytes: "); |
| 379 | AP4_Atom* details = desc->ToAtom(); |
| 380 | ShowPayload(*details, false); |
| 381 | printf("\n"); |
| 382 | delete details; |
| 383 | } |
| 384 | |
| 385 | char coding[5]; |
| 386 | AP4_FormatFourChars(coding, desc->GetFormat()); |
| 387 | printf( " Coding: %s", coding); |
| 388 | const char* format_name = AP4_GetFormatName(desc->GetFormat()); |
| 389 | if (format_name) { |
| 390 | printf(" (%s)\n", format_name); |
| 391 | } else { |
| 392 | printf("\n"); |
| 393 | } |
| 394 | AP4_String codec; |
| 395 | desc->GetCodecString(codec); |
| 396 | printf( " Codec String: %s\n", codec.GetChars()); |
| 397 | |
| 398 | switch (desc->GetType()) { |
| 399 | case AP4_SampleDescription::TYPE_MPEG: { |
| 400 | // MPEG sample description |
| 401 | AP4_MpegSampleDescription* mpeg_desc = AP4_DYNAMIC_CAST(AP4_MpegSampleDescription, desc); |
| 402 | |
| 403 | printf(" Stream Type: %s\n", mpeg_desc->GetStreamTypeString(mpeg_desc->GetStreamType())); |
| 404 | printf(" Object Type: %s\n", mpeg_desc->GetObjectTypeString(mpeg_desc->GetObjectTypeId())); |
| 405 | printf(" Max Bitrate: %d\n", mpeg_desc->GetMaxBitrate()); |
| 406 | printf(" Avg Bitrate: %d\n", mpeg_desc->GetAvgBitrate()); |
| 407 | printf(" Buffer Size: %d\n", mpeg_desc->GetBufferSize()); |
| 408 | |
| 409 | if (mpeg_desc->GetObjectTypeId() == AP4_OTI_MPEG4_AUDIO || |
| 410 | mpeg_desc->GetObjectTypeId() == AP4_OTI_MPEG2_AAC_AUDIO_LC || |
| 411 | mpeg_desc->GetObjectTypeId() == AP4_OTI_MPEG2_AAC_AUDIO_MAIN) { |
| 412 | AP4_MpegAudioSampleDescription* mpeg_audio_desc = AP4_DYNAMIC_CAST(AP4_MpegAudioSampleDescription, mpeg_desc); |
| 413 | if (mpeg_audio_desc) ShowMpegAudioSampleDescription(*mpeg_audio_desc); |
| 414 | } |
| 415 | break; |
| 416 | } |
| 417 | |
| 418 | case AP4_SampleDescription::TYPE_AVC: { |
| 419 | // AVC specifics |
| 420 | AP4_AvcSampleDescription* avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, desc); |
| 421 | const char* profile_name = AP4_AvccAtom::GetProfileName(avc_desc->GetProfile()); |
| 422 | printf(" AVC Profile: %d", avc_desc->GetProfile()); |
| 423 | if (profile_name) { |
| 424 | printf(" (%s)\n", profile_name); |
| 425 | } else { |
| 426 | printf("\n"); |
| 427 | } |
| 428 | printf(" AVC Profile Compat: %x\n", avc_desc->GetProfileCompatibility()); |
| 429 | printf(" AVC Level: %d\n", avc_desc->GetLevel()); |
| 430 | printf(" AVC NALU Length Size: %d\n", avc_desc->GetNaluLengthSize()); |
| 431 | printf(" AVC SPS: ["); |
| 432 | const char* sep = ""; |
| 433 | for (unsigned int i=0; i<avc_desc->GetSequenceParameters().ItemCount(); i++) { |
| 434 | printf("%s", sep); |
| 435 | ShowData(avc_desc->GetSequenceParameters()[i]); |
| 436 | sep = ", "; |
| 437 | } |
| 438 | printf("]\n"); |
| 439 | printf(" AVC PPS: ["); |
| 440 | sep = ""; |
| 441 | for (unsigned int i=0; i<avc_desc->GetPictureParameters().ItemCount(); i++) { |
| 442 | printf("%s", sep); |
| 443 | ShowData(avc_desc->GetPictureParameters()[i]); |
| 444 | sep = ", "; |
| 445 | } |
| 446 | printf("]\n"); |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | case AP4_SampleDescription::TYPE_HEVC: { |
| 451 | // HEVC specifics |
| 452 | AP4_HevcSampleDescription* hevc_desc = AP4_DYNAMIC_CAST(AP4_HevcSampleDescription, desc); |
| 453 | const char* profile_name = AP4_HvccAtom::GetProfileName(hevc_desc->GetGeneralProfileSpace(), hevc_desc->GetGeneralProfile()); |
| 454 | printf(" HEVC Profile Space: %d\n", hevc_desc->GetGeneralProfileSpace()); |
| 455 | printf(" HEVC Profile: %d", hevc_desc->GetGeneralProfile()); |
| 456 | if (profile_name) printf(" (%s)", profile_name); |
| 457 | printf("\n"); |
| 458 | printf(" HEVC Profile Compat: %x\n", hevc_desc->GetGeneralProfileCompatibilityFlags()); |
| 459 | printf(" HEVC Level: %d.%d\n", hevc_desc->GetGeneralLevel()/30, (hevc_desc->GetGeneralLevel()%30)/3); |
| 460 | printf(" HEVC Tier: %d\n", hevc_desc->GetGeneralTierFlag()); |
| 461 | printf(" HEVC Chroma Format: %d", hevc_desc->GetChromaFormat()); |
| 462 | const char* chroma_format_name = AP4_HvccAtom::GetChromaFormatName(hevc_desc->GetChromaFormat()); |
| 463 | if (chroma_format_name) printf(" (%s)", chroma_format_name); |
| 464 | printf("\n"); |
| 465 | printf(" HEVC Chroma Bit Depth: %d\n", hevc_desc->GetChromaBitDepth()); |
| 466 | printf(" HEVC Luma Bit Depth: %d\n", hevc_desc->GetLumaBitDepth()); |
| 467 | printf(" HEVC Average Frame Rate: %d\n", hevc_desc->GetAverageFrameRate()); |
| 468 | printf(" HEVC Constant Frame Rate: %d\n", hevc_desc->GetConstantFrameRate()); |
| 469 | printf(" HEVC NALU Length Size: %d\n", hevc_desc->GetNaluLengthSize()); |
| 470 | printf(" HEVC Sequences:\n"); |
| 471 | for (unsigned int i=0; i<hevc_desc->GetSequences().ItemCount(); i++) { |
| 472 | const AP4_HvccAtom::Sequence& seq = hevc_desc->GetSequences()[i]; |
| 473 | printf(" {\n"); |
| 474 | printf(" Array Completeness=%d\n", seq.m_ArrayCompleteness); |
| 475 | printf(" Type=%d", seq.m_NaluType); |
| 476 | const char* nalu_type_name = AP4_HevcNalParser::NaluTypeName(seq.m_NaluType); |
| 477 | if (nalu_type_name) { |
| 478 | printf(" (%s)", nalu_type_name); |
| 479 | } |
| 480 | printf("\n"); |
| 481 | const char* sep = ""; |
| 482 | for (unsigned int j=0; j<seq.m_Nalus.ItemCount(); j++) { |
| 483 | printf("%s ", sep); |
| 484 | ShowData(seq.m_Nalus[j]); |
| 485 | sep = "\n"; |
| 486 | } |
| 487 | printf("\n }\n"); |
| 488 | } |
| 489 | break; |
| 490 | } |
| 491 | |
| 492 | case AP4_SampleDescription::TYPE_AV1: { |
| 493 | // AV1 specifics |
| 494 | AP4_Av1SampleDescription* av1_desc = AP4_DYNAMIC_CAST(AP4_Av1SampleDescription, desc); |
| 495 | const char* profile_name = AP4_Av1cAtom::GetProfileName(av1_desc->GetSeqProfile()); |
| 496 | printf(" AV1 Profile: %d", av1_desc->GetSeqProfile()); |
| 497 | if (profile_name) { |
| 498 | printf(" (%s)\n", profile_name); |
| 499 | } else { |
| 500 | printf("\n"); |
| 501 | } |
| 502 | printf(" AV1 Level: %d.%d\n", |
| 503 | 2 + (av1_desc->GetSeqLevelIdx0() / 4), |
| 504 | av1_desc->GetSeqLevelIdx0() % 4); |
| 505 | printf(" AV1 Tier: %d\n", av1_desc->GetSeqTier0()); |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | case AP4_SampleDescription::TYPE_SUBTITLES: { |
| 510 | // Subtitles |
| 511 | AP4_SubtitleSampleDescription* subt_desc = AP4_DYNAMIC_CAST(AP4_SubtitleSampleDescription, desc); |
| 512 | printf(" Subtitles:\n"); |
| 513 | printf(" Namespace: %s\n", subt_desc->GetNamespace().GetChars()); |
| 514 | printf(" Schema Location: %s\n", subt_desc->GetSchemaLocation().GetChars()); |
| 515 | printf(" Image Mime Type: %s\n", subt_desc->GetImageMimeType().GetChars()); |
| 516 | break; |
| 517 | } |
| 518 | |
| 519 | default: |
| 520 | break; |
| 521 | } |
| 522 | |
| 523 | AP4_AudioSampleDescription* audio_desc = |
| 524 | AP4_DYNAMIC_CAST(AP4_AudioSampleDescription, desc); |
| 525 | if (audio_desc) { |
| 526 | // Audio sample description |
| 527 | printf(" Sample Rate: %d\n", audio_desc->GetSampleRate()); |
| 528 | printf(" Sample Size: %d\n", audio_desc->GetSampleSize()); |
| 529 | printf(" Channels: %d\n", audio_desc->GetChannelCount()); |
| 530 | } |
| 531 | AP4_VideoSampleDescription* video_desc = |
| 532 | AP4_DYNAMIC_CAST(AP4_VideoSampleDescription, desc); |
| 533 | if (video_desc) { |
| 534 | // Video sample description |
| 535 | printf(" Width: %d\n", video_desc->GetWidth()); |
| 536 | printf(" Height: %d\n", video_desc->GetHeight()); |
| 537 | printf(" Depth: %d\n", video_desc->GetDepth()); |
| 538 | } |
| 539 | |
| 540 | switch (desc->GetFormat()) { |
| 541 | case AP4_SAMPLE_FORMAT_AC_3: { |
| 542 | // Dolby Digital specifics |
| 543 | AP4_Dac3Atom* dac3 = AP4_DYNAMIC_CAST(AP4_Dac3Atom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DAC3)); |
| 544 | if (dac3) { |
| 545 | printf(" AC-3 Data Rate: %d\n", dac3->GetDataRate()); |
| 546 | printf(" AC-3 Stream:\n"); |
| 547 | printf(" fscod = %d\n", dac3->GetStreamInfo().fscod); |
| 548 | printf(" bsid = %d\n", dac3->GetStreamInfo().bsid); |
| 549 | printf(" bsmod = %d\n", dac3->GetStreamInfo().bsmod); |
| 550 | printf(" acmod = %d\n", dac3->GetStreamInfo().acmod); |
| 551 | printf(" lfeon = %d\n", dac3->GetStreamInfo().lfeon); |
| 552 | printf(" AC-3 dac3 payload: ["); |
| 553 | ShowData(dac3->GetRawBytes()); |
| 554 | printf("]\n"); |
| 555 | } |
| 556 | break; |
| 557 | } |
| 558 | |
| 559 | case AP4_SAMPLE_FORMAT_EC_3: { |
| 560 | // Dolby Digital Plus specifics |
| 561 | AP4_Dec3Atom* dec3 = AP4_DYNAMIC_CAST(AP4_Dec3Atom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DEC3)); |
| 562 | if (dec3) { |
| 563 | printf(" E-AC-3 Data Rate: %d\n", dec3->GetDataRate()); |
| 564 | for (unsigned int i=0; i<dec3->GetSubStreams().ItemCount(); i++) { |
| 565 | printf(" E-AC-3 Substream %d:\n", i); |
| 566 | printf(" fscod = %d\n", dec3->GetSubStreams()[i].fscod); |
| 567 | printf(" bsid = %d\n", dec3->GetSubStreams()[i].bsid); |
| 568 | printf(" bsmod = %d\n", dec3->GetSubStreams()[i].bsmod); |
| 569 | printf(" acmod = %d\n", dec3->GetSubStreams()[i].acmod); |
| 570 | printf(" lfeon = %d\n", dec3->GetSubStreams()[i].lfeon); |
| 571 | printf(" num_dep_sub = %d\n", dec3->GetSubStreams()[i].num_dep_sub); |
| 572 | printf(" chan_loc = %d\n", dec3->GetSubStreams()[i].chan_loc); |
| 573 | } |
| 574 | if (dec3->GetFlagEC3ExtensionTypeA()){ |
| 575 | printf(" Dolby Digital Plus with Dolby Atmos: Yes\n"); |
| 576 | printf(" Dolby Atmos Complexity Index: %d\n", dec3->GetComplexityIndexTypeA()); |
| 577 | } else { |
| 578 | printf(" Dolby Digital Plus with Dolby Atmos: No\n"); |
| 579 | } |
| 580 | printf(" E-AC-3 dec3 payload: ["); |
| 581 | ShowData(dec3->GetRawBytes()); |
| 582 | printf("]\n"); |
| 583 | } |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | case AP4_SAMPLE_FORMAT_AC_4: { |
| 588 | // Dolby AC-4 specifics |
| 589 | AP4_Dac4Atom* dac4 = AP4_DYNAMIC_CAST(AP4_Dac4Atom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DAC4)); |
| 590 | if (dac4) { |
| 591 | printf(" Codecs String: "); |
| 592 | AP4_String codec; |
| 593 | dac4->GetCodecString(codec); |
| 594 | printf("%s", codec.GetChars()); |
| 595 | printf("\n"); |
| 596 | |
| 597 | const AP4_Dac4Atom::Ac4Dsi& dsi = dac4->GetDsi(); |
| 598 | printf(" AC-4 dsi version: %d\n", dsi.ac4_dsi_version); |
| 599 | unsigned short self_contained = 0; |
| 600 | if (dsi.ac4_dsi_version == 1) { |
| 601 | printf(" AC-4 bitstream version: %d\n", dsi.d.v1.bitstream_version); |
| 602 | for (unsigned int i = 0; i < dsi.d.v1.n_presentations; i++) { |
| 603 | AP4_Dac4Atom::Ac4Dsi::PresentationV1& presentation = dsi.d.v1.presentations[i]; |
| 604 | if (presentation.presentation_version == 1 || presentation.presentation_version == 2) { |
| 605 | printf(" AC-4 Presentation %d:\n", i); |
| 606 | |
| 607 | char presentation_type [64]; |
| 608 | char presentation_codec[64]; |
| 609 | char presentation_lang [64 + 1] = "un"; |
| 610 | AP4_FormatString(presentation_codec, |
| 611 | sizeof(presentation_codec), |
| 612 | "ac-4.%02x.%02x.%02x", |
| 613 | dsi.d.v1.bitstream_version, |
| 614 | presentation.presentation_version, |
| 615 | presentation.d.v1.mdcompat); |
| 616 | for (int sg = 0; sg < presentation.d.v1.n_substream_groups; sg++){ |
| 617 | if ( presentation.d.v1.substream_groups[sg].d.v1.b_content_type && |
| 618 | (presentation.d.v1.substream_groups[sg].d.v1.content_classifier == 0 ||presentation.d.v1.substream_groups[sg].d.v1.content_classifier == 4) && |
| 619 | presentation.d.v1.substream_groups[sg].d.v1.b_language_indicator){ |
| 620 | memcpy(presentation_lang, presentation.d.v1.substream_groups[sg].d.v1.language_tag_bytes, presentation.d.v1.substream_groups[sg].d.v1.n_language_tag_bytes); |
| 621 | presentation_lang[presentation.d.v1.substream_groups[sg].d.v1.n_language_tag_bytes] = '\0'; |
| 622 | } |
| 623 | } |
| 624 | if (presentation.d.v1.b_multi_pid == 0) { self_contained ++; } |
| 625 | if (presentation.d.v1.b_presentation_channel_coded == 1) { |
| 626 | AP4_FormatString(presentation_type, sizeof(presentation_type), "Channel based"); |
| 627 | if (presentation.d.v1.dsi_presentation_ch_mode >= 11 && presentation.d.v1.dsi_presentation_ch_mode <= 15) { |
| 628 | AP4_FormatString(presentation_type, sizeof(presentation_type), "Channel based immsersive"); |
| 629 | } |
| 630 | } else { |
| 631 | AP4_FormatString(presentation_type, sizeof(presentation_type), "Object based"); |
| 632 | } |
| 633 | if (presentation.presentation_version == 2) { |
| 634 | printf(" Stream Type = Immersive stereo\n"); |
| 635 | }else { |
| 636 | printf(" Stream Type = %s\n", presentation_type); |
| 637 | } |
| 638 | printf(" presentation_id = %d\n", presentation.d.v1.b_presentation_id? presentation.d.v1.presentation_id : -1); |
| 639 | printf(" Codec String = %s\n", presentation_codec); |
| 640 | printf(" presentation_channel_mask_v1 = 0x%x\n", presentation.d.v1.presentation_channel_mask_v1); |
| 641 | printf(" Dolby Atmos source = %s\n", presentation.d.v1.dolby_atmos_indicator? "Yes": "No"); |
| 642 | printf(" Language = %s\n", presentation_lang); |
| 643 | printf(" Self Contained = %s\n", presentation.d.v1.b_multi_pid? "No": "Yes"); |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | printf(" Self Contained: %s\n", (self_contained == dsi.d.v1.n_presentations) ? "Yes": ((self_contained == 0)? "No": "Part")); |
| 649 | printf(" AC-4 dac4 payload: ["); |
| 650 | ShowData(dac4->GetRawBytes()); |
| 651 | printf("]\n"); |
| 652 | } |
| 653 | break; |
| 654 | } |
| 655 | |
| 656 | // VPx Specifics |
| 657 | case AP4_SAMPLE_FORMAT_VP8: |
| 658 | case AP4_SAMPLE_FORMAT_VP9: |
| 659 | case AP4_SAMPLE_FORMAT_VP10: { |
| 660 | AP4_VpccAtom* vpcc = AP4_DYNAMIC_CAST(AP4_VpccAtom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_VPCC)); |
| 661 | if (vpcc) { |
| 662 | printf(" Profile: %d\n", vpcc->GetProfile()); |
| 663 | printf(" Level: %d\n", vpcc->GetLevel()); |
| 664 | printf(" Bit Depth: %d\n", vpcc->GetBitDepth()); |
| 665 | printf(" Chroma Subsampling: %d\n", vpcc->GetChromaSubsampling()); |
| 666 | printf(" Colour Primaries: %d\n", vpcc->GetColourPrimaries()); |
| 667 | printf(" Transfer Characteristics: %d\n", vpcc->GetTransferCharacteristics()); |
| 668 | printf(" Matrix Coefficients: %d\n", vpcc->GetMatrixCoefficients()); |
| 669 | printf(" Video Full Range Flag: %s\n", vpcc->GetVideoFullRangeFlag() ? "true" : "false"); |
| 670 | } |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | // Dolby Vision specifics |
| 676 | AP4_DvccAtom* dvcc = AP4_DYNAMIC_CAST(AP4_DvccAtom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DVCC)); |
| 677 | if (dvcc) { |
| 678 | /* Dolby Vision */ |
| 679 | printf(" Dolby Vision:\n"); |
| 680 | printf(" Version: %d.%d\n", dvcc->GetDvVersionMajor(), dvcc->GetDvVersionMinor()); |
| 681 | const char* profile_name = AP4_DvccAtom::GetProfileName(dvcc->GetDvProfile()); |
| 682 | if (profile_name) { |
| 683 | printf(" Profile: %s\n", profile_name); |
| 684 | } else { |
| 685 | printf(" Profile: %d\n", dvcc->GetDvProfile()); |
| 686 | } |
| 687 | printf(" Level: %d\n", dvcc->GetDvLevel()); |
| 688 | printf(" RPU Present: %s\n", dvcc->GetRpuPresentFlag()?"true":"false"); |
| 689 | printf(" EL Present: %s\n", dvcc->GetElPresentFlag()?"true":"false"); |
| 690 | printf(" BL Present: %s\n", dvcc->GetBlPresentFlag()?"true":"false"); |
| 691 | printf(" BL Signal Compatibility ID: %d\n", dvcc->GetDvBlSignalCompatibilityID()); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | /*---------------------------------------------------------------------- |
| 696 | | ShowSampleDescription_Json |
| 697 | +---------------------------------------------------------------------*/ |
| 698 | static void |
| 699 | ShowSampleDescription_Json(AP4_SampleDescription& description, bool verbose) |
| 700 | { |
| 701 | printf("{\n"); |
| 702 | AP4_SampleDescription* desc = &description; |
| 703 | if (desc->GetType() == AP4_SampleDescription::TYPE_PROTECTED) { |
| 704 | AP4_ProtectedSampleDescription* prot_desc = AP4_DYNAMIC_CAST(AP4_ProtectedSampleDescription, desc); |
| 705 | if (prot_desc) { |
| 706 | ShowProtectedSampleDescription_Json(*prot_desc, verbose); |
| 707 | printf(",\n"); |
| 708 | desc = prot_desc->GetOriginalSampleDescription(); |
| 709 | } |
| 710 | } |
| 711 | char coding[5]; |
| 712 | AP4_FormatFourChars(coding, desc->GetFormat()); |
| 713 | const char* format_name = AP4_GetFormatName(desc->GetFormat()); |
| 714 | printf("\"coding\":\"%s\",\n", coding); |
| 715 | printf("\"coding_name\":\"%s\",\n", format_name ? format_name : ""); |
| 716 | AP4_String codec; |
| 717 | desc->GetCodecString(codec); |
| 718 | printf("\"codecs_string\":\"%s\"", codec.GetChars()); |
| 719 | |
| 720 | switch (desc->GetType()) { |
| 721 | case AP4_SampleDescription::TYPE_MPEG: { |
| 722 | // MPEG sample description |
| 723 | AP4_MpegSampleDescription* mpeg_desc = AP4_DYNAMIC_CAST(AP4_MpegSampleDescription, desc); |
| 724 | |
| 725 | printf(",\n"); |
| 726 | printf("\"stream_type\":%d,\n", mpeg_desc->GetStreamType()); |
| 727 | printf("\"stream_type_name\":\"%s\",\n", mpeg_desc->GetStreamTypeString(mpeg_desc->GetStreamType())); |
| 728 | printf("\"object_type\":%d,\n", mpeg_desc->GetObjectTypeId()); |
| 729 | printf("\"object_type_name\":\"%s\",\n", mpeg_desc->GetObjectTypeString(mpeg_desc->GetObjectTypeId())); |
| 730 | printf("\"max_bitrate\":%d,\n", mpeg_desc->GetMaxBitrate()); |
| 731 | printf("\"average_bitrate\":%d,\n", mpeg_desc->GetAvgBitrate()); |
| 732 | printf("\"buffer_size\":%d,\n", mpeg_desc->GetBufferSize()); |
| 733 | printf("\"decoder_info\": \""); |
| 734 | ShowData(mpeg_desc->GetDecoderInfo()); |
| 735 | printf("\""); |
| 736 | if (mpeg_desc->GetObjectTypeId() == AP4_OTI_MPEG4_AUDIO || |
| 737 | mpeg_desc->GetObjectTypeId() == AP4_OTI_MPEG2_AAC_AUDIO_LC || |
| 738 | mpeg_desc->GetObjectTypeId() == AP4_OTI_MPEG2_AAC_AUDIO_MAIN) { |
| 739 | AP4_MpegAudioSampleDescription* mpeg_audio_desc = AP4_DYNAMIC_CAST(AP4_MpegAudioSampleDescription, mpeg_desc); |
| 740 | if (mpeg_audio_desc) { |
| 741 | printf(",\n"); |
| 742 | ShowMpegAudioSampleDescription(*mpeg_audio_desc); |
| 743 | } |
| 744 | } |
| 745 | break; |
| 746 | } |
| 747 | |
| 748 | case AP4_SampleDescription::TYPE_AVC: { |
| 749 | // AVC specifics |
| 750 | AP4_AvcSampleDescription* avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, desc); |
| 751 | printf(",\n"); |
| 752 | printf("\"avc_profile\":%d,\n", avc_desc->GetProfile()); |
| 753 | const char* profile_name = AP4_AvccAtom::GetProfileName(avc_desc->GetProfile()); |
| 754 | if (profile_name) printf("\"avc_profile_name\":\"%s\",\n", profile_name); |
| 755 | printf("\"avc_profile_compat\":%d,\n", avc_desc->GetProfileCompatibility()); |
| 756 | printf("\"avc_level\":%d,\n", avc_desc->GetLevel()); |
| 757 | printf("\"avc_nalu_length_size\":%d,\n", avc_desc->GetNaluLengthSize()); |
| 758 | printf("\"avc_sps\": ["); |
| 759 | const char* sep = ""; |
| 760 | for (unsigned int i=0; i<avc_desc->GetSequenceParameters().ItemCount(); i++) { |
| 761 | printf("%s", sep); |
| 762 | printf("\""); |
| 763 | ShowData(avc_desc->GetSequenceParameters()[i]); |
| 764 | printf("\""); |
| 765 | sep = ", "; |
| 766 | } |
| 767 | printf("],\n"); |
| 768 | printf("\"avc_pps\": ["); |
| 769 | sep = ""; |
| 770 | for (unsigned int i=0; i<avc_desc->GetPictureParameters().ItemCount(); i++) { |
| 771 | printf("%s", sep); |
| 772 | printf("\""); |
| 773 | ShowData(avc_desc->GetPictureParameters()[i]); |
| 774 | printf("\""); |
| 775 | sep = ", "; |
| 776 | } |
| 777 | printf("]"); |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | case AP4_SampleDescription::TYPE_HEVC: { |
| 782 | // HEVC Specifics |
| 783 | AP4_HevcSampleDescription* hevc_desc = AP4_DYNAMIC_CAST(AP4_HevcSampleDescription, desc); |
| 784 | printf(",\n"); |
| 785 | printf("\"hevc_profile_space\":%d,\n", hevc_desc->GetGeneralProfileSpace()); |
| 786 | printf("\"hevc_profile\":%d,\n", hevc_desc->GetGeneralProfile()); |
| 787 | const char* profile_name = AP4_HvccAtom::GetProfileName(hevc_desc->GetGeneralProfileSpace(), hevc_desc->GetGeneralProfile()); |
| 788 | if (profile_name) printf("\"hevc_profile_name\":\"%s\",\n", profile_name); |
| 789 | printf("\"hevc_profile_compat\":%d,\n", hevc_desc->GetGeneralProfileCompatibilityFlags()); |
| 790 | printf("\"hevc_constraints\":%llu,\n", hevc_desc->GetGeneralConstraintIndicatorFlags()); |
| 791 | printf("\"hevc_level\":%d,\n", hevc_desc->GetGeneralLevel()); |
| 792 | printf("\"hevc_level_name\":\"%d.%d\",\n", hevc_desc->GetGeneralLevel()/30, (hevc_desc->GetGeneralLevel()%30)/3); |
| 793 | printf("\"hevc_tier\":%d,\n", hevc_desc->GetGeneralTierFlag()); |
| 794 | printf("\"hevc_chroma_format\":%d,\n", hevc_desc->GetChromaFormat()); |
| 795 | const char* chroma_format_name = AP4_HvccAtom::GetChromaFormatName(hevc_desc->GetChromaFormat()); |
| 796 | if (chroma_format_name) printf("\"hevc_chroma_format_name\":\"%s\",\n", chroma_format_name); |
| 797 | printf("\"hevc_chroma_bit_depth\":%d,\n", hevc_desc->GetChromaBitDepth()); |
| 798 | printf("\"hevc_lunma_bit_depth\":%d,\n", hevc_desc->GetLumaBitDepth()); |
| 799 | printf("\"hevc_average_frame_rate\":%d,\n", hevc_desc->GetAverageFrameRate()); |
| 800 | printf("\"hevc_constant_frame_rate\":%d,\n", hevc_desc->GetConstantFrameRate()); |
| 801 | printf("\"hevc_nalu_length_size\":%d,\n", hevc_desc->GetNaluLengthSize()); |
| 802 | printf("\"hevc_sequences\": [\n"); |
| 803 | const char* seq_sep = ""; |
| 804 | for (unsigned int i=0; i<hevc_desc->GetSequences().ItemCount(); i++) { |
| 805 | const AP4_HvccAtom::Sequence& seq = hevc_desc->GetSequences()[i]; |
| 806 | printf("%s {\n", seq_sep); |
| 807 | printf(" \"array_completeness\":%d,\n", seq.m_ArrayCompleteness); |
| 808 | printf(" \"type\":%d,\n", seq.m_NaluType); |
| 809 | const char* nalu_type_name = AP4_HevcNalParser::NaluTypeName(seq.m_NaluType); |
| 810 | if (nalu_type_name) { |
| 811 | printf(" \"type_name\":\"%s\",\n", nalu_type_name); |
| 812 | } |
| 813 | printf(" \"data\":["); |
| 814 | const char* sep = ""; |
| 815 | for (unsigned int j=0; j<seq.m_Nalus.ItemCount(); j++) { |
| 816 | printf("%s", sep); |
| 817 | printf("\""); |
| 818 | ShowData(seq.m_Nalus[j]); |
| 819 | printf("\""); |
| 820 | sep = ", "; |
| 821 | } |
| 822 | printf("]\n }"); |
| 823 | seq_sep = ",\n"; |
| 824 | } |
| 825 | printf("]"); |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | case AP4_SampleDescription::TYPE_AV1: { |
| 830 | // AV1 specifics |
| 831 | AP4_Av1SampleDescription* av1_desc = AP4_DYNAMIC_CAST(AP4_Av1SampleDescription, desc); |
| 832 | printf(",\n"); |
| 833 | printf("\"av1_seq_profile\":%d,\n", av1_desc->GetSeqProfile()); |
| 834 | const char* profile_name = AP4_Av1cAtom::GetProfileName(av1_desc->GetSeqProfile()); |
| 835 | if (profile_name) printf("\"av1_seq_profile_name\":\"%s\",\n", profile_name); |
| 836 | printf("\"av1_seq_level_idx_0\":%d,\n", av1_desc->GetSeqLevelIdx0()); |
| 837 | printf("\"av1_seq_tier_0\":%d", av1_desc->GetSeqTier0()); |
| 838 | break; |
| 839 | } |
| 840 | |
| 841 | case AP4_SampleDescription::TYPE_SUBTITLES: { |
| 842 | // Subtitles |
| 843 | printf(",\n"); |
| 844 | printf("\"subtitles\": {\n"); |
| 845 | AP4_SubtitleSampleDescription* subt_desc = AP4_DYNAMIC_CAST(AP4_SubtitleSampleDescription, desc); |
| 846 | printf(" \"namespace\": \"%s\",\n", subt_desc->GetNamespace().GetChars()); |
| 847 | printf(" \"schema_location\": \"%s\",\n", subt_desc->GetSchemaLocation().GetChars()); |
| 848 | printf(" \"image_mime_type\": \"%s\"\n", subt_desc->GetImageMimeType().GetChars()); |
| 849 | printf("}"); |
| 850 | break; |
| 851 | } |
| 852 | |
| 853 | default: |
| 854 | break; |
| 855 | } |
| 856 | |
| 857 | AP4_AudioSampleDescription* audio_desc = AP4_DYNAMIC_CAST(AP4_AudioSampleDescription, desc); |
| 858 | if (audio_desc) { |
| 859 | // Audio sample description |
| 860 | printf(",\n"); |
| 861 | printf("\"sample_rate\":%d,\n", audio_desc->GetSampleRate()); |
| 862 | printf("\"sample_size\":%d,\n", audio_desc->GetSampleSize()); |
| 863 | printf("\"channels\":%d", audio_desc->GetChannelCount()); |
| 864 | } |
| 865 | |
| 866 | AP4_VideoSampleDescription* video_desc = |
| 867 | AP4_DYNAMIC_CAST(AP4_VideoSampleDescription, desc); |
| 868 | if (video_desc) { |
| 869 | // Video sample description |
| 870 | printf(",\n"); |
| 871 | printf("\"width\":%d,\n", video_desc->GetWidth()); |
| 872 | printf("\"height\":%d,\n", video_desc->GetHeight()); |
| 873 | printf("\"depth\":%d", video_desc->GetDepth()); |
| 874 | } |
| 875 | |
| 876 | switch (desc->GetFormat()) { |
| 877 | case AP4_SAMPLE_FORMAT_AC_3: { |
| 878 | // Dolby Digital specifics |
| 879 | AP4_Dac3Atom* dac3 = AP4_DYNAMIC_CAST(AP4_Dac3Atom, desc->GetDetails().GetChild(AP4_ATOM_TYPE('d', 'a', 'c', '3'))); |
| 880 | if (dac3) { |
| 881 | printf(",\n"); |
| 882 | printf("\"dolby_digital_info\": {\n"); |
| 883 | printf(" \"dac3_payload\": \""); |
| 884 | ShowData(dac3->GetRawBytes()); |
| 885 | printf("\",\n"); |
| 886 | printf(" \"data_rate\": %d,\n", dac3->GetDataRate()); |
| 887 | printf(" \"stream_info\": {\n"); |
| 888 | printf(" \"fscod\": %d,\n", dac3->GetStreamInfo().fscod); |
| 889 | printf(" \"bsid\": %d,\n", dac3->GetStreamInfo().bsid); |
| 890 | printf(" \"bsmod\": %d,\n", dac3->GetStreamInfo().bsmod); |
| 891 | printf(" \"acmod\": %d,\n", dac3->GetStreamInfo().acmod); |
| 892 | printf(" \"lfeon\": %d\n", dac3->GetStreamInfo().lfeon); |
| 893 | printf(" }\n"); |
| 894 | printf("}"); |
| 895 | } |
| 896 | break; |
| 897 | } |
| 898 | |
| 899 | case AP4_SAMPLE_FORMAT_EC_3: { |
| 900 | // Dolby Digital Plus specifics |
| 901 | AP4_Dec3Atom* dec3 = AP4_DYNAMIC_CAST(AP4_Dec3Atom, desc->GetDetails().GetChild(AP4_ATOM_TYPE('d', 'e', 'c', '3'))); |
| 902 | if (dec3) { |
| 903 | printf(",\n"); |
| 904 | printf("\"dolby_digital_plus_info\": {\n"); |
| 905 | printf(" \"dec3_payload\": \""); |
| 906 | ShowData(dec3->GetRawBytes()); |
| 907 | printf("\",\n"); |
| 908 | printf(" \"data_rate\": %d,\n", dec3->GetDataRate()); |
| 909 | if (dec3->GetFlagEC3ExtensionTypeA()){ |
| 910 | printf(" \"Dolby_Atmos\": \"Yes\",\n"); |
| 911 | printf(" \"complexity_index\": %d,\n", dec3->GetComplexityIndexTypeA()); |
| 912 | } else { |
| 913 | printf(" \"Dolby_Atmos\": \"No\",\n"); |
| 914 | } |
| 915 | printf(" \"substreams\": [\n"); |
| 916 | const char* sep = ""; |
| 917 | for (unsigned int i=0; i<dec3->GetSubStreams().ItemCount(); i++) { |
| 918 | printf("%s {\n", sep); |
| 919 | printf(" \"fscod\": %d,\n", dec3->GetSubStreams()[i].fscod); |
| 920 | printf(" \"bsid\": %d,\n", dec3->GetSubStreams()[i].bsid); |
| 921 | printf(" \"bsmod\": %d,\n", dec3->GetSubStreams()[i].bsmod); |
| 922 | printf(" \"acmod\": %d,\n", dec3->GetSubStreams()[i].acmod); |
| 923 | printf(" \"lfeon\": %d,\n", dec3->GetSubStreams()[i].lfeon); |
| 924 | printf(" \"num_dep_sub\": %d,\n", dec3->GetSubStreams()[i].num_dep_sub); |
| 925 | printf(" \"chan_loc\": %d\n", dec3->GetSubStreams()[i].chan_loc); |
| 926 | printf(" }"); |
| 927 | sep = ",\n"; |
| 928 | } |
| 929 | printf("\n ]\n}"); |
| 930 | } |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | case AP4_SAMPLE_FORMAT_AC_4: { |
| 935 | // Dolby AC-4 specifics |
| 936 | AP4_Dac4Atom* dac4 = AP4_DYNAMIC_CAST(AP4_Dac4Atom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DAC4)); |
| 937 | if (dac4) { |
| 938 | printf(",\n"); |
| 939 | printf("\"dolby_ac4_info\": {\n"); |
| 940 | const AP4_Dac4Atom::Ac4Dsi& dsi = dac4->GetDsi(); |
| 941 | printf(" \"dsi version\": %d,\n", dsi.ac4_dsi_version); |
| 942 | unsigned short self_contained = 0; |
| 943 | if (dsi.ac4_dsi_version == 1) { |
| 944 | printf(" \"bitstream version\": %d,\n", dsi.d.v1.bitstream_version); |
| 945 | printf(" \"presentations\": [\n"); |
| 946 | const char* separator = ""; |
| 947 | for (unsigned int i = 0; i < dsi.d.v1.n_presentations; i++) { |
| 948 | AP4_Dac4Atom::Ac4Dsi::PresentationV1& presentation = dsi.d.v1.presentations[i]; |
| 949 | if (presentation.presentation_version == 1 || presentation.presentation_version == 2) { |
| 950 | printf("%s { ", separator); |
| 951 | |
| 952 | char presentation_type [64]; |
| 953 | char presentation_codec[64]; |
| 954 | char presentation_lang [64 + 1] = "un"; |
| 955 | AP4_FormatString(presentation_codec, |
| 956 | sizeof(presentation_codec), |
| 957 | "ac-4.%02x.%02x.%02x", |
| 958 | dsi.d.v1.bitstream_version, |
| 959 | presentation.presentation_version, |
| 960 | presentation.d.v1.mdcompat); |
| 961 | for (int sg = 0; sg < presentation.d.v1.n_substream_groups; sg++){ |
| 962 | if ( presentation.d.v1.substream_groups[sg].d.v1.b_content_type && |
| 963 | (presentation.d.v1.substream_groups[sg].d.v1.content_classifier == 0 ||presentation.d.v1.substream_groups[sg].d.v1.content_classifier == 4) && |
| 964 | presentation.d.v1.substream_groups[sg].d.v1.b_language_indicator){ |
| 965 | memcpy(presentation_lang, presentation.d.v1.substream_groups[sg].d.v1.language_tag_bytes, presentation.d.v1.substream_groups[sg].d.v1.n_language_tag_bytes); |
| 966 | presentation_lang[presentation.d.v1.substream_groups[sg].d.v1.n_language_tag_bytes] = '\0'; |
| 967 | } |
| 968 | } |
| 969 | if (presentation.d.v1.b_multi_pid == 0) { self_contained ++; } |
| 970 | if (presentation.d.v1.b_presentation_channel_coded == 1) { |
| 971 | AP4_FormatString(presentation_type, sizeof(presentation_type), "Channel based"); |
| 972 | if (presentation.d.v1.dsi_presentation_ch_mode >= 11 && presentation.d.v1.dsi_presentation_ch_mode <= 15) { |
| 973 | AP4_FormatString(presentation_type, sizeof(presentation_type), "Channel based immsersive"); |
| 974 | } |
| 975 | } else { |
| 976 | AP4_FormatString(presentation_type, sizeof(presentation_type), "Object based"); |
| 977 | } |
| 978 | if (presentation.presentation_version == 2) { |
| 979 | printf("\"Stream Type\": \"Immersive stereo\", "); |
| 980 | } else { |
| 981 | printf("\"Stream Type\": \"%s\", ", presentation_type); |
| 982 | } |
| 983 | printf("\"presentation_id\": %d, ", presentation.d.v1.b_presentation_id? presentation.d.v1.presentation_id : -1); |
| 984 | printf("\"presentation_channel_mask_v1\": %u, ",presentation.d.v1.presentation_channel_mask_v1); |
| 985 | printf("\"Dolby Atmos source\": \"%s\", ", presentation.d.v1.dolby_atmos_indicator? "Yes": "No"); |
| 986 | printf("\"Language\": \"%s\", ", presentation_lang); |
| 987 | printf("\"Self Contained\": \"%s\"} ", presentation.d.v1.b_multi_pid? "No": "Yes"); |
| 988 | separator = ",\n"; |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | printf("\n ],\n"); |
| 993 | |
| 994 | printf(" \"Self Contained\": \"%s\",\n", (self_contained == dsi.d.v1.n_presentations) ? "Yes": ((self_contained == 0)? "No": "Part")); |
| 995 | printf(" \"dac4_payload\": \""); |
| 996 | ShowData(dac4->GetRawBytes()); |
| 997 | printf("\"\n}"); |
| 998 | } |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | case AP4_SAMPLE_FORMAT_VP8: |
| 1003 | case AP4_SAMPLE_FORMAT_VP9: |
| 1004 | case AP4_SAMPLE_FORMAT_VP10: { |
| 1005 | // VPx Specifics |
| 1006 | AP4_VpccAtom* vpcc = AP4_DYNAMIC_CAST(AP4_VpccAtom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_VPCC)); |
| 1007 | if (vpcc) { |
| 1008 | printf(",\n"); |
| 1009 | printf("\"vpx_info\": {\n"); |
| 1010 | printf(" \"profile\":%d,\n", vpcc->GetProfile()); |
| 1011 | printf(" \"level\":%d,\n", vpcc->GetLevel()); |
| 1012 | printf(" \"bit_depth\":%d,\n", vpcc->GetBitDepth()); |
| 1013 | printf(" \"chroma_subsampling\":%d,\n", vpcc->GetChromaSubsampling()); |
| 1014 | printf(" \"colour_primaries\":%d,\n", vpcc->GetColourPrimaries()); |
| 1015 | printf(" \"transfer_characteristics\":%d,\n", vpcc->GetTransferCharacteristics()); |
| 1016 | printf(" \"matrix_coefficients\":%d,\n", vpcc->GetMatrixCoefficients()); |
| 1017 | printf(" \"video_full_range_flag\":%s\n", vpcc->GetVideoFullRangeFlag() ? "true" : "false"); |
| 1018 | printf("}"); |
| 1019 | } |
| 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | // Dolby Vision specifics |
| 1025 | AP4_DvccAtom* dvcc = AP4_DYNAMIC_CAST(AP4_DvccAtom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DVCC)); |
| 1026 | if(!dvcc) { |
| 1027 | dvcc = AP4_DYNAMIC_CAST(AP4_DvccAtom, desc->GetDetails().GetChild(AP4_ATOM_TYPE_DVVC)); |
| 1028 | } |
| 1029 | if (dvcc) { |
| 1030 | /* Codec String */ |
| 1031 | char workspace[64]; |
| 1032 | char coding[5]; |
| 1033 | strncpy(coding, codec.GetChars(), 4); |
| 1034 | coding[4] = '\0'; |
| 1035 | /* Non back-compatible */ |
| 1036 | if (strcmp(coding, "dvav") == 0 || strcmp(coding, "dva1") == 0 || |
| 1037 | strcmp(coding, "dvhe") == 0 || strcmp(coding, "dvh1") == 0){ |
| 1038 | AP4_FormatString(workspace, |
| 1039 | sizeof(workspace), |
| 1040 | "%s.%02d.%02d", |
| 1041 | coding, |
| 1042 | dvcc->GetDvProfile(), |
| 1043 | dvcc->GetDvLevel()); |
| 1044 | codec = workspace; |
| 1045 | } else { |
| 1046 | if (strcmp(coding, "avc1") == 0){ |
| 1047 | strcpy(coding, "dva1"); |
| 1048 | }else if (strcmp(coding, "avc3") == 0){ |
| 1049 | strcpy(coding, "dvav"); |
| 1050 | }else if (strcmp(coding, "hev1") == 0){ |
| 1051 | strcpy(coding, "dvhe"); |
| 1052 | }else if (strcmp(coding, "hvc1") == 0){ |
| 1053 | strcpy(coding, "dvh1"); |
| 1054 | } |
| 1055 | AP4_FormatString(workspace, |
| 1056 | sizeof(workspace), |
| 1057 | "%s,%s.%02d.%02d", |
| 1058 | codec.GetChars(), |
| 1059 | coding, |
| 1060 | dvcc->GetDvProfile(), |
| 1061 | dvcc->GetDvLevel()); |
| 1062 | codec = workspace; |
| 1063 | } |
| 1064 | printf(",\n"); |
| 1065 | printf("\"dv_codecs_string\":\""); |
| 1066 | printf("%s", codec.GetChars()); |
| 1067 | printf("\""); |
| 1068 | /* Dolby Vision */ |
| 1069 | printf(",\n"); |
| 1070 | printf("\"dolby_vision\": {\n"); |
| 1071 | printf(" \"version_major\": %d,\n", dvcc->GetDvVersionMajor()); |
| 1072 | printf(" \"version_minor\": %d,\n", dvcc->GetDvVersionMinor()); |
| 1073 | printf(" \"profile\": %d,\n", dvcc->GetDvProfile()); |
| 1074 | const char* profile_name = AP4_DvccAtom::GetProfileName(dvcc->GetDvProfile()); |
| 1075 | printf(" \"profile_name\": \"%s\",\n", profile_name?profile_name:""); |
| 1076 | printf(" \"level\": %d,\n", dvcc->GetDvLevel()); |
| 1077 | printf(" \"rpu_present\": %s,\n", dvcc->GetRpuPresentFlag()?"true":"false"); |
| 1078 | printf(" \"el_present\": %s,\n", dvcc->GetElPresentFlag()?"true":"false"); |
| 1079 | printf(" \"bl_present\": %s,\n", dvcc->GetBlPresentFlag()?"true":"false"); |
| 1080 | printf(" \"dv_bl_signal_compatibility_id\": %d\n", dvcc->GetDvBlSignalCompatibilityID()); |
| 1081 | printf("}"); |
| 1082 | } |
| 1083 | |
| 1084 | printf("\n}"); |
| 1085 | } |
| 1086 | |
| 1087 | /*---------------------------------------------------------------------- |
| 1088 | | ShowSampleDescription |
| 1089 | +---------------------------------------------------------------------*/ |
| 1090 | static void |
| 1091 | ShowSampleDescription(AP4_SampleDescription& description, bool verbose) |
| 1092 | { |
| 1093 | switch (Options.format) { |
| 1094 | case TEXT_FORMAT: ShowSampleDescription_Text(description, verbose); break; |
| 1095 | case JSON_FORMAT: ShowSampleDescription_Json(description, verbose); break; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | /*---------------------------------------------------------------------- |
| 1100 | | ShowDcfInfo |
| 1101 | +---------------------------------------------------------------------*/ |
| 1102 | static void |
| 1103 | ShowDcfInfo(AP4_File& file) |
| 1104 | { |
| 1105 | AP4_FtypAtom* ftyp = file.GetFileType(); |
| 1106 | if (ftyp == NULL) return; |
| 1107 | printf("OMA DCF File, version=%d\n", ftyp->GetMinorVersion()); |
| 1108 | if (ftyp->GetMinorVersion() != 2) return; |
| 1109 | |
| 1110 | AP4_OdheAtom* odhe = AP4_DYNAMIC_CAST(AP4_OdheAtom, file.FindChild("odrm/odhe")); |
| 1111 | if (odhe) { |
| 1112 | printf("Content Type: %s\n", odhe->GetContentType().GetChars()); |
| 1113 | } |
| 1114 | AP4_OhdrAtom* ohdr = AP4_DYNAMIC_CAST(AP4_OhdrAtom, file.FindChild("odrm/odhe/ohdr")); |
| 1115 | if (ohdr) { |
| 1116 | printf("Encryption Method: "); |
| 1117 | switch (ohdr->GetEncryptionMethod()) { |
| 1118 | case AP4_OMA_DCF_ENCRYPTION_METHOD_NULL: printf("NULL\n"); break; |
| 1119 | case AP4_OMA_DCF_ENCRYPTION_METHOD_AES_CBC: printf("AES-128-CBC\n"); break; |
| 1120 | case AP4_OMA_DCF_ENCRYPTION_METHOD_AES_CTR: printf("AES-128-CTR\n"); break; |
| 1121 | default: printf("%d\n", ohdr->GetEncryptionMethod()); |
| 1122 | } |
| 1123 | printf("Padding Scheme: "); |
| 1124 | switch (ohdr->GetPaddingScheme()) { |
| 1125 | case AP4_OMA_DCF_PADDING_SCHEME_NONE: printf("NONE\n"); break; |
| 1126 | case AP4_OMA_DCF_PADDING_SCHEME_RFC_2630: printf("RFC 2630\n"); break; |
| 1127 | default: printf("%d\n", ohdr->GetPaddingScheme()); |
| 1128 | } |
| 1129 | printf("Content ID: %s\n", ohdr->GetContentId().GetChars()); |
| 1130 | printf("Rights Issuer URL: %s\n", ohdr->GetRightsIssuerUrl().GetChars()); |
| 1131 | printf("Textual Headers:\n"); |
| 1132 | |
| 1133 | AP4_Size headers_size = ohdr->GetTextualHeaders().GetDataSize(); |
| 1134 | const char* headers = (const char*)ohdr->GetTextualHeaders().GetData(); |
| 1135 | while (headers_size) { |
| 1136 | printf(" %s\n", headers); |
| 1137 | AP4_Size header_len = (AP4_Size)strlen(headers); |
| 1138 | headers_size -= header_len+1; |
| 1139 | headers += header_len+1; |
| 1140 | } |
| 1141 | AP4_GrpiAtom* grpi = AP4_DYNAMIC_CAST(AP4_GrpiAtom, ohdr->GetChild(AP4_ATOM_TYPE_GRPI)); |
| 1142 | if (grpi) { |
| 1143 | printf("Group ID: %s\n", grpi->GetGroupId().GetChars()); |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | /*---------------------------------------------------------------------- |
| 1149 | | ReadGolomb |
| 1150 | +---------------------------------------------------------------------*/ |
| 1151 | static unsigned int |
| 1152 | ReadGolomb(AP4_BitStream& bits) |
| 1153 | { |
| 1154 | unsigned int leading_zeros = 0; |
| 1155 | while (bits.ReadBit() == 0) { |
| 1156 | leading_zeros++; |
| 1157 | } |
| 1158 | if (leading_zeros) { |
| 1159 | return (1<<leading_zeros)-1+bits.ReadBits(leading_zeros); |
| 1160 | } else { |
| 1161 | return 0; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | /*---------------------------------------------------------------------- |
| 1166 | | ShowAvcInfo |
| 1167 | +---------------------------------------------------------------------*/ |
| 1168 | static void |
| 1169 | ShowAvcInfo(const AP4_DataBuffer& sample_data, AP4_AvcSampleDescription* avc_desc) |
| 1170 | { |
| 1171 | const unsigned char* data = sample_data.GetData(); |
| 1172 | AP4_Size size = sample_data.GetDataSize(); |
| 1173 | |
| 1174 | while (size >= avc_desc->GetNaluLengthSize()) { |
| 1175 | unsigned int nalu_length = 0; |
| 1176 | if (avc_desc->GetNaluLengthSize() == 1) { |
| 1177 | nalu_length = *data++; |
| 1178 | --size; |
| 1179 | } else if (avc_desc->GetNaluLengthSize() == 2) { |
| 1180 | nalu_length = AP4_BytesToUInt16BE(data); |
| 1181 | data += 2; |
| 1182 | size -= 2; |
| 1183 | } else if (avc_desc->GetNaluLengthSize() == 4) { |
| 1184 | nalu_length = AP4_BytesToUInt32BE(data); |
| 1185 | data += 4; |
| 1186 | size -= 4; |
| 1187 | } else { |
| 1188 | return; |
| 1189 | } |
| 1190 | if (nalu_length <= size) { |
| 1191 | size -= nalu_length; |
| 1192 | } else { |
| 1193 | size = 0; |
| 1194 | } |
| 1195 | |
| 1196 | switch (*data & 0x1F) { |
| 1197 | case 1: { |
| 1198 | AP4_BitStream bits; |
| 1199 | bits.WriteBytes(data+1, 8); |
| 1200 | ReadGolomb(bits); |
| 1201 | unsigned int slice_type = ReadGolomb(bits); |
| 1202 | switch (slice_type) { |
| 1203 | case 0: printf("<P>"); break; |
| 1204 | case 1: printf("<B>"); break; |
| 1205 | case 2: printf("<I>"); break; |
| 1206 | case 3: printf("<SP>"); break; |
| 1207 | case 4: printf("<SI>"); break; |
| 1208 | case 5: printf("<P>"); break; |
| 1209 | case 6: printf("<B>"); break; |
| 1210 | case 7: printf("<I>"); break; |
| 1211 | case 8: printf("<SP>"); break; |
| 1212 | case 9: printf("<SI>"); break; |
| 1213 | default: printf("<S/%d>", slice_type); break; |
| 1214 | } |
| 1215 | return; // only show first slice type |
| 1216 | } |
| 1217 | |
| 1218 | case 5: |
| 1219 | printf("<I>"); |
| 1220 | return; |
| 1221 | } |
| 1222 | |
| 1223 | data += nalu_length; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | /*---------------------------------------------------------------------- |
| 1228 | | ShowSample_Text |
| 1229 | +---------------------------------------------------------------------*/ |
| 1230 | static void |
| 1231 | ShowSample_Text(AP4_Track& track, |
| 1232 | AP4_Sample& sample, |
| 1233 | AP4_DataBuffer& sample_data, |
| 1234 | unsigned int index, |
| 1235 | bool verbose, |
| 1236 | bool show_sample_data, |
| 1237 | AP4_AvcSampleDescription* avc_desc) |
| 1238 | { |
| 1239 | printf("[%02d.%06d] size=%6d duration=%6d", |
| 1240 | track.GetId(), |
| 1241 | index+1, |
| 1242 | (int)sample.GetSize(), |
| 1243 | (int)sample.GetDuration()); |
| 1244 | if (verbose) { |
| 1245 | printf(" (%6d ms) offset=%10lld dts=%10lld (%10lld ms) cts=%10lld (%10lld ms) [%d]", |
| 1246 | (int)AP4_ConvertTime(sample.GetDuration(), track.GetMediaTimeScale(), 1000), |
| 1247 | sample.GetOffset(), |
| 1248 | sample.GetDts(), |
| 1249 | AP4_ConvertTime(sample.GetDts(), track.GetMediaTimeScale(), 1000), |
| 1250 | sample.GetCts(), |
| 1251 | AP4_ConvertTime(sample.GetCts(), track.GetMediaTimeScale(), 1000), |
| 1252 | sample.GetDescriptionIndex()); |
| 1253 | } |
| 1254 | if (sample.IsSync()) { |
| 1255 | printf(" [S] "); |
| 1256 | } else { |
| 1257 | printf(" "); |
| 1258 | } |
| 1259 | if (avc_desc || show_sample_data) { |
| 1260 | sample.ReadData(sample_data); |
| 1261 | } |
| 1262 | if (avc_desc) { |
| 1263 | ShowAvcInfo(sample_data, avc_desc); |
| 1264 | } |
| 1265 | if (show_sample_data) { |
| 1266 | unsigned int show = sample_data.GetDataSize(); |
| 1267 | if (!verbose) { |
| 1268 | if (show > 12) show = 12; // max first 12 chars |
| 1269 | } |
| 1270 | |
| 1271 | for (unsigned int i=0; i<show; i++) { |
| 1272 | if (verbose) { |
| 1273 | if (i%16 == 0) { |
| 1274 | printf("\n%06d: ", i); |
| 1275 | } |
| 1276 | } |
| 1277 | printf("%02x", sample_data.GetData()[i]); |
| 1278 | if (verbose) printf(" "); |
| 1279 | } |
| 1280 | if (show != sample_data.GetDataSize()) { |
| 1281 | printf("..."); |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | /*---------------------------------------------------------------------- |
| 1287 | | ScanMedia |
| 1288 | +---------------------------------------------------------------------*/ |
| 1289 | static void |
| 1290 | ScanMedia(AP4_Movie& movie, AP4_Track& track, AP4_ByteStream& stream, MediaInfo& info) |
| 1291 | { |
| 1292 | AP4_UI64 total_size = 0; |
| 1293 | AP4_UI64 total_duration = 0; |
| 1294 | |
| 1295 | AP4_UI64 position; |
| 1296 | stream.Tell(position); |
| 1297 | stream.Seek(0); |
| 1298 | AP4_LinearReader reader(movie, &stream); |
| 1299 | reader.EnableTrack(track.GetId()); |
| 1300 | |
| 1301 | info.sample_count = 0; |
| 1302 | |
| 1303 | AP4_Sample sample; |
| 1304 | if (movie.HasFragments()) { |
| 1305 | AP4_DataBuffer sample_data; |
| 1306 | for(unsigned int i=0; ; i++) { |
| 1307 | AP4_UI32 track_id = 0; |
| 1308 | AP4_Result result = reader.ReadNextSample(sample, sample_data, track_id); |
| 1309 | if (AP4_SUCCEEDED(result)) { |
| 1310 | total_size += sample.GetSize(); |
| 1311 | total_duration += sample.GetDuration(); |
| 1312 | ++info.sample_count; |
| 1313 | } else { |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | } else { |
| 1318 | info.sample_count = track.GetSampleCount(); |
| 1319 | for (unsigned int i=0; i<track.GetSampleCount(); i++) { |
| 1320 | if (AP4_SUCCEEDED(track.GetSample(i, sample))) { |
| 1321 | total_size += sample.GetSize(); |
| 1322 | } |
| 1323 | } |
| 1324 | total_duration = track.GetMediaDuration(); |
| 1325 | } |
| 1326 | info.duration = total_duration; |
| 1327 | |
| 1328 | double duration_ms = (double)AP4_ConvertTime(total_duration, track.GetMediaTimeScale(), 1000); |
| 1329 | if (duration_ms) { |
| 1330 | info.bitrate = 8.0*1000.0*(double)total_size/duration_ms; |
| 1331 | } else { |
| 1332 | info.bitrate = 0.0; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | /*---------------------------------------------------------------------- |
| 1337 | | ShowTrackInfo_Text |
| 1338 | +---------------------------------------------------------------------*/ |
| 1339 | static void |
| 1340 | ShowTrackInfo_Text(AP4_Movie& movie, AP4_Track& track, AP4_ByteStream& stream, bool show_samples, bool show_sample_data, bool verbose, bool fast) |
| 1341 | { |
| 1342 | printf(" flags: %d", track.GetFlags()); |
| 1343 | if (track.GetFlags() & AP4_TRACK_FLAG_ENABLED) { |
| 1344 | printf(" ENABLED"); |
| 1345 | } |
| 1346 | if (track.GetFlags() & AP4_TRACK_FLAG_IN_MOVIE) { |
| 1347 | printf(" IN-MOVIE"); |
| 1348 | } |
| 1349 | if (track.GetFlags() & AP4_TRACK_FLAG_IN_PREVIEW) { |
| 1350 | printf(" IN-PREVIEW"); |
| 1351 | } |
| 1352 | printf("\n"); |
| 1353 | printf(" id: %d\n", track.GetId()); |
| 1354 | printf(" type: "); |
| 1355 | switch (track.GetType()) { |
| 1356 | case AP4_Track::TYPE_AUDIO: printf("Audio\n"); break; |
| 1357 | case AP4_Track::TYPE_VIDEO: printf("Video\n"); break; |
| 1358 | case AP4_Track::TYPE_HINT: printf("Hint\n"); break; |
| 1359 | case AP4_Track::TYPE_SYSTEM: printf("System\n"); break; |
| 1360 | case AP4_Track::TYPE_TEXT: printf("Text\n"); break; |
| 1361 | case AP4_Track::TYPE_JPEG: printf("JPEG\n"); break; |
| 1362 | case AP4_Track::TYPE_SUBTITLES: printf("Subtitles\n"); break; |
| 1363 | default: { |
| 1364 | char hdlr[5]; |
| 1365 | AP4_FormatFourChars(hdlr, track.GetHandlerType()); |
| 1366 | printf("Unknown ["); |
| 1367 | printf("%s", hdlr); |
| 1368 | printf("]\n"); |
| 1369 | break; |
| 1370 | } |
| 1371 | } |
| 1372 | printf(" duration: %d ms\n", track.GetDurationMs()); |
| 1373 | printf(" language: %s\n", track.GetTrackLanguage()); |
| 1374 | printf(" media:\n"); |
| 1375 | printf(" sample count: %d\n", track.GetSampleCount()); |
| 1376 | printf(" timescale: %d\n", track.GetMediaTimeScale()); |
| 1377 | printf(" duration: %lld (media timescale units)\n", track.GetMediaDuration()); |
| 1378 | printf(" duration: %d (ms)\n", (AP4_UI32)AP4_ConvertTime(track.GetMediaDuration(), track.GetMediaTimeScale(), 1000)); |
| 1379 | if (!fast) { |
| 1380 | MediaInfo media_info; |
| 1381 | ScanMedia(movie, track, stream, media_info); |
| 1382 | printf(" bitrate (computed): %.3f Kbps\n", media_info.bitrate/1000.0); |
| 1383 | if (movie.HasFragments()) { |
| 1384 | printf(" sample count with fragments: %lld\n", media_info.sample_count); |
| 1385 | printf(" duration with fragments: %lld\n", media_info.duration); |
| 1386 | printf(" duration with fragments: %d (ms)\n", (AP4_UI32)AP4_ConvertTime(media_info.duration, track.GetMediaTimeScale(), 1000)); |
| 1387 | } |
| 1388 | } |
| 1389 | if (track.GetWidth() || track.GetHeight()) { |
| 1390 | printf(" display width: %f\n", (float)track.GetWidth()/65536.0); |
| 1391 | printf(" display height: %f\n", (float)track.GetHeight()/65536.0); |
| 1392 | } |
| 1393 | if (track.GetType() == AP4_Track::TYPE_VIDEO && track.GetSampleCount()) { |
| 1394 | printf(" frame rate (computed): %.3f\n", (float)track.GetSampleCount()/ |
| 1395 | ((float)track.GetMediaDuration()/(float)track.GetMediaTimeScale())); |
| 1396 | } |
| 1397 | |
| 1398 | // show all sample descriptions |
| 1399 | AP4_AvcSampleDescription* avc_desc = NULL; |
| 1400 | for (unsigned int desc_index=0; |
| 1401 | AP4_SampleDescription* sample_desc = track.GetSampleDescription(desc_index); |
| 1402 | desc_index++) { |
| 1403 | printf(" Sample Description %d\n", desc_index); |
| 1404 | ShowSampleDescription(*sample_desc, verbose); |
| 1405 | avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sample_desc); |
| 1406 | } |
| 1407 | |
| 1408 | // show samples if requested |
| 1409 | if (show_samples) { |
| 1410 | AP4_Sample sample; |
| 1411 | AP4_DataBuffer sample_data; |
| 1412 | AP4_Ordinal index = 0; |
| 1413 | while (AP4_SUCCEEDED(track.GetSample(index, sample))) { |
| 1414 | if (avc_desc || show_sample_data) { |
| 1415 | sample.ReadData(sample_data); |
| 1416 | } |
| 1417 | |
| 1418 | ShowSample_Text(track, sample, sample_data, index, verbose, show_sample_data, avc_desc); |
| 1419 | printf("\n"); |
| 1420 | index++; |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | /*---------------------------------------------------------------------- |
| 1426 | | ShowTrackInfo_Json |
| 1427 | +---------------------------------------------------------------------*/ |
| 1428 | static void |
| 1429 | ShowTrackInfo_Json(AP4_Movie& movie, AP4_Track& track, AP4_ByteStream& stream, bool /*show_samples*/, bool /*show_sample_data*/, bool verbose, bool fast) |
| 1430 | { |
| 1431 | printf("{\n"); |
| 1432 | printf(" \"flags\":%d,\n", track.GetFlags()); |
| 1433 | printf(" \"flag_names\":["); |
| 1434 | const char* sep = ""; |
| 1435 | if (track.GetFlags() & AP4_TRACK_FLAG_ENABLED) { |
| 1436 | printf("\"ENABLED\""); |
| 1437 | sep = " ,"; |
| 1438 | } |
| 1439 | if (track.GetFlags() & AP4_TRACK_FLAG_IN_MOVIE) { |
| 1440 | printf("%s\"IN-MOVIE\"", sep); |
| 1441 | sep = " ,"; |
| 1442 | } |
| 1443 | if (track.GetFlags() & AP4_TRACK_FLAG_IN_PREVIEW) { |
| 1444 | printf("%s\"IN-PREVIEW\"", sep); |
| 1445 | } |
| 1446 | printf("],\n"); |
| 1447 | printf(" \"id\":%d,\n", track.GetId()); |
| 1448 | printf(" \"type\":"); |
| 1449 | switch (track.GetType()) { |
| 1450 | case AP4_Track::TYPE_AUDIO: printf("\"Audio\""); break; |
| 1451 | case AP4_Track::TYPE_VIDEO: printf("\"Video\""); break; |
| 1452 | case AP4_Track::TYPE_HINT: printf("\"Hint\""); break; |
| 1453 | case AP4_Track::TYPE_SYSTEM: printf("\"System\""); break; |
| 1454 | case AP4_Track::TYPE_TEXT: printf("\"Text\""); break; |
| 1455 | case AP4_Track::TYPE_JPEG: printf("\"JPEG\""); break; |
| 1456 | case AP4_Track::TYPE_SUBTITLES: printf("\"Subtitles\""); break; |
| 1457 | default: { |
| 1458 | char hdlr[5]; |
| 1459 | AP4_FormatFourChars(hdlr, track.GetHandlerType()); |
| 1460 | printf("\"Unknown ["); |
| 1461 | printf("%s", hdlr); |
| 1462 | printf("]\""); |
| 1463 | break; |
| 1464 | } |
| 1465 | } |
| 1466 | printf(",\n"); |
| 1467 | printf(" \"duration_ms\":%d,\n", track.GetDurationMs()); |
| 1468 | printf(" \"language\":\"%s\",\n", track.GetTrackLanguage()); |
| 1469 | printf(" \"media\":{\n"); |
| 1470 | printf(" \"sample_count\":%d,\n", track.GetSampleCount()); |
| 1471 | printf(" \"timescale\":%d,\n", track.GetMediaTimeScale()); |
| 1472 | printf(" \"duration\":%lld,\n", track.GetMediaDuration()); |
| 1473 | printf(" \"duration_ms\":%d", (AP4_UI32)AP4_ConvertTime(track.GetMediaDuration(), track.GetMediaTimeScale(), 1000)); |
| 1474 | if (!fast) { |
| 1475 | MediaInfo media_info; |
| 1476 | ScanMedia(movie, track, stream, media_info); |
| 1477 | printf(",\n"); |
| 1478 | printf(" \"bitrate\":%.3f", media_info.bitrate/1000.0); |
| 1479 | if (movie.HasFragments()) { |
| 1480 | printf(",\n"); |
| 1481 | printf(" \"sample_count_with_fragments\":%lld,\n", media_info.sample_count); |
| 1482 | printf(" \"duration_with_fragments\":%lld,\n", media_info.duration); |
| 1483 | printf(" \"duration_with_fragments_ms\":%d", (AP4_UI32)AP4_ConvertTime(media_info.duration, track.GetMediaTimeScale(), 1000)); |
| 1484 | } |
| 1485 | printf("\n"); |
| 1486 | } else { |
| 1487 | printf("\n"); |
| 1488 | } |
| 1489 | printf(" },\n"); |
| 1490 | if (track.GetWidth() || track.GetHeight()) { |
| 1491 | printf(" \"display_width\":%f,\n", (float)track.GetWidth()/65536.0); |
| 1492 | printf(" \"display_height\":%f,\n", (float)track.GetHeight()/65536.0); |
| 1493 | } |
| 1494 | if (track.GetType() == AP4_Track::TYPE_VIDEO && track.GetSampleCount()) { |
| 1495 | printf(" \"frame_rate\":%.3f,\n", (float)1000*track.GetSampleCount()/ |
| 1496 | (float)track.GetDurationMs()); |
| 1497 | } |
| 1498 | |
| 1499 | // show all sample descriptions |
| 1500 | printf(" \"sample_descriptions\":[\n"); |
| 1501 | //AP4_AvcSampleDescription* avc_desc = NULL; |
| 1502 | sep = ""; |
| 1503 | for (unsigned int desc_index=0; |
| 1504 | AP4_SampleDescription* sample_desc = track.GetSampleDescription(desc_index); |
| 1505 | desc_index++) { |
| 1506 | printf("%s", sep); |
| 1507 | ShowSampleDescription(*sample_desc, verbose); |
| 1508 | sep = ",\n"; |
| 1509 | //if (sample_desc->GetFormat() == AP4_SAMPLE_FORMAT_AVC1) { |
| 1510 | // avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sample_desc); |
| 1511 | //} |
| 1512 | } |
| 1513 | printf(" ]\n"); |
| 1514 | printf("}"); |
| 1515 | } |
| 1516 | |
| 1517 | /*---------------------------------------------------------------------- |
| 1518 | | ShowTrackInfo |
| 1519 | +---------------------------------------------------------------------*/ |
| 1520 | static void |
| 1521 | ShowTrackInfo(AP4_Movie& movie, AP4_Track& track, AP4_ByteStream& stream, bool show_samples, bool show_sample_data, bool verbose, bool fast) |
| 1522 | { |
| 1523 | switch (Options.format) { |
| 1524 | case TEXT_FORMAT: |
| 1525 | ShowTrackInfo_Text(movie, track, stream, show_samples, show_sample_data, verbose, fast); |
| 1526 | break; |
| 1527 | |
| 1528 | case JSON_FORMAT: |
| 1529 | ShowTrackInfo_Json(movie, track, stream, show_samples, show_sample_data, verbose, fast); |
| 1530 | break; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | /*---------------------------------------------------------------------- |
| 1535 | | ShowMovieInfo |
| 1536 | +---------------------------------------------------------------------*/ |
| 1537 | static void |
| 1538 | ShowMovieInfo(AP4_Movie& movie) |
| 1539 | { |
| 1540 | switch (Options.format) { |
| 1541 | case TEXT_FORMAT: |
| 1542 | printf("Movie:\n"); |
| 1543 | printf(" duration: %lld (movie timescale units)\n", movie.GetDuration()); |
| 1544 | printf(" duration: %d (ms)\n", movie.GetDurationMs()); |
| 1545 | printf(" time scale: %d\n", movie.GetTimeScale()); |
| 1546 | printf(" fragments: %s\n", movie.HasFragments()?"yes":"no"); |
| 1547 | printf("\n"); |
| 1548 | break; |
| 1549 | |
| 1550 | case JSON_FORMAT: |
| 1551 | printf("\"movie\":{\n"); |
| 1552 | printf(" \"duration_ms\":%d,\n", movie.GetDurationMs()); |
| 1553 | printf(" \"duration\":%lld,\n", movie.GetDuration()); |
| 1554 | printf(" \"time_scale\":%d,\n", movie.GetTimeScale()); |
| 1555 | printf(" \"fragments\":%s\n", movie.HasFragments()?"true":"false"); |
| 1556 | printf("},\n"); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | /*---------------------------------------------------------------------- |
| 1561 | | ShowFileInfo |
| 1562 | +---------------------------------------------------------------------*/ |
| 1563 | static void |
| 1564 | ShowFileInfo(AP4_File& file) |
| 1565 | { |
| 1566 | AP4_FtypAtom* file_type = file.GetFileType(); |
| 1567 | if (file_type == NULL) return; |
| 1568 | char four_cc[5]; |
| 1569 | |
| 1570 | AP4_FormatFourChars(four_cc, file_type->GetMajorBrand()); |
| 1571 | switch (Options.format) { |
| 1572 | case TEXT_FORMAT: |
| 1573 | printf("File:\n"); |
| 1574 | printf(" major brand: %s\n", four_cc); |
| 1575 | printf(" minor version: %x\n", file_type->GetMinorVersion()); |
| 1576 | break; |
| 1577 | |
| 1578 | case JSON_FORMAT: |
| 1579 | printf("\"file\":{\n"); |
| 1580 | printf(" \"major_brand\":\"%s\",\n", four_cc); |
| 1581 | printf(" \"minor_version\":%d,\n", file_type->GetMinorVersion()); |
| 1582 | break; |
| 1583 | } |
| 1584 | |
| 1585 | // compatible brands |
| 1586 | if (Options.format == JSON_FORMAT) printf(" \"compatible_brands\":["); |
| 1587 | const char* sep = ""; |
| 1588 | for (unsigned int i=0; i<file_type->GetCompatibleBrands().ItemCount(); i++) { |
| 1589 | AP4_UI32 cb = file_type->GetCompatibleBrands()[i]; |
| 1590 | if (cb == 0) continue; |
| 1591 | AP4_FormatFourChars(four_cc, cb); |
| 1592 | switch (Options.format) { |
| 1593 | case TEXT_FORMAT: |
| 1594 | printf(" compatible brand: %s\n", four_cc); |
| 1595 | break; |
| 1596 | |
| 1597 | case JSON_FORMAT: |
| 1598 | printf("%s\"%s\"", sep, four_cc); |
| 1599 | sep = ", "; |
| 1600 | break; |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | if (Options.format == JSON_FORMAT) { |
| 1605 | printf("],\n"); |
| 1606 | } |
| 1607 | |
| 1608 | // fast-start |
| 1609 | switch (Options.format) { |
| 1610 | case TEXT_FORMAT: |
| 1611 | printf(" fast start: %s\n\n", file.IsMoovBeforeMdat() ? "yes" : "no"); |
| 1612 | break; |
| 1613 | |
| 1614 | case JSON_FORMAT: |
| 1615 | printf(" \"fast_start\":%s\n},\n", file.IsMoovBeforeMdat() ? "true" : "false"); |
| 1616 | break; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | |
| 1621 | /*---------------------------------------------------------------------- |
| 1622 | | ShowTracks |
| 1623 | +---------------------------------------------------------------------*/ |
| 1624 | static void |
| 1625 | ShowTracks(AP4_Movie& movie, AP4_List<AP4_Track>& tracks, AP4_ByteStream& stream, bool show_samples, bool show_sample_data, bool verbose, bool fast) |
| 1626 | { |
| 1627 | if (Options.format == JSON_FORMAT) printf("\"tracks\":[\n"); |
| 1628 | int index=1; |
| 1629 | for (AP4_List<AP4_Track>::Item* track_item = tracks.FirstItem(); |
| 1630 | track_item; |
| 1631 | track_item = track_item->GetNext(), ++index) { |
| 1632 | if (Options.format == TEXT_FORMAT) { |
| 1633 | printf("Track %d:\n", index); |
| 1634 | } |
| 1635 | if (Options.format == JSON_FORMAT && index > 1) printf(",\n"); |
| 1636 | ShowTrackInfo(movie, *track_item->GetData(), stream, show_samples, show_sample_data, verbose, fast); |
| 1637 | } |
| 1638 | if (Options.format == JSON_FORMAT) printf("]\n"); |
| 1639 | } |
| 1640 | |
| 1641 | /*---------------------------------------------------------------------- |
| 1642 | | ShowMarlinTracks |
| 1643 | +---------------------------------------------------------------------*/ |
| 1644 | static void |
| 1645 | ShowMarlinTracks(AP4_File& file, AP4_ByteStream& stream, AP4_List<AP4_Track>& tracks, bool show_samples, bool show_sample_data, bool verbose, bool fast) |
| 1646 | { |
| 1647 | if (Options.format != TEXT_FORMAT) return; |
| 1648 | |
| 1649 | AP4_List<AP4_MarlinIpmpParser::SinfEntry> sinf_entries; |
| 1650 | AP4_Result result = AP4_MarlinIpmpParser::Parse(file, stream, sinf_entries); |
| 1651 | if (AP4_FAILED(result)) { |
| 1652 | printf("WARNING: cannot parse Marlin IPMP info\n"); |
| 1653 | ShowTracks(*file.GetMovie(), tracks, stream, show_samples, show_sample_data, verbose, fast); |
| 1654 | return; |
| 1655 | } |
| 1656 | int index=1; |
| 1657 | for (AP4_List<AP4_Track>::Item* track_item = tracks.FirstItem(); |
| 1658 | track_item; |
| 1659 | track_item = track_item->GetNext(), ++index) { |
| 1660 | printf("Track %d:\n", index); |
| 1661 | AP4_Track* track = track_item->GetData(); |
| 1662 | ShowTrackInfo(*file.GetMovie(), *track, stream, show_samples, show_sample_data, verbose, fast); |
| 1663 | |
| 1664 | for (AP4_List<AP4_MarlinIpmpParser::SinfEntry>::Item* sinf_entry_item = sinf_entries.FirstItem(); |
| 1665 | sinf_entry_item; |
| 1666 | sinf_entry_item = sinf_entry_item->GetNext()) { |
| 1667 | AP4_MarlinIpmpParser::SinfEntry* sinf_entry = sinf_entry_item->GetData(); |
| 1668 | if (sinf_entry->m_TrackId == track->GetId()) { |
| 1669 | printf(" [ENCRYPTED]\n"); |
| 1670 | if (sinf_entry->m_Sinf == NULL) { |
| 1671 | printf("WARNING: NULL sinf entry for track ID %d\n", track->GetId()); |
| 1672 | } else { |
| 1673 | AP4_ContainerAtom* schi = AP4_DYNAMIC_CAST(AP4_ContainerAtom, sinf_entry->m_Sinf->GetChild(AP4_ATOM_TYPE_SCHI)); |
| 1674 | AP4_SchmAtom* schm = AP4_DYNAMIC_CAST(AP4_SchmAtom, sinf_entry->m_Sinf->GetChild(AP4_ATOM_TYPE_SCHM)); |
| 1675 | if (schm && schi) { |
| 1676 | AP4_UI32 scheme_type = schm->GetSchemeType(); |
| 1677 | printf(" Scheme Type: %c%c%c%c\n", |
| 1678 | (char)((scheme_type>>24) & 0xFF), |
| 1679 | (char)((scheme_type>>16) & 0xFF), |
| 1680 | (char)((scheme_type>> 8) & 0xFF), |
| 1681 | (char)((scheme_type ) & 0xFF)); |
| 1682 | printf(" Scheme Version: %d\n", schm->GetSchemeVersion()); |
| 1683 | ShowProtectionSchemeInfo_Text(scheme_type, *schi, verbose); |
| 1684 | } else { |
| 1685 | if (schm == NULL) printf("WARNING: schm atom is NULL\n"); |
| 1686 | if (schi == NULL) printf("WARNING: schi atom is NULL\n"); |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | sinf_entries.DeleteReferences(); |
| 1693 | } |
| 1694 | |
| 1695 | /*---------------------------------------------------------------------- |
| 1696 | | ShowSampleLayout |
| 1697 | +---------------------------------------------------------------------*/ |
| 1698 | static void |
| 1699 | ShowSampleLayout(AP4_List<AP4_Track>& tracks, bool /* verbose */) |
| 1700 | { |
| 1701 | AP4_Array<int> cursors; |
| 1702 | cursors.SetItemCount(tracks.ItemCount()); |
| 1703 | for (unsigned int i=0; i<tracks.ItemCount(); i++) { |
| 1704 | cursors[i] = 0; |
| 1705 | } |
| 1706 | |
| 1707 | AP4_Sample sample; |
| 1708 | AP4_UI64 sample_offset = 0; |
| 1709 | AP4_UI32 sample_size = 0; |
| 1710 | AP4_UI64 sample_dts = 0; |
| 1711 | bool sample_is_sync = false; |
| 1712 | bool indicator = true; |
| 1713 | AP4_Track* previous_track = NULL; |
| 1714 | for (unsigned int i=0;;i++) { |
| 1715 | AP4_UI64 min_offset = (AP4_UI64)(-1); |
| 1716 | int chosen_index = -1; |
| 1717 | AP4_Track* chosen_track = NULL; |
| 1718 | AP4_Ordinal index = 0; |
| 1719 | for (AP4_List<AP4_Track>::Item* track_item = tracks.FirstItem(); |
| 1720 | track_item; |
| 1721 | track_item = track_item->GetNext()) { |
| 1722 | AP4_Track* track = track_item->GetData(); |
| 1723 | AP4_Result result = track->GetSample(cursors[index], sample); |
| 1724 | if (AP4_SUCCEEDED(result)) { |
| 1725 | if (sample.GetOffset() < min_offset) { |
| 1726 | chosen_index = index; |
| 1727 | chosen_track = track; |
| 1728 | sample_offset = sample.GetOffset(); |
| 1729 | sample_size = sample.GetSize(); |
| 1730 | sample_dts = sample.GetDts(); |
| 1731 | sample_is_sync = sample.IsSync(); |
| 1732 | min_offset = sample_offset; |
| 1733 | } |
| 1734 | } |
| 1735 | index++; |
| 1736 | } |
| 1737 | |
| 1738 | // stop if we've exhausted all samples |
| 1739 | if (chosen_index == -1) break; |
| 1740 | |
| 1741 | // update the cursor for the chosen track |
| 1742 | cursors[chosen_index] = cursors[chosen_index]+1; |
| 1743 | |
| 1744 | // see if we've changed tracks |
| 1745 | if (previous_track != chosen_track) { |
| 1746 | previous_track = chosen_track; |
| 1747 | indicator = !indicator; |
| 1748 | } |
| 1749 | |
| 1750 | // show the chosen track/sample |
| 1751 | char track_type = ' '; |
| 1752 | switch (chosen_track->GetType()) { |
| 1753 | case AP4_Track::TYPE_AUDIO: track_type = 'A'; break; |
| 1754 | case AP4_Track::TYPE_VIDEO: track_type = 'V'; break; |
| 1755 | case AP4_Track::TYPE_HINT: track_type = 'H'; break; |
| 1756 | case AP4_Track::TYPE_TEXT: track_type = 'T'; break; |
| 1757 | case AP4_Track::TYPE_SYSTEM: track_type = 'S'; break; |
| 1758 | case AP4_Track::TYPE_SUBTITLES: track_type = 'U'; break; |
| 1759 | default: track_type = ' '; break; |
| 1760 | } |
| 1761 | AP4_UI64 sample_dts_ms = AP4_ConvertTime(sample_dts, chosen_track->GetMediaTimeScale(), 1000); |
| 1762 | printf("%c %08d [%c] (%d)%c size=%6d, offset=%8lld, dts=%lld (%lld ms)\n", |
| 1763 | indicator?'|':' ', |
| 1764 | i, |
| 1765 | track_type, |
| 1766 | chosen_track->GetId(), |
| 1767 | sample_is_sync?'*':' ', |
| 1768 | sample_size, |
| 1769 | sample_offset, |
| 1770 | sample_dts, |
| 1771 | sample_dts_ms); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | /*---------------------------------------------------------------------- |
| 1776 | | ShowFragments_Text |
| 1777 | +---------------------------------------------------------------------*/ |
| 1778 | static void |
| 1779 | ShowFragments_Text(AP4_Movie& movie, bool verbose, bool show_sample_data, AP4_ByteStream* stream) |
| 1780 | { |
| 1781 | stream->Seek(0); |
| 1782 | AP4_LinearReader reader(movie, stream); |
| 1783 | AP4_List<AP4_Track>::Item* track_item = movie.GetTracks().FirstItem(); |
| 1784 | AP4_Array<unsigned int> counters; |
| 1785 | while (track_item) { |
| 1786 | reader.EnableTrack(track_item->GetData()->GetId()); |
| 1787 | track_item = track_item->GetNext(); |
| 1788 | counters.Append(0); |
| 1789 | } |
| 1790 | |
| 1791 | AP4_Sample sample; |
| 1792 | AP4_DataBuffer sample_data; |
| 1793 | AP4_UI32 prev_track_id = 0; |
| 1794 | unsigned int* counter = &counters[0]; |
| 1795 | for (;;) { |
| 1796 | AP4_UI32 track_id = 0; |
| 1797 | AP4_Result result = reader.ReadNextSample(sample, sample_data, track_id); |
| 1798 | if (AP4_SUCCEEDED(result)) { |
| 1799 | AP4_Track* track = movie.GetTrack(track_id); |
| 1800 | |
| 1801 | AP4_SampleDescription* sample_desc = track->GetSampleDescription(sample.GetDescriptionIndex()); |
| 1802 | AP4_AvcSampleDescription* avc_desc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sample_desc); |
| 1803 | |
| 1804 | if (track_id != prev_track_id) { |
| 1805 | printf("Track %d:\n", track_id); |
| 1806 | prev_track_id = track_id; |
| 1807 | |
| 1808 | // find the right counter for this track |
| 1809 | unsigned int counter_index = 0; |
| 1810 | for (AP4_List<AP4_Track>::Item* track_item = movie.GetTracks().FirstItem(); |
| 1811 | track_item; |
| 1812 | track_item = track_item->GetNext(), ++counter_index) { |
| 1813 | if (track_item->GetData()->GetId() == track_id) { |
| 1814 | if (counter_index < counters.ItemCount()) { |
| 1815 | counter = &counters[counter_index]; |
| 1816 | } |
| 1817 | break; |
| 1818 | } |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | ShowSample_Text(*track, sample, sample_data, *counter, verbose, show_sample_data, avc_desc); |
| 1823 | printf("\n"); |
| 1824 | |
| 1825 | ++*counter; |
| 1826 | } else { |
| 1827 | break; |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | /*---------------------------------------------------------------------- |
| 1833 | | main |
| 1834 | +---------------------------------------------------------------------*/ |
| 1835 | int |
| 1836 | main(int argc, char** argv) |
| 1837 | { |
| 1838 | if (argc < 2) { |
| 1839 | PrintUsageAndExit(); |
| 1840 | } |
| 1841 | Options.format = TEXT_FORMAT; |
| 1842 | const char* filename = NULL; |
| 1843 | bool verbose = false; |
| 1844 | bool show_samples = false; |
| 1845 | bool show_sample_data = false; |
| 1846 | bool show_layout = false; |
| 1847 | bool fast = false; |
| 1848 | |
| 1849 | while (char* arg = *++argv) { |
| 1850 | if (!strcmp(arg, "--verbose")) { |
| 1851 | verbose = true; |
| 1852 | } else if (!strcmp(arg, "--format")) { |
| 1853 | if (argv) { |
| 1854 | arg = *++argv; |
| 1855 | if (!strcmp(arg, "text")) { |
| 1856 | Options.format = TEXT_FORMAT; |
| 1857 | } else if (!strcmp(arg, "json")) { |
| 1858 | Options.format = JSON_FORMAT; |
| 1859 | } else { |
| 1860 | fprintf(stderr, "ERROR: unsupported format\n"); |
| 1861 | return 1; |
| 1862 | } |
| 1863 | } else { |
| 1864 | fprintf(stderr, "ERROR: missing argument after '--format' option\n"); |
| 1865 | return 1; |
| 1866 | } |
| 1867 | |
| 1868 | } else if (!strcmp(arg, "--fast")) { |
| 1869 | fast = true; |
| 1870 | } else if (!strcmp(arg, "--show-samples")) { |
| 1871 | show_samples = true; |
| 1872 | } else if (!strcmp(arg, "--show-sample-data")) { |
| 1873 | show_samples = true; |
| 1874 | show_sample_data = true; |
| 1875 | } else if (!strcmp(arg, "--show-layout")) { |
| 1876 | show_layout = true; |
| 1877 | } else { |
| 1878 | if (filename == NULL) { |
| 1879 | filename = arg; |
| 1880 | } else { |
| 1881 | fprintf(stderr, "ERROR: unexpected argument '%s'\n", arg); |
| 1882 | return 1; |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | if (filename == NULL) { |
| 1887 | fprintf(stderr, "ERROR: filename missing\n"); |
| 1888 | return 1; |
| 1889 | } |
| 1890 | |
| 1891 | AP4_ByteStream* input = NULL; |
| 1892 | AP4_Result result = AP4_FileByteStream::Create(filename, |
| 1893 | AP4_FileByteStream::STREAM_MODE_READ, |
| 1894 | input); |
| 1895 | if (AP4_FAILED(result)) { |
| 1896 | fprintf(stderr, "ERROR: cannot open input file %s (%d)\n", filename, result); |
| 1897 | return 1; |
| 1898 | } |
| 1899 | |
| 1900 | if (Options.format == JSON_FORMAT) printf("{\n"); |
| 1901 | |
| 1902 | AP4_File* file = new AP4_File(*input, true); |
| 1903 | ShowFileInfo(*file); |
| 1904 | |
| 1905 | AP4_Movie* movie = file->GetMovie(); |
| 1906 | AP4_FtypAtom* ftyp = file->GetFileType(); |
| 1907 | if (movie) { |
| 1908 | ShowMovieInfo(*movie); |
| 1909 | |
| 1910 | AP4_List<AP4_Track>& tracks = movie->GetTracks(); |
| 1911 | if (Options.format == TEXT_FORMAT) { |
| 1912 | printf("Found %d Tracks\n", tracks.ItemCount()); |
| 1913 | } |
| 1914 | |
| 1915 | if (ftyp && ftyp->GetMajorBrand() == AP4_MARLIN_BRAND_MGSV) { |
| 1916 | ShowMarlinTracks(*file, *input, tracks, show_samples, show_sample_data, verbose, fast); |
| 1917 | } else { |
| 1918 | ShowTracks(*movie, tracks, *input, show_samples, show_sample_data, verbose, fast); |
| 1919 | } |
| 1920 | |
| 1921 | if (show_layout) { |
| 1922 | ShowSampleLayout(tracks, verbose); |
| 1923 | } |
| 1924 | |
| 1925 | if (movie->HasFragments() && show_samples) { |
| 1926 | if (Options.format == TEXT_FORMAT) { |
| 1927 | ShowFragments_Text(*movie, verbose, show_sample_data, input); |
| 1928 | } |
| 1929 | } |
| 1930 | } else { |
| 1931 | // check if this is a DCF file |
| 1932 | if (ftyp && ftyp->GetMajorBrand() == AP4_OMA_DCF_BRAND_ODCF) { |
| 1933 | ShowDcfInfo(*file); |
| 1934 | } else { |
| 1935 | if (Options.format == TEXT_FORMAT) { |
| 1936 | printf("No movie found in the file\n"); |
| 1937 | } else { |
| 1938 | printf("\"movie\":{}\n"); |
| 1939 | } |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | if (Options.format == JSON_FORMAT) printf("}\n"); |
| 1944 | |
| 1945 | input->Release(); |
| 1946 | delete file; |
| 1947 | |
| 1948 | return 0; |
| 1949 | } |