From 82e6e07a812ebe2ca65c3ee62c13e56b1be6e4d4 Mon Sep 17 00:00:00 2001 From: Oswald de Bruin Date: Mon, 3 Jun 2013 10:32:44 +0200 Subject: [PATCH] Last MP4 edits --- lib/mp4.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- lib/mp4.h | 14 ++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/mp4.cpp b/lib/mp4.cpp index 20e7b7dc..821351fb 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -247,9 +247,15 @@ namespace MP4 { case 0x6D703461: return ((MP4A*)this)->toPrettyString(indent); break; + case 0x61616320: + return ((AAC*)this)->toPrettyString(indent); + break; case 0x61766331: return ((AVC1*)this)->toPrettyString(indent); break; + case 0x68323634: + return ((H264*)this)->toPrettyString(indent); + break; case 0x65647473: return ((EDTS*)this)->toPrettyString(indent); break; @@ -3661,6 +3667,7 @@ namespace MP4 { void STSC::setSTSCEntry(STSCEntry newSTSCEntry, uint32_t no){ if(no + 1 > getEntryCount()){ + setEntryCount(no+1); for (int i = getEntryCount(); i < no; i++){ setInt64(0, 8 + (i * 12));//filling up undefined entries of 64 bits setInt32(0, 8 + (i * 12) + 8); @@ -3716,6 +3723,7 @@ namespace MP4 { void STCO::setChunkOffset(uint32_t newChunkOffset, uint32_t no){ if (no + 1 > getEntryCount()){ + setEntryCount(no+1); for (int i = getEntryCount(); i < no; i++){ setInt32(0, 8 + i * 4);//filling undefined entries } @@ -3924,6 +3932,15 @@ namespace MP4 { VisualSampleEntry::VisualSampleEntry(){ memcpy(data + 4, "erro", 4); + setHorizResolution(0x00480000); + setVertResolution(0x00480000); + setFrameCount(1); + setCompressorName(""); + setDepth(0x0018); + } + + void VisualSampleEntry::setCodec(char* newCodec){ + memcpy(data + 4, newCodec, 4); } void VisualSampleEntry::setWidth(uint16_t newWidth){ @@ -3967,6 +3984,7 @@ namespace MP4 { } void VisualSampleEntry::setCompressorName(std::string newCompressorName){ + newCompressorName.resize(32, ' '); setString(newCompressorName,42); } @@ -4036,6 +4054,13 @@ namespace MP4 { AudioSampleEntry::AudioSampleEntry(){ memcpy(data + 4, "erro", 4); + setChannelCount(2); + setSampleSize(16); + setSampleRate(44100); + } + + void AudioSampleEntry::setCodec(char* newCodec){ + memcpy(data + 4, newCodec, 4); } void AudioSampleEntry::setChannelCount(uint16_t newChannelCount){ @@ -4086,7 +4111,15 @@ namespace MP4 { } std::string MP4A::toPrettyString(uint32_t indent){ - return toPrettyAudioString(indent, "[mp4a] MPEG 4 Audio"); + return toPrettyAudioString(indent, "[mp4a] MPEG-4 Audio"); + } + + AAC::AAC(){ + memcpy(data + 4, "aac ", 4); + } + + std::string AAC::toPrettyString(uint32_t indent){ + return toPrettyAudioString(indent, "[aac ] Advanced Audio Codec"); } AVC1::AVC1(){ @@ -4097,6 +4130,14 @@ namespace MP4 { return toPrettyVisualString(indent, "[avc1] Advanced Video Codec 1"); } + H264::H264(){ + memcpy(data + 4, "h264", 4); + } + + std::string H264::toPrettyString(uint32_t indent){ + return toPrettyVisualString(indent, "[h264] H.264/MPEG-4 AVC"); + } + STSD::STSD(char v, uint32_t f){ memcpy(data + 4, "stsd", 4); setVersion(v); diff --git a/lib/mp4.h b/lib/mp4.h index 3bd29efa..d819e4a6 100644 --- a/lib/mp4.h +++ b/lib/mp4.h @@ -739,6 +739,7 @@ namespace MP4 { ///\todo set default values public: VisualSampleEntry(); + void setCodec(char* newCodec); void setWidth(uint16_t newWidth); uint16_t getWidth(); void setHeight(uint16_t newHeight); @@ -762,6 +763,7 @@ namespace MP4 { public: ///\todo set default values AudioSampleEntry(); + void setCodec(char* newCodec); void setChannelCount(uint16_t newChannelCount); uint16_t getChannelCount(); void setSampleSize(uint16_t newSampleSize); @@ -779,11 +781,23 @@ namespace MP4 { std::string toPrettyString(uint32_t indent = 0); }; + class AAC: public AudioSampleEntry{ + public: + AAC(); + std::string toPrettyString(uint32_t indent = 0); + }; + class AVC1: public VisualSampleEntry{ public: AVC1(); std::string toPrettyString(uint32_t indent = 0); }; + + class H264: public VisualSampleEntry{ + public: + H264(); + std::string toPrettyString(uint32_t indent = 0); + }; class STSD: public fullBox{ public: