]> granicus.if.org Git - handbrake/commitdiff
Patched mp4v2 in mpeg4ip to make the "matrix" property of the tkhd atom in an mp4...
authormaurj <handbrake@maurj.com>
Thu, 15 Feb 2007 18:06:22 +0000 (18:06 +0000)
committermaurj <handbrake@maurj.com>
Thu, 15 Feb 2007 18:06:22 +0000 (18:06 +0000)
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
libmediafork/deca52.c
libmediafork/muxmp4.c

index 8d6d3ad90c233a9e7bf413dd18665bfadb3d677e..8a55c5da21b34353d302d4c3a31ee29faa19ec7c 100644 (file)
@@ -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() 
index f2a52aa218b32259308244f413a873855902f788..9d76097c99dcd6e55bc174a28d0d0a41a68adb82 100644 (file)
@@ -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) {
index 5e23f3d89fbc2bebf902ef93d18ee9733cc90005..de5bb55687075422d18eddfd47137ef78325a832 100644 (file)
@@ -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 );