diff options
author | jstebbins <[email protected]> | 2015-02-04 18:12:23 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2015-02-04 18:12:23 +0000 |
commit | 088f1a40324ee53ac9be1e99984544edbc6e4683 (patch) | |
tree | 7a53644d62a273d4badcfc2870f63139431badae | |
parent | 887cf2902803ef75b8d7f487a592acc63b86789e (diff) |
mux: fix chapter timestamps, factor in video encoder delay
libav does not fix chapter timestamps for us, so we must do this until
I can figure out a good fix to libav.
git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/0.10.x@6873 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/internal.h | 2 | ||||
-rw-r--r-- | libhb/muxavformat.c | 23 |
2 files changed, 23 insertions, 2 deletions
diff --git a/libhb/internal.h b/libhb/internal.h index d6bbb7073..7e2379919 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -371,7 +371,7 @@ union hb_esconfig_u int sps_length; uint8_t pps[HB_CONFIG_MAX_SIZE]; int pps_length; - uint32_t init_delay; + int init_delay; } h264; struct diff --git a/libhb/muxavformat.c b/libhb/muxavformat.c index 9934c3551..814504c7d 100644 --- a/libhb/muxavformat.c +++ b/libhb/muxavformat.c @@ -47,6 +47,8 @@ struct hb_mux_object_s int ntracks; hb_mux_data_t ** tracks; + + int64_t chapter_delay; }; enum @@ -194,6 +196,7 @@ static int avformatInit( hb_mux_object_t * m ) job->mux_data = track; track->type = MUX_TYPE_VIDEO; + track->prev_chapter_tc = AV_NOPTS_VALUE; track->st = avformat_new_stream(m->oc, NULL); if (track->st == NULL) { @@ -963,7 +966,11 @@ static int add_chapter(hb_mux_object_t *m, int64_t start, int64_t end, char * ti chap->id = nchap; chap->time_base = m->time_base; - chap->start = start; + // libav does not currently have a good way to deal with chapters and + // delayed stream timestamps. It makes no corrections to the chapter + // track. A patch to libav would touch a lot of things, so for now, + // work around the issue here. + chap->start = start + m->chapter_delay; chap->end = end; av_dict_set(&chap->metadata, "title", title, 0); @@ -977,6 +984,20 @@ static int avformatMux(hb_mux_object_t *m, hb_mux_data_t *track, hb_buffer_t *bu hb_job_t *job = m->job; uint8_t sub_out[2048]; + if (track->type == MUX_TYPE_VIDEO && + track->prev_chapter_tc == AV_NOPTS_VALUE) + { + // Chapter timestamps are biased the same as video timestamps. + // This needs to be reflected in the initial chapter timestamp. + // + // TODO: Don't assume the first chapter is at 0. Pass the first + // chapter through the pipeline instead of dropping it as we + // currently do. + m->chapter_delay = av_rescale_q(m->job->config.h264.init_delay, + (AVRational){1,90000}, + track->st->time_base); + track->prev_chapter_tc = -m->chapter_delay; + } // We only compute dts duration for MP4 files if (track->type == MUX_TYPE_VIDEO && (job->mux & HB_MUX_MASK_MP4)) { |