diff options
-rw-r--r-- | libhb/common.h | 3 | ||||
-rw-r--r-- | libhb/hb.c | 8 | ||||
-rw-r--r-- | libhb/hb.h | 3 | ||||
-rw-r--r-- | libhb/internal.h | 3 | ||||
-rw-r--r-- | libhb/reader.c | 7 | ||||
-rw-r--r-- | libhb/scan.c | 58 | ||||
-rw-r--r-- | test/test.c | 15 |
7 files changed, 66 insertions, 31 deletions
diff --git a/libhb/common.h b/libhb/common.h index 95b50e9da..2a12e8f45 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -225,7 +225,8 @@ struct hb_job_s int64_t pts_to_stop; // declare eof when we pass this pts in // the time-linearized input stream int start_at_preview; // if non-zero, encoding will start - // at the position of preview n (1-10) + // at the position of preview n + int seek_points; // out of N previews uint32_t frames_to_skip; // decode but discard this many frames // initially (for frame accurate positioning // to non-I frames). diff --git a/libhb/hb.c b/libhb/hb.c index 713c82580..267c5b716 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -277,8 +277,11 @@ void hb_set_cpu_count( hb_handle_t * h, int cpu_count ) * @param h Handle to hb_handle_t * @param path location of VIDEO_TS folder. * @param title_index Desired title to scan. 0 for all titles. + * @param preview_count Number of preview images to generate. + * @param store_previews Whether or not to write previews to disk. */ -void hb_scan( hb_handle_t * h, const char * path, int title_index ) +void hb_scan( hb_handle_t * h, const char * path, int title_index, + int preview_count, int store_previews ) { hb_title_t * title; @@ -290,7 +293,8 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index ) } hb_log( "hb_scan: path=%s, title_index=%d", path, title_index ); - h->scan_thread = hb_scan_init( h, path, title_index, h->list_title ); + h->scan_thread = hb_scan_init( h, path, title_index, h->list_title, + preview_count, store_previews ); } /** diff --git a/libhb/hb.h b/libhb/hb.h index 8bfd9a144..4ea050975 100644 --- a/libhb/hb.h +++ b/libhb/hb.h @@ -77,7 +77,8 @@ char * hb_dvd_name( char * path ); Scan the specified path. Can be a DVD device, a VIDEO_TS folder or a VOB file. If title_index is 0, scan all titles. */ void hb_scan( hb_handle_t *, const char * path, - int title_index ); + int title_index, int preview_count, + int store_previews ); /* hb_get_titles() Returns the list of valid titles detected by the latest scan. */ diff --git a/libhb/internal.h b/libhb/internal.h index cc888b121..d21a281e0 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -132,7 +132,8 @@ static inline void hb_buffer_swap_copy( hb_buffer_t *src, hb_buffer_t *dst ) **********************************************************************/ hb_thread_t * hb_update_init( int * build, char * version ); hb_thread_t * hb_scan_init( hb_handle_t *, const char * path, - int title_index, hb_list_t * list_title ); + int title_index, hb_list_t * list_title, + int preview_count, int store_previews ); hb_thread_t * hb_work_init( hb_list_t * jobs, int cpu_count, volatile int * die, int * error, hb_job_t ** job ); hb_thread_t * hb_reader_init( hb_job_t * ); diff --git a/libhb/reader.c b/libhb/reader.c index bdb1cf0b5..911a33bd6 100644 --- a/libhb/reader.c +++ b/libhb/reader.c @@ -209,13 +209,16 @@ static void ReaderFunc( void * _r ) if ( r->job->start_at_preview ) { // XXX code from DecodePreviews - should go into its own routine - hb_dvd_seek( r->dvd, (float)r->job->start_at_preview / 11. ); + hb_dvd_seek( r->dvd, (float)r->job->start_at_preview / + ( r->job->seek_points ? ( r->job->seek_points + 1.0 ) : 11.0 ) ); } } else if ( r->stream && r->job->start_at_preview ) { // XXX code from DecodePreviews - should go into its own routine - hb_stream_seek( r->stream, (float)( r->job->start_at_preview - 1 ) / 11. ); + hb_stream_seek( r->stream, (float)( r->job->start_at_preview - 1 ) / + ( r->job->seek_points ? ( r->job->seek_points + 1.0 ) : 11.0 ) ); + } list = hb_list_init(); diff --git a/libhb/scan.c b/libhb/scan.c index 36682bea5..26927ffbc 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -8,6 +8,8 @@ #include "a52dec/a52.h" #include "dca.h" +#define HB_MAX_PREVIEWS 30 // 30 previews = every 5 minutes of a 2.5 hour video + typedef struct { hb_handle_t * h; @@ -18,6 +20,9 @@ typedef struct hb_dvd_t * dvd; hb_stream_t * stream; + + int preview_count; + int store_previews; } hb_scan_t; @@ -39,7 +44,8 @@ static const char *aspect_to_string( double aspect ) } hb_thread_t * hb_scan_init( hb_handle_t * handle, const char * path, - int title_index, hb_list_t * list_title ) + int title_index, hb_list_t * list_title, + int preview_count, int store_previews ) { hb_scan_t * data = calloc( sizeof( hb_scan_t ), 1 ); @@ -47,7 +53,10 @@ hb_thread_t * hb_scan_init( hb_handle_t * handle, const char * path, data->path = strdup( path ); data->title_index = title_index; data->list_title = list_title; - + + data->preview_count = preview_count; + data->store_previews = store_previews; + return hb_thread_init( "scan", ScanFunc, data, HB_NORMAL_PRIORITY ); } @@ -316,10 +325,10 @@ static int column_all_dark( hb_title_t *title, uint8_t* luma, int top, int botto typedef struct { int n; - int t[10]; - int b[10]; - int l[10]; - int r[10]; + int t[HB_MAX_PREVIEWS]; + int b[HB_MAX_PREVIEWS]; + int l[HB_MAX_PREVIEWS]; + int r[HB_MAX_PREVIEWS]; } crop_record_t; static void record_crop( crop_record_t *crops, int t, int b, int l, int r ) @@ -397,7 +406,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) hb_list_t * list_es; int progressive_count = 0; int interlaced_preview_count = 0; - info_list_t * info_list = calloc( 10+1, sizeof(*info_list) ); + info_list_t * info_list = calloc( data->preview_count+1, sizeof(*info_list) ); crop_record_t *crops = calloc( 1, sizeof(*crops) ); buf_ps = hb_buffer_init( HB_DVD_READ_BUFFER_SIZE ); @@ -408,7 +417,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) if (data->dvd) hb_dvd_start( data->dvd, title->index, 1 ); - for( i = 0; i < 10; i++ ) + for( i = 0; i < data->preview_count; i++ ) { int j; FILE * file_preview; @@ -416,7 +425,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) if (data->dvd) { - if( !hb_dvd_seek( data->dvd, (float) ( i + 1 ) / 11.0 ) ) + if( !hb_dvd_seek( data->dvd, (float) ( i + 1 ) / ( data->preview_count + 1.0 ) ) ) { continue; } @@ -426,7 +435,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) /* we start reading streams at zero rather than 1/11 because * short streams may have only one sequence header in the entire * file and we need it to decode any previews. */ - if (!hb_stream_seek(data->stream, (float) i / 11.0 ) ) + if (!hb_stream_seek(data->stream, (float) i / ( data->preview_count + 1.0 ) ) ) { continue; } @@ -560,20 +569,23 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) hb_deep_log( 2, "Interlacing detected in preview frame %i", i+1); interlaced_preview_count++; } - - hb_get_tempory_filename( data->h, filename, "%x%d", - (intptr_t)title, i ); - - file_preview = fopen( filename, "w" ); - if( file_preview ) - { - fwrite( vid_buf->data, title->width * title->height * 3 / 2, - 1, file_preview ); - fclose( file_preview ); - } - else + + if( data->store_previews ) { - hb_log( "scan: fopen failed (%s)", filename ); + hb_get_tempory_filename( data->h, filename, "%x%d", + (intptr_t)title, i ); + + file_preview = fopen( filename, "w" ); + if( file_preview ) + { + fwrite( vid_buf->data, title->width * title->height * 3 / 2, + 1, file_preview ); + fclose( file_preview ); + } + else + { + hb_log( "scan: fopen failed (%s)", filename ); + } } /* Detect black borders */ diff --git a/test/test.c b/test/test.c index 59cf0eb0b..efa7f29d2 100644 --- a/test/test.c +++ b/test/test.c @@ -92,6 +92,8 @@ static int cfr = 0; static int mp4_optimize = 0; static int ipod_atom = 0; static int color_matrix = 0; +static int preview_count = 10; +static int store_previews = 0; /* Exit cleanly on Ctrl-C */ static volatile int die = 0; @@ -196,7 +198,8 @@ int main( int argc, char ** argv ) */ titleindex = 0; } - hb_scan( h, input, titleindex ); + + hb_scan( h, input, titleindex, preview_count, store_previews ); /* Wait... */ while( !die ) @@ -1873,6 +1876,9 @@ static void ShowHelp() " -c, --chapters <string> Select chapters (e.g. \"1-3\" for chapters\n" " 1 to 3, or \"3\" for chapter 3 only,\n" " default: all chapters)\n" + " --previews <#:B> Select how many preview images are generated (max 30),\n" + " and whether or not they're stored to disk (0 or 1).\n" + " (default: 10:0)\n" "\n" "### Destination Options------------------------------------------------------\n\n" @@ -2073,6 +2079,9 @@ static void ShowPresets() ****************************************************************************/ static int ParseOptions( int argc, char ** argv ) { + + #define PREVIEWS 257 + for( ;; ) { static struct option long_options[] = @@ -2132,6 +2141,7 @@ static int ParseOptions( int argc, char ** argv ) { "aname", required_argument, NULL, 'A' }, { "color-matrix",required_argument, NULL, 'M' }, + { "previews", required_argument, NULL, PREVIEWS }, { 0, 0, 0, 0 } }; @@ -2477,6 +2487,9 @@ static int ParseOptions( int argc, char ** argv ) anames = strdup( optarg ); } break; + case PREVIEWS: + sscanf( optarg, "%i:%i", &preview_count, &store_previews ); + break; case 'M': if( atoi( optarg ) == 601 ) color_matrix = 1; |