libhb: if no source chapter name information is available, set default chapters names...
authorRodeo <tdskywalker@gmail.com>
Thu, 3 May 2012 16:04:28 +0000 (16:04 +0000)
committerRodeo <tdskywalker@gmail.com>
Thu, 3 May 2012 16:04:28 +0000 (16:04 +0000)
Standardize calculation of chapter->hours, chapter->minutes and chapter->seconds across all sources.

Get rid of an unused variable in libhb/dvd.c

Ignore chapter names set by MakeMKV. "Chapter 1" is just as good as, if not better than "Chapter 01" or even "Chapter 00".

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4636 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/bd.c
libhb/decmetadata.c
libhb/dvd.c
libhb/dvdnav.c
libhb/stream.c
macosx/Controller.m
test/test.c

index bb051115a2e7c46182a588a30b71397b25ffec80..f980dac03bc54b2f7de1fb02840be46619f20925 100644 (file)
@@ -457,14 +457,15 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration )
         chapter = calloc( sizeof( hb_chapter_t ), 1 );
 
         chapter->index = ii + 1;
+        sprintf( chapter->title, "Chapter %d", chapter->index );
+
         chapter->duration = ti->chapters[ii].duration;
         chapter->block_start = ti->chapters[ii].offset;
 
-        int seconds;
-        seconds            = ( chapter->duration + 45000 ) / 90000;
-        chapter->hours     = seconds / 3600;
-        chapter->minutes   = ( seconds % 3600 ) / 60;
-        chapter->seconds   = seconds % 60;
+        int seconds      = ( chapter->duration + 45000 ) / 90000;
+        chapter->hours   = ( seconds / 3600 );
+        chapter->minutes = ( seconds % 3600 ) / 60;
+        chapter->seconds = ( seconds % 60 );
 
         hb_log( "bd: chap %d packet=%"PRIu64", %"PRId64" ms",
                 chapter->index,
index bd848a95ad4f054bfccae95925aabfe0dc3c8ce7..01f1b0decab17707392ac99797ca712322c5e82c 100644 (file)
@@ -80,13 +80,25 @@ static void decmp4metadata( hb_title_t *title )
                 chapter = calloc( sizeof( hb_chapter_t ), 1 );
                 chapter->index = i;
                 chapter->duration = chapter_list[i-1].duration * 90;
-                chapter->hours    = chapter->duration / 90000 / 3600;
-                chapter->minutes  = ( ( chapter->duration / 90000 ) % 3600 ) / 60;
-                chapter->seconds  = ( chapter->duration / 90000 ) % 60;
-                strcpy( chapter->title, chapter_list[i-1].title );
-                hb_deep_log( 2, "Added chapter %i, name='%s', dur=%"PRId64", (%02i:%02i:%02i)", chapter->index, chapter->title, 
-                       chapter->duration, chapter->hours, 
-                       chapter->minutes, chapter->seconds);
+
+                int seconds      = ( chapter->duration + 45000 ) / 90000;
+                chapter->hours   = ( seconds / 3600 );
+                chapter->minutes = ( seconds % 3600 ) / 60;
+                chapter->seconds = ( seconds % 60 );
+
+                if( chapter_list[i-1].title )
+                {
+                    strcpy( chapter->title, chapter_list[i-1].title );
+                }
+                else
+                {
+                    sprintf( chapter->title, "Chapter %d", chapter->index );
+                }
+
+                hb_deep_log( 2, "Added chapter %i, name='%s', dur=%"PRId64", (%02i:%02i:%02i)",
+                             chapter->index, chapter->title, chapter->duration,
+                             chapter->hours, chapter->minutes, chapter->seconds);
+
                 hb_list_add( title->list_chapter, chapter );
                 i++;
             }
index 5dbe85072a036e92cd583ff4927f2c95e1ce0f89..f4260d5fcabfbec73e910fd328bc6082896859d8 100644 (file)
@@ -170,7 +170,6 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
     ifo_handle_t * vts = NULL;
     int            pgc_id, pgn, i;
     hb_chapter_t * chapter;
-    int            c;
     uint64_t       duration;
     float          duration_correction;
     unsigned char  unused[1024];
@@ -562,12 +561,14 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
     /* Chapters */
     hb_log( "scan: title %d has %d chapters", t,
             vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts );
-    for( i = 0, c = 1;
+    for( i = 0;
          i < vts->vts_ptt_srpt->title[title->ttn-1].nr_of_ptts; i++ )
     {
         chapter = calloc( sizeof( hb_chapter_t ), 1 );
+
         /* remember the on-disc chapter number */
         chapter->index = i + 1;
+        sprintf( chapter->title, "Chapter %d", chapter->index );
 
         pgc_id = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgcn;
         pgn    = vts->vts_ptt_srpt->title[title->ttn-1].ptt[i].pgn;
@@ -605,8 +606,8 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
             FindNextCell( d );
             d->cell_cur = d->cell_next;
         }
+
         hb_list_add( title->list_chapter, chapter );
-        c++;
     }
 
     /* The durations we get for chapters aren't precise. Scale them so
@@ -620,13 +621,13 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
     duration_correction = (float) title->duration / (float) duration;
     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
     {
-        int seconds;
-        chapter            = hb_list_item( title->list_chapter, i );
-        chapter->duration  = duration_correction * chapter->duration;
-        seconds            = ( chapter->duration + 45000 ) / 90000;
-        chapter->hours     = seconds / 3600;
-        chapter->minutes   = ( seconds % 3600 ) / 60;
-        chapter->seconds   = seconds % 60;
+        chapter           = hb_list_item( title->list_chapter, i );
+        chapter->duration = duration_correction * chapter->duration;
+
+        int seconds       = ( chapter->duration + 45000 ) / 90000;
+        chapter->hours    = ( seconds / 3600 );
+        chapter->minutes  = ( seconds % 3600 ) / 60;
+        chapter->seconds  = ( seconds % 60 );
 
         hb_log( "scan: chap %d c=%d->%d, b=%"PRIu64"->%"PRIu64" (%"PRIu64"), %"PRId64" ms",
                 chapter->index, chapter->cell_start, chapter->cell_end,
index 8b356e188d896f20e7a06c9fd59a315ba7839e4f..e40a02f05a5ea8be45f4fa38fc411677de425cb8 100644 (file)
@@ -721,9 +721,11 @@ static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * e, int t, uint64_t min_dura
         {
             chapter = calloc( sizeof( hb_chapter_t ), 1 );
 
-            chapter->index = c + 1;
             chapter->pgcn = pgcn;
             chapter->pgn = i;
+            chapter->index = c + 1;
+            sprintf( chapter->title, "Chapter %d", chapter->index );
+
             hb_list_add( title->list_chapter, chapter );
             c++;
         }
@@ -780,13 +782,13 @@ static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * e, int t, uint64_t min_dura
     duration_correction = (float) title->duration / (float) duration;
     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )
     {
-        int seconds;
-        chapter            = hb_list_item( title->list_chapter, i );
-        chapter->duration  = duration_correction * chapter->duration;
-        seconds            = ( chapter->duration + 45000 ) / 90000;
-        chapter->hours     = seconds / 3600;
-        chapter->minutes   = ( seconds % 3600 ) / 60;
-        chapter->seconds   = seconds % 60;
+        chapter           = hb_list_item( title->list_chapter, i );
+        chapter->duration = duration_correction * chapter->duration;
+
+        int seconds       = ( chapter->duration + 45000 ) / 90000;
+        chapter->hours    = ( seconds / 3600 );
+        chapter->minutes  = ( seconds % 3600 ) / 60;
+        chapter->seconds  = ( seconds % 60 );
 
         hb_log( "scan: chap %d c=%d->%d, b=%"PRIu64"->%"PRIu64" (%"PRIu64"), %"PRId64" ms",
                 chapter->index, chapter->cell_start, chapter->cell_end,
index 7961eebfbe5ff913ffaf77d2e65d12f5600b64f3..48b1e9742729416e01f99ca32af844372c46dfe2 100644 (file)
@@ -5501,15 +5501,29 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream, hb_title_t *title )
                 chapter->index    = i+1;
                 chapter->duration = ( m->end / ( (double) m->time_base.num * m->time_base.den ) ) * 90000  - duration_sum;
                 duration_sum     += chapter->duration;
-                chapter->hours    = chapter->duration / 90000 / 3600;
-                chapter->minutes  = ( ( chapter->duration / 90000 ) % 3600 ) / 60;
-                chapter->seconds  = ( chapter->duration / 90000 ) % 60;
+
+                int seconds      = ( chapter->duration + 45000 ) / 90000;
+                chapter->hours   = ( seconds / 3600 );
+                chapter->minutes = ( seconds % 3600 ) / 60;
+                chapter->seconds = ( seconds % 60 );
+
                 tag = av_dict_get( m->metadata, "title", NULL, 0 );
-                strcpy( chapter->title, tag ? tag->value : "" );
+                /* Ignore generic chapter names set by MakeMKV ("Chapter 00" etc.).
+                 * Our default chapter names are better. */
+                if( tag && tag->value &&
+                    ( strncmp( "Chapter ", tag->value, 8 ) || strlen( tag->value ) > 11 ) )
+                {
+                    strcpy( chapter->title, tag->value );
+                }
+                else
+                {
+                    sprintf( chapter->title, "Chapter %d", chapter->index );
+                }
+
                 hb_deep_log( 2, "Added chapter %i, name='%s', dur=%"PRIu64", (%02i:%02i:%02i)",
-                            chapter->index, chapter->title,
-                            chapter->duration, chapter->hours,
-                            chapter->minutes, chapter->seconds );
+                             chapter->index, chapter->title, chapter->duration,
+                             chapter->hours, chapter->minutes, chapter->seconds );
+
                 hb_list_add( title->list_chapter, chapter );
             }
     }
index 31f63808d4e3e67a04b63d4a0452f66b15a9b759..e3c85dffaf8acb3232f0b3ae8b327bceb5e15e31 100644 (file)
@@ -2331,7 +2331,7 @@ fWorkingCount = 0;
         hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
         if( chapter != NULL )
         {
-          [ChapterNamesArray addObject:[NSString stringWithCString:chapter->title encoding:NSUTF8StringEncoding]];
+          [ChapterNamesArray addObject:[NSString stringWithUTF8String:chapter->title]];
         }
     }
     [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"];
index 952a67e5a219886cb8d7e7b7de603b68665b8775..27c7d498b5a46f2a4068f22ea5fe9342331f7fc3 100644 (file)
@@ -1301,21 +1301,6 @@ static int HandleEvents( hb_handle_t * h )
 
                         hb_close_csv_file( file );
                     }
-                }
-                else
-                {
-                    /* No marker file */
-
-                    int number_of_chapters = hb_list_count(job->title->list_chapter);
-                    int chapter;
-
-                    for(chapter = 0; chapter <= number_of_chapters - 1 ; chapter++)
-                    {
-                        hb_chapter_t * chapter_s;
-                        chapter_s = hb_list_item( job->title->list_chapter, chapter);
-                        snprintf( chapter_s->title, 1023, "Chapter %i", chapter + 1 );
-                        chapter_s->title[1023] = '\0';
-                    }
                 }
                        }