diff options
author | jbrjake <[email protected]> | 2008-11-30 04:00:11 +0000 |
---|---|---|
committer | jbrjake <[email protected]> | 2008-11-30 04:00:11 +0000 |
commit | 69f6bca6694d93d05a69bad93a748cf31d52c28f (patch) | |
tree | da667ca11872c0c9ec2b3775ea2ac0831d4ed2cd /libhb | |
parent | b2a296d98c0363f781fe37f6a28678bbaaba0377 (diff) |
Adds two new parameters to hb_scan, to control the number of preview frames generated during scan, and whether or not they're written to disk for later display. This will break any interfaces that use hb_scan until the new params are specified...sorry. Also adds a new job->seek_points setting (set this to the same as the number of previews) to be used with job->start_at_preview when doing live preview encodes, so the seek function has a frame of reference.
Wires up the CLI with a --previews option (long option only) to control the new scan parameters, and defaults the CLI to not writing previews to disk.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1970 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-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 |
6 files changed, 52 insertions, 30 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 */ |