X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=test%2Ftest.c;h=134e0179b168d9f294994f2d030079f02a7d1e65;hb=434bd2c69bd7bad39e5c2c43467648d901d58691;hp=3d665a7af843b9b7f2f303849c90134e821b4cbb;hpb=8fecfabb5a3859af102a1d02f4a97f4c62931447;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/test/test.c b/test/test.c index 3d665a7a..134e0179 100644 --- a/test/test.c +++ b/test/test.c @@ -72,6 +72,11 @@ static char ** subtracks = NULL; static char ** subforce = NULL; static char * subburn = NULL; static char * subdefault = NULL; +static char ** srtfile = NULL; +static char ** srtcodeset = NULL; +static char ** srtoffset = NULL; +static char ** srtlang = NULL; +static int srtdefault = -1; static int subtitle_scan = 0; static int width = 0; static int height = 0; @@ -137,7 +142,7 @@ static char* bsd_name_for_path(char *path); static int device_is_dvd(char *device); static io_service_t get_iokit_service( char *device ); static int is_dvd_service( io_service_t service ); -static is_whole_media_service( io_service_t service ); +static int is_whole_media_service( io_service_t service ); #endif /* Only print the "Muxing..." message once */ @@ -405,12 +410,19 @@ static void PrintTitleInfo( hb_title_t * title ) audio = hb_list_audio_config_item( title->list_audio, i ); if( ( audio->in.codec == HB_ACODEC_AC3 ) || ( audio->in.codec == HB_ACODEC_DCA) ) { - fprintf( stderr, " + %d, %s, %dHz, %dbps\n", i + 1, - audio->lang.description, audio->in.samplerate, audio->in.bitrate ); + fprintf( stderr, " + %d, %s (iso639-2: %s), %dHz, %dbps\n", + i + 1, + audio->lang.description, + audio->lang.iso639_2, + audio->in.samplerate, + audio->in.bitrate ); } else { - fprintf( stderr, " + %d, %s\n", i + 1, audio->lang.description ); + fprintf( stderr, " + %d, %s (iso639-2: %s)\n", + i + 1, + audio->lang.iso639_2, + audio->lang.description ); } } fprintf( stderr, " + subtitle tracks:\n" ); @@ -1790,6 +1802,44 @@ static int HandleEvents( hb_handle_t * h ) } } + if( srtfile ) + { + char * token; + int i, pos; + hb_subtitle_config_t sub_config; + + pos = 0; + for( i=0; srtfile[i] != NULL; i++ ) + { + char *codeset = "L1"; + int64_t offset = 0; + char *lang = "und"; + + pos++; + token = srtfile[i]; + if( srtcodeset && srtcodeset[i] ) + { + codeset = srtcodeset[i]; + } + if( srtoffset && srtoffset[i] ) + { + offset = strtoll( srtoffset[i], &srtoffset[i], 0 ); + } + if ( srtlang && srtlang[i] ) + { + lang = srtlang[i]; + } + sub_config.default_track = + ( srtdefault != -1 ) && ( srtdefault == i + 1 ); + sub_config.force = 0; + strncpy( sub_config.src_filename, srtfile[i], 128); + strncpy( sub_config.src_codeset, codeset, 40); + sub_config.offset = offset; + + hb_srt_add( job, &sub_config, lang); + } + } + if( native_language ) { char audio_lang[4]; @@ -2304,7 +2354,7 @@ static void ShowHelp() " --subtitle-burn \"Burn\" the selected subtitle into the video track\n" " If \"number\" is omitted, the first trac is burned.\n" " --subtitle-default Flag the selected subtitle as the default subtitle\n" - " to be displayed upon playback. Settings no default\n" + " to be displayed upon playback. Setting no default\n" " means no subtitle will be automatically displayed\n" " If \"number\" is omitted, the first trac is default.\n" " -N, --native-language Specifiy the your language preference. When the first\n" @@ -2319,7 +2369,22 @@ static void ShowHelp() " that matches the --native-language. If there are no\n" " matching audio tracks then the first matching\n" " subtitle track is used instead.\n" - + " --srt-file SubRip SRT filename(s), separated by commas.\n" + " --srt-codeset Character codeset(s) that the SRT file(s) are\n" + " encoded in, separted by commas.\n" + " Use 'iconv -l' for a list of valid\n" + " codesets. If not specified latin1 is assumed\n" + " --srt-offset Offset in milli-seconds to apply to the SRT file(s)\n" + " separted by commas. If not specified zero is assumed.\n" + " Offsets may be negative.\n" + " --srt-lang Language as an iso639-2 code fra, eng, spa et cetera)\n" + " for the SRT file(s) separated by commas. If not specified\n" + " then 'und' is used.\n" + " --srt-default Flag the selected srt as the default subtitle\n" + " to be displayed upon playback. Setting no default\n" + " means no subtitle will be automatically displayed\n" + " If \"number\" is omitted, the first srt is default.\n" + " \"number\" is an 1 based index into the srt-file list\n" "\n" @@ -2364,15 +2429,25 @@ static void ShowPresets() printf("\n>\n"); } -static char** str_split( char *str, char *delem ) +static char * hb_strndup( char * str, int len ) +{ + char * res; + int str_len = strlen( str ); + + res = malloc( len > str_len ? str_len + 1 : len + 1 ); + strncpy( res, str, len ); + res[len] = '\0'; + return res; +} + +static char** str_split( char *str, char delem ) { - char * token; - char * copy_str; char * pos; + char * end; char ** ret; int count, i; - if ( str == NULL || delem == NULL || str[0] == 0 ) + if ( str == NULL || str[0] == 0 ) { ret = malloc( sizeof(char*) ); *ret = NULL; @@ -2382,24 +2457,23 @@ static char** str_split( char *str, char *delem ) // Find number of elements in the string count = 1; pos = str; - while ( ( pos = strstr( pos+1, delem ) ) != NULL ) + while ( ( pos = strchr( pos, delem ) ) != NULL ) { - if ( *(pos+1) != 0 ) - count++; + count++; + pos++; } - ret = calloc( ( count + 1 ), sizeof(char*) ); - copy_str = strdup( str ); - token = strtok( copy_str, delem ); + ret = calloc( ( count + 1 ), sizeof(char*) ); - i = 0; - while( token != NULL && i < count ) + pos = str; + for ( i = 0; i < count - 1; i++ ) { - ret[i] = strdup( token ); - token = strtok(NULL, ","); - i++; + end = strchr( pos, delem ); + ret[i] = hb_strndup(pos, end - pos); + pos = end + 1; } - free( copy_str ); + ret[i] = strdup(pos); + return ret; } @@ -2421,6 +2495,11 @@ static int ParseOptions( int argc, char ** argv ) #define SUB_BURNED 266 #define SUB_DEFAULT 267 #define NATIVE_DUB 268 + #define SRT_FILE 269 + #define SRT_CODESET 270 + #define SRT_OFFSET 271 + #define SRT_LANG 272 + #define SRT_DEFAULT 273 for( ;; ) { @@ -2451,9 +2530,13 @@ static int ParseOptions( int argc, char ** argv ) { "subtitle-forced", optional_argument, NULL, 'F' }, { "subtitle-burned", optional_argument, NULL, SUB_BURNED }, { "subtitle-default", optional_argument, NULL, SUB_DEFAULT }, + { "srt-file", required_argument, NULL, SRT_FILE }, + { "srt-codeset", required_argument, NULL, SRT_CODESET }, + { "srt-offset", required_argument, NULL, SRT_OFFSET }, + { "srt-lang", required_argument, NULL, SRT_LANG }, + { "srt-default", optional_argument, NULL, SRT_DEFAULT }, { "native-language", required_argument, NULL,'N' }, { "native-dub", no_argument, NULL, NATIVE_DUB }, - { "encoder", required_argument, NULL, 'e' }, { "aencoder", required_argument, NULL, 'E' }, { "two-pass", no_argument, NULL, '2' }, @@ -2504,7 +2587,7 @@ static int ParseOptions( int argc, char ** argv ) int c; c = getopt_long( argc, argv, - "hv::uC:f:4i:Io:t:Lc:m::M:a:A:6:s:UFN:e:E:2dD:7895gOw:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z", + "hv::uC:f:4i:Io:t:Lc:m::M:a:A:6:s:UF::N:e:E:2dD:7895gOw:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z", long_options, &option_index ); if( c < 0 ) { @@ -2640,10 +2723,10 @@ static int ParseOptions( int argc, char ** argv ) } break; case 's': - subtracks = str_split( optarg, "," ); + subtracks = str_split( optarg, ',' ); break; case 'F': - subtracks = str_split( optarg, "," ); + subforce = str_split( optarg, ',' ); break; case SUB_BURNED: if( optarg != NULL ) @@ -2671,6 +2754,28 @@ static int ParseOptions( int argc, char ** argv ) case NATIVE_DUB: native_dub = 1; break; + case SRT_FILE: + srtfile = str_split( optarg, ',' ); + break; + case SRT_CODESET: + srtcodeset = str_split( optarg, ',' ); + break; + case SRT_OFFSET: + srtoffset = str_split( optarg, ',' ); + break; + case SRT_LANG: + srtlang = str_split( optarg, ',' ); + break; + case SRT_DEFAULT: + if( optarg != NULL ) + { + srtdefault = atoi( optarg ); + } + else + { + srtdefault = 1 ; + } + break; case '2': twoPass = 1; break; @@ -3206,7 +3311,7 @@ static int is_dvd_service( io_service_t service ) * The whole media object is indicated in the IORegistry by the presence of a * property with the key "Whole" and value "Yes". ****************************************************************************/ -static is_whole_media_service( io_service_t service ) +static int is_whole_media_service( io_service_t service ) { int result = 0;