From 16c65f4eda417fc0d861a57ec753ecb4781a860f Mon Sep 17 00:00:00 2001 From: maurj Date: Thu, 15 Feb 2007 18:06:22 +0000 Subject: [PATCH] Patched mp4v2 in mpeg4ip to make the "matrix" property of the tkhd atom in an mp4 container not be protected. (it's stored in the "reserved3" property of the tkhd atom). Added some new code to muxmp4.c to check for a job->pixel_ratio, and set the tkhd matrix to scale the width up by the right amount where one exists. This means that QuickTime now honours our anamorphic scaling! Updated a small error in deca52.c which wasn't critical, but was causing an error when compiling git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/0.8.0_beta2_5.1@353 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- contrib/patch-mpeg4ip.patch | 18 ++++++++++--- libmediafork/deca52.c | 2 +- libmediafork/muxmp4.c | 53 +++++++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/contrib/patch-mpeg4ip.patch b/contrib/patch-mpeg4ip.patch index 8d6d3ad90..8a55c5da2 100644 --- a/contrib/patch-mpeg4ip.patch +++ b/contrib/patch-mpeg4ip.patch @@ -1,13 +1,23 @@ diff -Naur mpeg4ip/lib/mp4v2/atom_tkhd.cpp mpeg4ip_patched/lib/mp4v2/atom_tkhd.cpp ---- mpeg4ip/lib/mp4v2/atom_tkhd.cpp 2003-11-20 00:46:11.000000000 +0100 -+++ mpeg4ip_patched/lib/mp4v2/atom_tkhd.cpp 2007-02-15 15:23:51.000000000 +0100 +--- mpeg4ip/lib/mp4v2/atom_tkhd.cpp 2003-11-19 23:46:11.000000000 +0000 ++++ mpeg4ip_patched/lib/mp4v2/atom_tkhd.cpp 2007-02-15 15:58:06.000000000 +0000 @@ -61,7 +61,8 @@ pProp->SetFixed16Format(); AddProperty(pProp); /* 8 */ - AddReserved("reserved3", 38); /* 9 */ -+ // maurj patch to allow PAR to work in QT -+ // AddReserved("reserved3", 38); /* 9 */ ++ /* patched by maurj to enable us to set the matrix for anamorphic display */ ++ AddProperty(new MP4BytesProperty("reserved3", 38)); /* 9 */ pProp = new MP4Float32Property("width"); pProp->SetFixed32Format(); +@@ -106,7 +107,8 @@ + m_pProperties[9]->SetReadOnly(false); + ((MP4BytesProperty*)m_pProperties[9])-> + SetValue(reserved3, sizeof(reserved3)); +- m_pProperties[9]->SetReadOnly(true); ++ /* patched by maurj to enable us to set the matrix for anamorphic display */ ++ /* m_pProperties[9]->SetReadOnly(true);*/ + } + + void MP4TkhdAtom::Read() diff --git a/libmediafork/deca52.c b/libmediafork/deca52.c index f2a52aa21..9d76097c9 100644 --- a/libmediafork/deca52.c +++ b/libmediafork/deca52.c @@ -74,7 +74,7 @@ int deca52Init( hb_work_object_t * w, hb_job_t * job ) and have turned on the "preserve 5.1" flag */ pv->flags_out = A52_3F2R | A52_LFE; } else if (job->channelsused == 1) { - /* we're going to be encoding to AAC, + /* we're going to be encoding to AAC, */ /* and want to keep the mono-ness of the source audio */ pv->flags_out = A52_MONO; } else if (job->channelsused == 2 && job->channels == 5 && job->lfechannels == 1) { diff --git a/libmediafork/muxmp4.c b/libmediafork/muxmp4.c index 5e23f3d89..de5bb5568 100644 --- a/libmediafork/muxmp4.c +++ b/libmediafork/muxmp4.c @@ -88,11 +88,12 @@ static int MP4Init( hb_mux_object_t * m ) MP4AddH264PictureParameterSet( m->file, mux_data->track, job->config.h264.pps, job->config.h264.pps_length ); - if( job->h264_level == 30) - { - hb_log("About to add iPod atom"); - AddIPodUUID(m->file, mux_data->track); - } + if( job->h264_level == 30) + { + hb_log("About to add iPod atom"); + AddIPodUUID(m->file, mux_data->track); + } + } else /* FFmpeg or XviD */ { @@ -106,6 +107,48 @@ static int MP4Init( hb_mux_object_t * m ) job->config.mpeg4.bytes, job->config.mpeg4.length ); } + /* apply the anamorphic transformation matrix if needed */ + + if( job->pixel_ratio ) { + + uint8_t* val; + uint8_t nval[38]; + uint32_t *ptr32 = (uint32_t*) (nval + 2); + uint32_t size; + + MP4GetBytesProperty(m->file, "moov.trak.tkhd.reserved3", &val, &size); + + if (size == 38) { + + memcpy(nval, val, size); + + float width, height; + float widthRatio; + width = job->pixel_aspect_width; + height = job->pixel_aspect_height; + widthRatio = (width / height) * 0x10000; + + uint32_t widthRatioInt; + widthRatioInt = (uint32_t)widthRatio; + +#ifdef WORDS_BIGENDIAN + ptr32[0] = widthRatioInt; +#else + /* we need to switch the endianness, as the file format expects big endian */ + ptr32[0] = ((widthRatioInt & 0x000000FF) << 24) + ((widthRatioInt & 0x0000FF00) << 8) + ((widthRatioInt & 0x00FF0000) >> 8) + ((widthRatioInt & 0xFF000000) >> 24); +#endif + + if(!MP4SetBytesProperty(m->file, "moov.trak.tkhd.reserved3", nval, size)) { + hb_log("Problem setting transform matrix"); + } + + } + + } + + /* end of transformation matrix */ + + for( i = 0; i < hb_list_count( title->list_audio ); i++ ) { audio = hb_list_item( title->list_audio, i ); -- 2.40.0