diff options
author | jbrjake <[email protected]> | 2007-07-26 04:44:08 +0000 |
---|---|---|
committer | jbrjake <[email protected]> | 2007-07-26 04:44:08 +0000 |
commit | 80ffb9a03d9454a7ae272dc3415d672cffc0c44a (patch) | |
tree | 3bc2ab61a7eaf53425c0e67d9a7baf7dc3d39bb6 | |
parent | 5ba628237996fb82df61337b0d6ee684cde35df5 (diff) |
Native language subtitle scan improvements. Thanks, eddyg!
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@741 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/hb.c | 100 | ||||
-rw-r--r-- | libhb/work.c | 89 | ||||
-rw-r--r-- | test/test.c | 5 |
3 files changed, 131 insertions, 63 deletions
diff --git a/libhb/hb.c b/libhb/hb.c index a956e957a..f3ec1bbcf 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -557,7 +557,21 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) title_copy->list_subtitle = hb_list_init(); - + /* + * The following code is confusing, there are three ways in which we select subtitles + * and it depends on whether this is single or two pass mode. + * + * subtitle_scan may be enabled, in which case the first pass scans all subtitles + * of that language. The second pass does not select any because they are set at the + * end of the first pass. + * + * native_language may have a preferred language, in which case we may be switching + * the language we want for the subtitles in the first pass of a single pass, or the + * second pass of a two pass. + * + * We may have manually selected a subtitle, in which case that is selected in the + * first pass of a single pass, or the second of a two pass. + */ memset( audio_lang, 0, sizeof( audio_lang ) ); if ( job->subtitle_scan || job->native_language ) { @@ -578,15 +592,21 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) } } - + /* + * In all cases switch the language if we need to to our native + * language. + */ if( job->native_language ) { if( strncasecmp( job->native_language, audio_lang, sizeof( audio_lang ) ) != 0 ) { - hb_log( "Enabled subtitles in native language '%s', audio is in '%s'", - job->native_language, audio_lang); + if( job->pass != 2 ) + { + hb_log( "Enabled subtitles in native language '%s', audio is in '%s'", + job->native_language, audio_lang); + } /* * The main audio track is not in our native language, so switch * the subtitles to use our native language instead. @@ -601,12 +621,13 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) } } } - - if ( job->subtitle_scan || job->native_language ) + + /* + * If doing a subtitle scan then add all the matching subtitles for this + * language. + */ + if ( job->subtitle_scan ) { - /* - * Select subtitles that match the language we want - */ for( i=0; i < hb_list_count( title->list_subtitle ); i++ ) { subtitle = hb_list_item( title->list_subtitle, i ); @@ -615,15 +636,18 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) /* * Matched subtitle language with audio language, so * add this to our list to scan. + * + * We will update the subtitle list on the second pass + * later after the first pass has completed. */ subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); hb_list_add( title_copy->list_subtitle, subtitle_copy ); - if ( !job->subtitle_scan ) { + if ( job->native_language ) { /* * With native language just select the * first match in our langiage, not all of - * them. + * them. Subsequent ones are likely to be commentary */ break; } @@ -631,16 +655,56 @@ void hb_add( hb_handle_t * h, hb_job_t * job ) } } else { /* - * Manually selected subtitle, in which case only bother adding them - * for pass 0 or pass 2 of a two pass. + * Not doing a subtitle scan in this pass, but maybe we are in the + * first pass? */ - if( job->pass != 1 ) + if( job->select_subtitle ) { - if( ( subtitle = hb_list_item( title->list_subtitle, job->subtitle ) ) ) + /* + * Don't add subtitles here, we'll add them via select_subtitle + * at the end of pass 1 + */ + } else { + /* + * Definitely not doing a subtitle scan. + */ + if( job->pass != 1 && job->native_language ) { - subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); - memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); - hb_list_add( title_copy->list_subtitle, subtitle_copy ); + /* + * We are not doing a subtitle scan but do want the + * native langauge subtitle selected, so select it + * for pass 0 or pass 2 of a two pass. + */ + for( i=0; i < hb_list_count( title->list_subtitle ); i++ ) + { + subtitle = hb_list_item( title->list_subtitle, i ); + if( strcmp( subtitle->iso639_2, audio_lang ) == 0 ) + { + /* + * Matched subtitle language with audio language, so + * add this to our list to scan. + */ + subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); + memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); + hb_list_add( title_copy->list_subtitle, subtitle_copy ); + break; + } + } + } else { + /* + * Manually selected subtitle, in which case only + * bother adding them for pass 0 or pass 2 of a two + * pass. + */ + if( job->pass != 1 ) + { + if( ( subtitle = hb_list_item( title->list_subtitle, job->subtitle ) ) ) + { + subtitle_copy = malloc( sizeof( hb_subtitle_t ) ); + memcpy( subtitle_copy, subtitle, sizeof( hb_subtitle_t ) ); + hb_list_add( title_copy->list_subtitle, subtitle_copy ); + } + } } } } diff --git a/libhb/work.c b/libhb/work.c index 92707cc42..49ac70c1a 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -199,6 +199,11 @@ static void do_job( hb_job_t * job, int cpu_count ) if( job->select_subtitle && !job->subtitle_scan ) { + /* + * Must be second pass of a two pass with subtitle scan enabled, so + * add the subtitle that we found on the first pass for use in this + * pass. + */ hb_list_add( title->list_subtitle, *( job->select_subtitle ) ); } @@ -535,54 +540,56 @@ static void do_job( hb_job_t * job, int cpu_count ) hb_fifo_close( &audio->fifo_sync ); hb_fifo_close( &audio->fifo_out ); } - - /* - * Before closing the title print out our subtitle stats if we need to - * Find the highest and lowest. - */ - for( i=0; i < hb_list_count( title->list_subtitle ); i++ ) - { - subtitle = hb_list_item( title->list_subtitle, i ); - hb_log( "Subtitle stream 0x%x '%s': %d hits", - subtitle->id, subtitle->lang, subtitle->hits ); - if( subtitle->hits > subtitle_highest ) - { - subtitle_highest = subtitle->hits; - subtitle_highest_id = subtitle->id; - } - - if( subtitle->hits < subtitle_lowest ) - { - subtitle_lowest = subtitle->hits; - subtitle_lowest_id = subtitle->id; - } - } - if( job->native_language ) { + if( job->subtitle_scan ) + { /* - * We still have a native_language, so the audio and subtitles are - * different, so in this case it is a foreign film and we want to - * select the first subtitle in our language. + * Before closing the title print out our subtitle stats if we need to + * Find the highest and lowest. */ - subtitle = hb_list_item( title->list_subtitle, 0 ); - subtitle_hit = subtitle->id; - hb_log( "Found a native-language subtitle id 0x%x", subtitle_hit); - } else { - if( subtitle_lowest < subtitle_highest ) + for( i=0; i < hb_list_count( title->list_subtitle ); i++ ) { + subtitle = hb_list_item( title->list_subtitle, i ); + hb_log( "Subtitle stream 0x%x '%s': %d hits", + subtitle->id, subtitle->lang, subtitle->hits ); + if( subtitle->hits > subtitle_highest ) + { + subtitle_highest = subtitle->hits; + subtitle_highest_id = subtitle->id; + } + + if( subtitle->hits < subtitle_lowest ) + { + subtitle_lowest = subtitle->hits; + subtitle_lowest_id = subtitle->id; + } + } + + if( job->native_language ) { /* - * OK we have more than one, and the lowest is lower, but how much - * lower to qualify for turning it on by default? - * - * Let's say 10% as a default. + * We still have a native_language, so the audio and subtitles are + * different, so in this case it is a foreign film and we want to + * select the subtitle with the highest hits in our language. */ - if( subtitle_lowest < ( subtitle_highest * 0.1 ) ) + subtitle_hit = subtitle_highest_id; + hb_log( "Found a native-language subtitle id 0x%x", subtitle_hit); + } else { + if( subtitle_lowest < subtitle_highest ) { - subtitle_hit = subtitle_lowest_id; - hb_log( "Found a subtitle candidate id 0x%x", - subtitle_hit ); - } else { - hb_log( "No candidate subtitle detected during subtitle-scan"); + /* + * OK we have more than one, and the lowest is lower, but how much + * lower to qualify for turning it on by default? + * + * Let's say 10% as a default. + */ + if( subtitle_lowest < ( subtitle_highest * 0.1 ) ) + { + subtitle_hit = subtitle_lowest_id; + hb_log( "Found a subtitle candidate id 0x%x", + subtitle_hit ); + } else { + hb_log( "No candidate subtitle detected during subtitle-scan"); + } } } } diff --git a/test/test.c b/test/test.c index 9c85e3121..929e3eb20 100644 --- a/test/test.c +++ b/test/test.c @@ -635,12 +635,9 @@ static int HandleEvents( hb_handle_t * h ) * Turn on subtitle scan if requested, note that this option * precludes encoding of any actual subtitles. */ - job->subtitle_scan = subtitle_scan; if ( subtitle_scan ) { - fprintf( stderr, "Subtitle Scan Enabled, will scan all " - "subtitles matching the audio language for any\n" - "that meet our auto-selection criteria.\n"); + fprintf( stderr, "Warning: Subtitle Scan only works in two-pass, disabling\n"); } job->pass = 0; hb_add( h, job ); |