OSDN Git Service

Optimize MP4 files for HTTP streaming (on the CLI it's -O or --optimize).
authorjbrjake <jbrjake@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 21 Nov 2007 17:41:33 +0000 (17:41 +0000)
committerjbrjake <jbrjake@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 21 Nov 2007 17:41:33 +0000 (17:41 +0000)
Has mpeg4ip run a second pass after muxing is complete, to move the MOOV atom to the beginning of the file. To get this to work, I had to replace a patch from Perian, which has written the avc1 "Compressor Name" in the Pascal string style QuickTime expects. Unfortunately, that patch left mpeg4ip unable to parse its own output, when muxing x264 video. Instead, now the Compressor Name is a blank string, and QuickTime substitutes "H.264" for it.

NOTE: This is *not* hinting for RTP streaming, just shuffling the container around so it starts playing faster over the web.

git-svn-id: svn://localhost/HandBrake/trunk@1074 b64f7644-9d1e-0410-96f1-a4d463321fa5

contrib/Jamfile
contrib/patch-mpeg4ip-no_compressor_name.patch [new file with mode: 0644]
libhb/common.h
libhb/muxmp4.c
test/test.c

index 546e482..f597eac 100644 (file)
@@ -221,7 +221,7 @@ if $(OS) != CYGWIN
         cd `dirname $(>)` && CONTRIB=`pwd` &&
         rm -rf mpeg4ip && (gzip -dc mpeg4ip.tar.gz | tar xf - ) && 
         cd mpeg4ip &&
-        $(PATCH) -p1 < ../patch-mpeg4ip.patch && $(PATCH) -p0 < ../patch-mpeg4ip-pascal-str.patch &&
+        $(PATCH) -p1 < ../patch-mpeg4ip.patch  && $(PATCH) -p0 < ../patch-mpeg4ip-no_compressor_name.patch &&
         ./bootstrap --cache-file=$CONTRIB/config.cache --disable-mp3lame --disable-faac --disable-x264 --disable-server --disable-player &&
         $(MAKE) -C lib/mp4v2 libmp4v2.la && cp lib/mp4v2/.libs/libmp4v2.a $CONTRIB/lib &&
         cp mpeg4ip_config.h include/mpeg4ip.h include/mpeg4ip_version.h \
@@ -236,7 +236,7 @@ else
         cd `dirname $(>)` && CONTRIB=`pwd` &&
         rm -rf mpeg4ip && (gzip -dc mpeg4ip.tar.gz | tar xf - ) && 
         cd mpeg4ip &&
-        $(PATCH) -p1 < ../patch-mpeg4ip.patch && $(PATCH) -p1 < ../patch_mpeg4ip_cygwin.patch && $(PATCH) -p0 < ../patch-mpeg4ip-pascal-str.patch &&
+        $(PATCH) -p1 < ../patch-mpeg4ip.patch && $(PATCH) -p0 < ../patch-mpeg4ip-no_compressor_name.patch && $(PATCH) -p1 < ../patch_mpeg4ip_cygwin.patch &&
         ./bootstrap --cache-file=$CONTRIB/config.cache --disable-mp3lame --disable-faac --disable-x264 --disable-server --disable-player &&
         $(MAKE) -C lib/mp4v2 libmp4v2.la && cp lib/mp4v2/.libs/libmp4v2.a $CONTRIB/lib &&
         cp mpeg4ip_config.h include/mpeg4ip.h include/mpeg4ip_version.h \
diff --git a/contrib/patch-mpeg4ip-no_compressor_name.patch b/contrib/patch-mpeg4ip-no_compressor_name.patch
new file mode 100644 (file)
index 0000000..652711c
--- /dev/null
@@ -0,0 +1,11 @@
+--- lib/mp4v2/atom_avc1.cpp.bak.cpp    2004-07-13 17:07:50.000000000 -0400
++++ lib/mp4v2/atom_avc1.cpp    2007-11-19 13:44:21.000000000 -0500
+@@ -41,7 +41,7 @@
+       MP4StringProperty* pProp = 
+               new MP4StringProperty("compressorName");
+       pProp->SetFixedLength(32);
+-      pProp->SetValue("AVC Coding");
++      pProp->SetValue("");
+       AddProperty(pProp); /* 6 */
+       AddReserved("reserved4", 4); /* 7 */
index 8a45d7e..1f16366 100644 (file)
@@ -259,7 +259,7 @@ struct hb_job_s
 
     /* Allow MP4 files > 4 gigs */
     int             largeFileSize;
-    
+    int             mp4_optimize;
 
     int indepth_scan;
     hb_subtitle_t ** select_subtitle;
index d279667..0760aac 100644 (file)
@@ -323,6 +323,9 @@ static int MP4Init( hb_mux_object_t * m )
         /* Set the correct number of channels for this track */
         reserved2[9] = (u_int8_t)HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->amixdown);
         MP4SetTrackBytesProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.mp4a.reserved2", reserved2, sizeof(reserved2));
+
+        /* If we ever upgrade mpeg4ip, the line above should be replaced with the line below.*/
+//        MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.mp4a.channels",  (u_int16_t)HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->amixdown));
         
         /* store a reference to the first audio track,
         so we can use it to feed the chapter text track's sample rate */
@@ -464,11 +467,6 @@ static int MP4End( hb_mux_object_t * m )
         free(sample);
     }
     
-#if 0
-    hb_job_t * job = m->job;
-    char filename[1024]; memset( filename, 0, 1024 );
-#endif
-
     if (job->areBframes)
     /* Walk the entire video sample table and find the minumum ctts value. */
     {
@@ -499,13 +497,15 @@ static int MP4End( hb_mux_object_t * m )
 
     MP4Close( m->file );
 
-#if 0
-    hb_log( "muxmp4: optimizing file" );
-    snprintf( filename, 1024, "%s.tmp", job->file );
-    MP4Optimize( job->file, filename, MP4_DETAILS_ERROR );
-    remove( job->file );
-    rename( filename, job->file );
-#endif
+    if ( job->mp4_optimize )
+    {
+        hb_log( "muxmp4: optimizing file" );
+        char filename[1024]; memset( filename, 0, 1024 );
+        snprintf( filename, 1024, "%s.tmp", job->file );
+        MP4Optimize( job->file, filename, MP4_DETAILS_ERROR );
+        remove( job->file );
+        rename( filename, job->file );
+    }
 
     return 0;
 }
index 5224691..6cd7005 100644 (file)
@@ -70,6 +70,7 @@ static int    largeFileSize = 0;
 static int    preset        = 0;
 static char * preset_name   = 0;
 static int    vfr           = 0;
+static int    mp4_optimize  = 0;
 
 /* Exit cleanly on Ctrl-C */
 static volatile int die = 0;
@@ -848,6 +849,10 @@ static int HandleEvents( hb_handle_t * h )
             {
                 job->largeFileSize = 1;
             }
+            if ( mp4_optimize )
+            {
+                job->mp4_optimize = 1;
+            }
             
             job->file = strdup( output );
 
@@ -1089,6 +1094,7 @@ static void ShowHelp()
     "                            autodetected from file name)\n"
     "    -4, --large-file        Use 64-bit mp4 files that can hold more than\n"
     "                            4 GB. Note: Breaks iPod, @TV, PS3 compatibility.\n"""
+    "    -O, --optimize          Optimize mp4 files for HTTP streaming\n"
     "\n"
        
        "### Picture Settings---------------------------------------------------------\n\n"
@@ -1246,6 +1252,7 @@ static int ParseOptions( int argc, char ** argv )
             { "input",       required_argument, NULL,    'i' },
             { "output",      required_argument, NULL,    'o' },
             { "large-file",  no_argument,       NULL,    '4' },
+            { "optimize",    no_argument,       NULL,    'O' },
             
             { "title",       required_argument, NULL,    't' },
             { "longest",     no_argument,       NULL,    'L' },
@@ -1294,7 +1301,7 @@ static int ParseOptions( int argc, char ** argv )
         int c;
 
         c = getopt_long( argc, argv,
-                         "hvuC:f:4i:o:t:Lc:ma:6:s:UFN:e:E:2d789gpP::w:l:n:b:q:S:B:r:R:Qx:TY:X:VZ:z",
+                         "hvuC:f:4i:o:t:Lc:ma:6:s:UFN:e:E:2d789gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:VZ:z",
                          long_options, &option_index );
         if( c < 0 )
         {
@@ -1336,6 +1343,10 @@ static int ParseOptions( int argc, char ** argv )
             case '4':
                 largeFileSize = 1;
                 break;
+            case 'O':
+                mp4_optimize = 1;
+                break;
+
             case 't':
                 titleindex = atoi( optarg );
                 break;