From adc34a0ac973d3abc17f8c2beaea322e980a1900 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 29 Sep 2015 14:39:59 +0200 Subject: [PATCH] Fixed aspect ratios in MP4. --- lib/mp4_generic.cpp | 38 ++++++++++++++++++-------------------- lib/mp4_generic.h | 8 ++++---- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/mp4_generic.cpp b/lib/mp4_generic.cpp index bb3b90a2..d4612b26 100644 --- a/lib/mp4_generic.cpp +++ b/lib/mp4_generic.cpp @@ -1934,8 +1934,8 @@ namespace MP4 { initialize(); setTrackID(trackId); setDuration(duration); - setWidth(width << 16); - setHeight(height << 16); + setWidth(width); + setHeight(height); } TKHD::TKHD(DTSC::Track & track, bool fragmented) { @@ -1946,8 +1946,8 @@ namespace MP4 { setDuration(track.lastms - track.firstms); } if (track.type == "video") { - setWidth(track.width << 16); - setHeight(track.height << 16); + setWidth(track.width); + setHeight(track.height); } } @@ -2102,35 +2102,35 @@ namespace MP4 { return getInt32(offset + index * 4); } - void TKHD::setWidth(uint32_t newWidth) { + void TKHD::setWidth(double newWidth) { if (getVersion() == 0) { - setInt32(newWidth, 76); + setInt32(newWidth * 65536.0, 76); } else { - setInt32(newWidth, 88); + setInt32(newWidth * 65536.0, 88); } } - uint32_t TKHD::getWidth() { + double TKHD::getWidth() { if (getVersion() == 0) { - return getInt32(76); + return getInt32(76) / 65536.0; } else { - return getInt32(88); + return getInt32(88) / 65536.0; } } - void TKHD::setHeight(uint32_t newHeight) { + void TKHD::setHeight(double newHeight) { if (getVersion() == 0) { - setInt32(newHeight, 80); + setInt32(newHeight * 65536.0, 80); } else { - setInt32(newHeight, 92); + setInt32(newHeight * 65536.0, 92); } } - uint32_t TKHD::getHeight() { + double TKHD::getHeight() { if (getVersion() == 0) { - return getInt32(80); + return getInt32(80) / 65536.0; } else { - return getInt32(92); + return getInt32(92) / 65536.0; } } @@ -2153,8 +2153,8 @@ namespace MP4 { } } r << std::endl; - r << std::string(indent + 1, ' ') << "Width: " << (getWidth() >> 16) << "." << (getWidth() & 0xFFFF) << std::endl; - r << std::string(indent + 1, ' ') << "Height: " << (getHeight() >> 16) << "." << (getHeight() & 0xFFFF) << std::endl; + r << std::string(indent + 1, ' ') << "Width: " << getWidth() << std::endl; + r << std::string(indent + 1, ' ') << "Height: " << getHeight() << std::endl; return r.str(); } @@ -2738,8 +2738,6 @@ namespace MP4 { avccBox.setPayload(track.init); setCLAP(avccBox); } - MP4::PASP paspBox; - setPASP(paspBox); } void VisualSampleEntry::initialize(){ diff --git a/lib/mp4_generic.h b/lib/mp4_generic.h index acdc52b4..ad66fcf6 100644 --- a/lib/mp4_generic.h +++ b/lib/mp4_generic.h @@ -443,10 +443,10 @@ namespace MP4 { void setMatrix(int32_t newMatrix, size_t index); int32_t getMatrix(size_t index); - void setWidth(uint32_t newWidth); - uint32_t getWidth(); - void setHeight(uint32_t newHeight); - uint32_t getHeight(); + void setWidth(double newWidth); + double getWidth(); + void setHeight(double newHeight); + double getHeight(); std::string toPrettyString(uint32_t indent = 0); protected: void initialize();