OSDN Git Service

- Fixed the size for tx3g samples in muxmp4.c I forgot to add the size of the string...
authorritsuka <ritsuka@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 8 May 2009 16:03:21 +0000 (16:03 +0000)
committerritsuka <ritsuka@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 8 May 2009 16:03:21 +0000 (16:03 +0000)
- Small fixes in deccc608sub.c, trim null characters away.
- Moved the duration time from hb_mux_object_s to hb_mux_data_s so that multiple subtitle tracks can be muxed with interference.
- Uses par to calculate the subtitle track width so that It will be the same as the video track.

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

libhb/deccc608sub.c
libhb/muxmp4.c

index 5cfe238..87899b4 100644 (file)
@@ -535,6 +535,8 @@ void get_char_in_unicode (unsigned char *buffer, unsigned char c)
 
 int get_char_in_utf_8 (unsigned char *buffer, unsigned char c) // Returns number of bytes used
 {
+    if (c==0x00)
+        return 0;
     if (c<0x80) // Regular line-21 character set, mostly ASCII except these exceptions
     {
         switch (c)
@@ -1646,7 +1648,7 @@ int write_cc_buffer_as_srt (struct eia608_screen *data, struct s_write *wb)
     }
     if (wb->enc_buffer_used)
     {
-        hb_buffer_t *buffer = hb_buffer_init( wb->enc_buffer_used + 2 );
+        hb_buffer_t *buffer = hb_buffer_init( wb->enc_buffer_used + 1 );
         buffer->start = ms_start;
         buffer->stop = ms_end;
         memcpy( buffer->data, wb->enc_buffer, wb->enc_buffer_used + 1 );
index f6c4622..dadfcdd 100644 (file)
@@ -23,8 +23,6 @@ struct hb_mux_object_s
     // bias to keep render offsets in ctts atom positive (set up by encx264)
     int64_t init_delay;
 
-    uint64_t sum_sub_duration; // sum of subtitle frame durations so far
-
     /* Chapter state information for muxing */
     MP4TrackId chapter_track;
     int current_chapter;
@@ -33,9 +31,11 @@ struct hb_mux_object_s
 
 struct hb_mux_data_s
 {
-    MP4TrackId track;
-    uint8_t    subtitle;
-    int        sub_format;
+    MP4TrackId  track;
+    uint8_t     subtitle;
+    int         sub_format;
+
+    uint64_t    sum_dur; // sum of the frame durations so far
 };
 
 /* Tune video track chunk duration.
@@ -410,6 +410,12 @@ static int MP4Init( hb_mux_object_t * m )
         if( subtitle && subtitle->format == TEXTSUB && 
             subtitle->dest == PASSTHRUSUB )
         {
+            uint64_t width, height = 60;
+            if( job->anamorphic.mode )
+                width = job->width * ( (float) job->anamorphic.par_width / job->anamorphic.par_height );
+            else
+                width = job->width;
+
             mux_data = calloc(1, sizeof( hb_mux_data_t ) );
             subtitle->mux_data = mux_data;
             mux_data->subtitle = 1;
@@ -422,12 +428,11 @@ static int MP4Init( hb_mux_object_t * m )
             MP4TuneTrackDurationPerChunk( m, mux_data->track );
 
             const uint8_t textColor[4] = { 255,255,255,255 };
-            uint64_t subHeight = 60;
 
             MP4SetTrackIntegerProperty(m->file, mux_data->track, "tkhd.alternate_group", 2);
 
-            MP4SetTrackFloatProperty(m->file, mux_data->track, "tkhd.width", job->width);
-            MP4SetTrackFloatProperty(m->file, mux_data->track, "tkhd.height", subHeight);
+            MP4SetTrackFloatProperty(m->file, mux_data->track, "tkhd.width", width);
+            MP4SetTrackFloatProperty(m->file, mux_data->track, "tkhd.height", height);
 
             MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.dataReferenceIndex", 1);
             MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.horizontalJustification", 1);
@@ -435,8 +440,8 @@ static int MP4Init( hb_mux_object_t * m )
 
             MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.bgColorAlpha", 255);
 
-            MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", subHeight);
-            MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", job->width);
+            MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", height);
+            MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", width);
 
             MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.fontID", 1);
             MP4SetTrackIntegerProperty(m->file, mux_data->track, "mdia.minf.stbl.stsd.tx3g.fontSize", 24);
@@ -455,7 +460,7 @@ static int MP4Init( hb_mux_object_t * m )
             MP4GetTrackBytesProperty(m->file, mux_data->track, "tkhd.matrix", &val, &size);
             memcpy(nval, val, size);
 
-            const uint32_t ytranslation = (job->height - subHeight) * 0x10000;
+            const uint32_t ytranslation = (job->height - height) * 0x10000;
                 
 #ifdef WORDS_BIGENDIAN
             ptr32[7] = ytranslation;
@@ -643,21 +648,21 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
         if( mux_data->sub_format == TEXTSUB )
         {
             /* Write an empty sample */
-            if ( m->sum_sub_duration < buf->start )
+            if ( mux_data->sum_dur < buf->start )
             {
                 uint8_t empty[2] = {0,0};
                 if( !MP4WriteSample( m->file,
                                     mux_data->track,
                                     empty,
                                     2,
-                                    buf->start - m->sum_sub_duration,
+                                    buf->start - mux_data->sum_dur,
                                     0,
                                     1 ))
                 {
                     hb_error("Failed to write to output file, disk full?");
                     *job->die = 1;
                 } 
-                m->sum_sub_duration += buf->start - m->sum_sub_duration;
+                mux_data->sum_dur += buf->start - mux_data->sum_dur;
             }
 
             /* Write the subtitle sample */
@@ -669,7 +674,7 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
             if( !MP4WriteSample( m->file,
                                  mux_data->track,
                                  buffer,
-                                 buf->size,
+                                 buf->size + 2,
                                  buf->stop - buf->start,
                                  0,
                                  1 ))
@@ -678,10 +683,10 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
                 *job->die = 1;
             }
 
-            m->sum_sub_duration += (buf->stop - buf->start);
+            mux_data->sum_dur += (buf->stop - buf->start);
             hb_deep_log(3, "MuxMP4:Sub:%fs:%lld:%lld:%lld: %s", (float)buf->start / 90000, buf->start, buf->stop, 
                    (buf->stop - buf->start), buf->data);
-            hb_deep_log(3, "MuxMP4:Total time elapsed:%lld", m->sum_sub_duration);
+            hb_deep_log(3, "MuxMP4:Total time elapsed:%lld", mux_data->sum_dur);
         }
     }
     else