summaryrefslogtreecommitdiffstats
path: root/libhb/sync.c
diff options
context:
space:
mode:
authorjbrjake <[email protected]>2009-06-04 17:52:01 +0000
committerjbrjake <[email protected]>2009-06-04 17:52:01 +0000
commita9eb0fba5299b12a951f2116276ef3382c1ff50a (patch)
treea4ee5ec78bca4077b8de2c522ee600824ff1696e /libhb/sync.c
parent2c5699a0b597b55a6c6f7cc663e473dd4a7345e1 (diff)
Adds an interjob structure to preserve some encode data across jobs within an instance of libhb. This allows correcting the estimated bitrate/filesize of 2-pass encodes of variable framerate content, as the actual frame count is known after the first pass. Thanks for putting the idea into code, Shaya.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2482 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/sync.c')
-rw-r--r--libhb/sync.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/libhb/sync.c b/libhb/sync.c
index 8ae1b78e8..abcf11141 100644
--- a/libhb/sync.c
+++ b/libhb/sync.c
@@ -96,28 +96,37 @@ int syncInit( hb_work_object_t * w, hb_job_t * job )
pv->job = job;
pv->pts_offset = INT64_MIN;
- /* Calculate how many video frames we are expecting */
- if (job->pts_to_stop)
+ if( job->pass == 2 )
{
- duration = job->pts_to_stop + 90000;
- }
- else if( job->frame_to_stop )
- {
- /* Set the duration to a rough estimate */
- duration = ( job->frame_to_stop / ( job->vrate / job->vrate_base ) ) * 90000;
+ /* We already have an accurate frame count from pass 1 */
+ hb_interjob_t * interjob = hb_interjob_get( job->h );
+ pv->count_frames_max = interjob->frame_count;
}
else
{
- duration = 0;
- for( i = job->chapter_start; i <= job->chapter_end; i++ )
+ /* Calculate how many video frames we are expecting */
+ if ( job->pts_to_stop )
+ {
+ duration = job->pts_to_stop + 90000;
+ }
+ else if( job->frame_to_stop )
+ {
+ /* Set the duration to a rough estimate */
+ duration = ( job->frame_to_stop / ( job->vrate / job->vrate_base ) ) * 90000;
+ }
+ else
{
- chapter = hb_list_item( title->list_chapter, i - 1 );
- duration += chapter->duration;
+ duration = 0;
+ for( i = job->chapter_start; i <= job->chapter_end; i++ )
+ {
+ chapter = hb_list_item( title->list_chapter, i - 1 );
+ duration += chapter->duration;
+ }
+ duration += 90000;
+ /* 1 second safety so we're sure we won't miss anything */
}
- duration += 90000;
- /* 1 second safety so we're sure we won't miss anything */
+ pv->count_frames_max = duration * job->vrate / job->vrate_base / 90000;
}
- pv->count_frames_max = duration * job->vrate / job->vrate_base / 90000;
hb_log( "sync: expecting %d video frames", pv->count_frames_max );
pv->busy |= 1;
@@ -156,6 +165,16 @@ void syncClose( hb_work_object_t * w )
hb_log( "sync: got %d frames, %d expected",
pv->count_frames, pv->count_frames_max );
+ /* save data for second pass */
+ if( job->pass == 1 )
+ {
+ /* Preserve frame count for better accuracy in pass 2 */
+ hb_interjob_t * interjob = hb_interjob_get( job->h );
+ interjob->frame_count = pv->count_frames;
+ interjob->last_job = job->sequence_id;
+ interjob->total_time = pv->next_start;
+ }
+
if (pv->drops || pv->dups )
{
hb_log( "sync: %d frames dropped, %d duplicated", pv->drops, pv->dups );