rendered paste bodyIndex: test/test.c===================================================================--- test/test.c (revision 1364)+++ test/test.c (working copy)@@ -18,9 +18,12 @@ static int update = 0; static char * input = NULL; static char * output = NULL;+static char * basename = NULL;+static char * suffix = NULL; static char * format = NULL; static int titleindex = 1; static int longest_title = 0;+static int title_all = 0; static int subtitle_scan = 0; static int subtitle_force = 0; static char * native_language = NULL;@@ -158,7 +161,8 @@ /* Feed libhb with a DVD to scan */ fprintf( stderr, "Opening %s...\n", input ); - if (longest_title) {+ if( longest_title || title_all ) + { /* * We need to scan for all the titles in order to find the longest */@@ -334,6 +338,7 @@ hb_list_t * list; hb_title_t * title; hb_job_t * job;+ int begin_title, end_title; list = hb_get_titles( h ); @@ -382,7 +387,7 @@ title = hb_list_item( list, 0 ); } - if( !titleindex )+ if( !titleindex && !title_all ) { /* Scan-only mode, print infos and exit */ int i;@@ -395,6 +400,67 @@ break; } + /*+ * We will loop here and apply the same settings to all titles+ * in the source. + */+ if( title_all )+ {+ begin_title = 0;+ end_title = hb_list_count( list );+ } else {+ /*+ * Don't loop+ */+ begin_title = titleindex;+ end_title = titleindex;+ }++ for( titleindex = begin_title; titleindex < end_title; titleindex++ )+ {+ if( title_all )+ {+ /*+ * Change the title to encode, and add a suffix to the filename+ * of the title index.+ *+ * e.g. filename-%d.m4v where %d is the title number.+ */+ char *new_filename;++ if( !basename )+ {+ basename = strdup( output );++ suffix = strrchr( basename, '.' );+ if( suffix ) + {+ *suffix = '\0';+ suffix++;+ } + }++ new_filename = malloc( strlen(basename) + strlen(suffix) + 7 );++ if( new_filename )+ {+ if( suffix )+ {+ sprintf(new_filename, "%s-%d.%s", basename, titleindex+1, suffix);+ } else {+ sprintf(new_filename, "%s-%d", basename, titleindex+1);+ }+ + free(output);++ output = new_filename;+ } else {+ hb_cli_error_handler("memory allocation failure for filename");+ exit(1);+ }+ title = hb_list_item( list, titleindex );+ }+ /* Set job settings */ job = title->job; @@ -1051,6 +1117,9 @@ job->pass = 0; hb_add( h, job ); }+ + } /* for all titles */+ hb_start( h ); break; }@@ -1147,8 +1216,8 @@ "### Source Options-----------------------------------------------------------\n\n" " -i, --input <string> Set input device\n"- " -t, --title <number> Select a title to encode (0 to scan only,\n"- " default: 1)\n"+ " -t, --title <number> Select a title to encode (0 to scan only,\n"+ " 'all' for all titles, default: 1)\n" " -L, --longest Select the longest title\n" " -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n" " 1 to 3, or \"3\" for chapter 3 only,\n"@@ -1427,7 +1496,14 @@ break; case 't':- titleindex = atoi( optarg );+ if( strcmp( optarg, "all" ) == 0 )+ {+ title_all = 1;+ } + else + {+ titleindex = atoi( optarg );+ } break; case 'L': longest_title = 1;