Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image sequence input (not fully merged back, Linux gui not added) #4461

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions gtk/src/hb-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -3553,9 +3553,12 @@ void ghb_backend_scan_stop()
}

void
ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count, uint64_t min_duration)
ghb_backend_scan(const gchar *path, gint titleindex, gint image_sequence,
const gchar *sequence_framerate, gint preview_count,
uint64_t min_duration)
{
hb_scan( h_scan, path, titleindex, preview_count, 1, min_duration );
hb_scan( h_scan, path, titleindex, image_sequence, sequence_framerate,
preview_count, 1, min_duration );
hb_status.scan.state |= GHB_STATE_SCANNING;
// initialize count and cur to something that won't cause FPE
// when computing progress
Expand All @@ -3570,7 +3573,7 @@ void
ghb_backend_queue_scan(const gchar *path, gint titlenum)
{
g_debug("ghb_backend_queue_scan()");
hb_scan( h_queue, path, titlenum, -1, 0, 0 );
hb_scan( h_queue, path, titlenum, 0, 0.0f, -1, 0, 0 );
hb_status.queue.state |= GHB_STATE_SCANNING;
}

Expand Down
10 changes: 9 additions & 1 deletion libhb/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4248,7 +4248,15 @@ void hb_job_set_file(hb_job_t *job, const char *file)
}
}

hb_filter_object_t * hb_filter_copy( hb_filter_object_t * filter )
void hb_job_set_sequence_framerate(hb_job_t *job, const char *sequence_framerate)
{
if (job != NULL)
{
hb_update_str(&job->sequence_framerate, sequence_framerate);
}
}

hb_filter_object_t *hb_filter_copy(hb_filter_object_t *filter)
{
if( filter == NULL )
return NULL;
Expand Down
5 changes: 5 additions & 0 deletions libhb/handbrake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void hb_job_set_encoder_options(hb_job_t *job, const char *options);
void hb_job_set_encoder_profile(hb_job_t *job, const char *profile);
void hb_job_set_encoder_level (hb_job_t *job, const char *level);
void hb_job_set_file (hb_job_t *job, const char *file);
void hb_job_set_sequence_framerate(hb_job_t *job, const char *sequence_framerate);

hb_audio_t *hb_audio_copy(const hb_audio_t *src);
hb_list_t *hb_audio_list_copy(const hb_list_t *src);
Expand Down Expand Up @@ -537,6 +538,10 @@ struct hb_job_s
/* Include chapter marker track in mp4? */
int chapter_markers;

/* Should be opened as an image sequence, Boolean */
int image_sequence;
const char * sequence_framerate;

// Video filters
int grayscale; // Black and white encoding
hb_list_t * list_filter;
Expand Down
7 changes: 5 additions & 2 deletions libhb/handbrake/handbrake.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ void hb_dvd_set_dvdnav( int enable );

/* hb_scan()
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. */
a VOB file. If title_index is 0, scan all titles.
If image_sequence is non-0, try opening as image sequence with framerate
set in sequence_framerate. */
void hb_scan( hb_handle_t *, const char * path,
int title_index, int preview_count,
int title_index, int image_sequence,
const char *sequence_framerate, int preview_count,
int store_previews, uint64_t min_duration );
void hb_scan_stop( hb_handle_t * );
void hb_force_rescan( hb_handle_t * );
Expand Down
11 changes: 7 additions & 4 deletions libhb/handbrake/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ static inline hb_buffer_t * hb_video_buffer_init( int width, int height )
/***********************************************************************
* Threads: scan.c, work.c, reader.c, muxcommon.c
**********************************************************************/
hb_thread_t * hb_scan_init( hb_handle_t *, volatile int * die,
const char * path, int title_index,
hb_title_set_t * title_set, int preview_count,
int store_previews, uint64_t min_duration );
hb_thread_t *hb_scan_init(hb_handle_t *, volatile int *die,
const char *path, int title_index,
hb_title_set_t *title_set, int image_sequence,
const char *sequence_framerate, int preview_count,
int store_previews, uint64_t min_duration);
hb_thread_t * hb_work_init( hb_list_t * jobs,
volatile int * die, hb_error_code * error, hb_job_t ** job );
void ReadLoop( void * _w );
Expand Down Expand Up @@ -360,6 +361,8 @@ hb_stream_t * hb_bd_stream_open( hb_handle_t *h, hb_title_t *title );
void hb_ts_stream_reset(hb_stream_t *stream);
hb_stream_t * hb_stream_open(hb_handle_t *h, const char * path,
hb_title_t *title, int scan);
hb_stream_t * hb_sequence_open(hb_handle_t *h, const char * path,
const char * framerate);
void hb_stream_close( hb_stream_t ** );
hb_title_t * hb_stream_title_scan( hb_stream_t *, hb_title_t *);
hb_buffer_t * hb_stream_read( hb_stream_t * );
Expand Down
9 changes: 6 additions & 3 deletions libhb/hb.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,13 @@ void hb_remove_previews( hb_handle_t * h )
* @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 image_sequence Whether to try reading an image sequence from the starting image.
* @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,
int preview_count, int store_previews, uint64_t min_duration )
void hb_scan(hb_handle_t *h, const char *path, int title_index,
int image_sequence, const char *sequence_framerate,
int preview_count, int store_previews, uint64_t min_duration)
{
hb_title_t * title;

Expand Down Expand Up @@ -434,7 +436,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, &h->scan_die, path, title_index,
&h->title_set, preview_count,
&h->title_set, image_sequence,
sequence_framerate, preview_count,
store_previews, min_duration );
}

Expand Down
15 changes: 14 additions & 1 deletion libhb/hb_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ hb_dict_t* hb_job_to_dict( const hb_job_t * job )
"s:{s:o, s:o, s:o, s:o, s:[]},"
// Source {Path, Title, Angle}
"s:{s:o, s:o, s:o,},"
// ImageSequence, SequenceFramerate
"s:o, s:o,"
// PAR {Num, Den}
"s:{s:o, s:o},"
// Video {Encoder, QSV {Decode, AsyncDepth, AdapterIndex}}
Expand All @@ -527,6 +529,8 @@ hb_dict_t* hb_job_to_dict( const hb_job_t * job )
"Path", hb_value_string(job->title->path),
"Title", hb_value_int(job->title->index),
"Angle", hb_value_int(job->angle),
"ImageSequence", hb_value_bool(job->image_sequence),
"SequenceFramerate", hb_value_string(job->sequence_framerate),
"PAR",
"Num", hb_value_int(job->par.num),
"Den", hb_value_int(job->par.den),
Expand Down Expand Up @@ -920,7 +924,7 @@ void hb_json_job_scan( hb_handle_t * h, const char * json_job )

// If the job wants to use Hardware decode, it must also be
// enabled during scan. So enable it here.
hb_scan(h, path, title_index, -1, 0, 0);
hb_scan(h, path, title_index, 0, NULL, -1, 0, 0);

// Wait for scan to complete
hb_state_t state;
Expand Down Expand Up @@ -993,6 +997,7 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
hb_value_t * acodec_copy_mask = NULL, * acodec_fallback = NULL;
const char * destfile = NULL;
const char * range_type = NULL;
const char * sequence_framerate = NULL;
const char * video_preset = NULL, * video_tune = NULL;
const char * video_profile = NULL, * video_level = NULL;
const char * video_options = NULL;
Expand All @@ -1013,6 +1018,8 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
"s:{s?s, s:o, s?b, s?b, s:b, s?o s?{s?b, s?b}},"
// Source {Angle, Range {Type, Start, End, SeekPoints}}
"s:{s?i, s?{s:s, s?I, s?I, s?I}},"
// ImageSequence, SequenceFramerate
"s:b, s:s,"
// PAR {Num, Den}
"s?{s:i, s:i},"
// Video {Codec, Quality, Bitrate, Preset, Tune, Profile, Level, Options
Expand Down Expand Up @@ -1058,6 +1065,8 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
"Start", unpack_I(&range_start),
"End", unpack_I(&range_end),
"SeekPoints", unpack_I(&range_seek_points),
"ImageSequence", unpack_b(&job->image_sequence),
"SequenceFramerate", unpack_s(&sequence_framerate),
"PAR",
"Num", unpack_i(&job->par.num),
"Den", unpack_i(&job->par.den),
Expand Down Expand Up @@ -1175,6 +1184,10 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
{
hb_job_set_file(job, destfile);
}
if(sequence_framerate != NULL && sequence_framerate[0] != 0)
{
hb_job_set_sequence_framerate(job, sequence_framerate);
}

hb_job_set_encoder_preset(job, video_preset);
hb_job_set_encoder_tune(job, video_tune);
Expand Down
7 changes: 7 additions & 0 deletions libhb/preset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,13 @@ int hb_preset_apply_title(hb_handle_t *h, int title_index,
if (hb_list_count(title->list_chapter) <= 1)
chapters = 0;

// Apply image sequence settings if present
if (hb_dict_get_bool(preset, "ImageSequence"))
{
hb_dict_set_bool(job_dict, "ImageSequence", 1);
hb_dict_set(job_dict, "SequenceFramerate", hb_dict_get(preset, "SequenceFramerate"));
}

// Set "Destination" settings in job
hb_dict_t *dest_dict = hb_dict_get(job_dict, "Destination");
hb_dict_set(dest_dict, "ChapterMarkers", hb_value_bool(chapters));
Expand Down
12 changes: 10 additions & 2 deletions libhb/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,16 @@ static int hb_reader_open( hb_work_private_t * r )
else if (r->title->type == HB_STREAM_TYPE ||
r->title->type == HB_FF_STREAM_TYPE)
{
if (!(r->stream = hb_stream_open(r->h, r->title->path, r->title, 0)))
return 1;
if (r->job->image_sequence == 0)
{
if (!(r->stream = hb_stream_open(r->h, r->title->path, r->title, 0)))
return 1;
}
else
{
if (!(r->stream = hb_sequence_open(r->h, r->title->path, r->job->sequence_framerate)))
return 1;
}
if (r->job->start_at_preview)
{
// First try seeking to PTS title duration / (seek_points + 1)
Expand Down
54 changes: 45 additions & 9 deletions libhb/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ typedef struct
hb_stream_t * stream;
hb_batch_t * batch;

int image_sequence;
char * sequence_framerate;

int preview_count;
int store_previews;

Expand Down Expand Up @@ -56,10 +59,11 @@ static const char *aspect_to_string(hb_rational_t *dar)
return arstr;
}

hb_thread_t * hb_scan_init( hb_handle_t * handle, volatile int * die,
const char * path, int title_index,
hb_title_set_t * title_set, int preview_count,
int store_previews, uint64_t min_duration )
hb_thread_t *hb_scan_init(hb_handle_t *handle, volatile int *die,
const char *path, int title_index,
hb_title_set_t *title_set, int image_sequence,
const char *sequence_framerate, int preview_count,
int store_previews, uint64_t min_duration)
{
hb_scan_t * data = calloc( sizeof( hb_scan_t ), 1 );

Expand All @@ -69,7 +73,9 @@ hb_thread_t * hb_scan_init( hb_handle_t * handle, volatile int * die,
data->title_index = title_index;
data->title_set = title_set;

data->preview_count = preview_count;
data->image_sequence = image_sequence;
data->sequence_framerate = strdup(sequence_framerate);
data->preview_count = preview_count;
data->store_previews = store_previews;
data->min_title_duration = min_duration;

Expand Down Expand Up @@ -188,13 +194,35 @@ static void ScanFunc( void * _data )
// mode.
if (data->title_index == 0)
data->title_index = 1;
hb_title_t * title = hb_title_init( data->path, data->title_index );
data->stream = hb_stream_open(data->h, data->path, title, 1);

hb_title_t *title = hb_title_init(data->path, data->title_index);
if (data->image_sequence == 1)
{
hb_log( "trying to load image sequence" );
data->stream = hb_sequence_open(data->h, data->path, data->sequence_framerate);
}
else
{
data->stream = hb_stream_open(data->h, data->path, title, 1);
}
if (data->stream != NULL)
{
title = hb_stream_title_scan( data->stream, title );
if ( title )
hb_list_add( data->title_set->list_title, title );
{
if (data->image_sequence == 1)
{
char *name = data->path;
char *sep = hb_strr_dir_sep(data->path);
if (sep)
name = sep + 1;
title->name = strdup(name);
char *dot_term = strrchr(title->name, '.');
if (dot_term)
*dot_term = '\0';
}
hb_list_add(data->title_set->list_title, title);
}
}
else
{
Expand Down Expand Up @@ -322,6 +350,7 @@ static void ScanFunc( void * _data )
hb_batch_close( &data->batch );
}
free( data->path );
free( data->sequence_framerate );
free( data );
_data = NULL;
hb_buffer_pool_free();
Expand Down Expand Up @@ -586,7 +615,14 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
}
else if (data->stream)
{
stream = hb_stream_open(data->h, data->path, title, 0);
if(data->image_sequence == 0)
{
stream = hb_stream_open(data->h, data->path, title, 0);
}
else
{
stream = hb_sequence_open(data->h, data->path, data->sequence_framerate);
}
}

if (title->video_codec == WORK_NONE)
Expand Down