diff options
author | maurj <[email protected]> | 2007-03-23 16:08:12 +0000 |
---|---|---|
committer | maurj <[email protected]> | 2007-03-23 16:08:12 +0000 |
commit | d247bba2cb6161ada13d4930116f5a090eae9f51 (patch) | |
tree | 37ace515ac76830b9933f1f7b16131457017197c /libhb | |
parent | aac0c8376178c6c60c93edb018a328e9b5b20ac3 (diff) |
Added chapter markers in a chapter text track in mp4 files.
This option is turned off by default. It can be turned on in the CLI by specifying a "-m" or "--markers" option. it is not yet enabled as an option in the Mac GUI.
These chapter tracks are only detected by QuickTime if the file extension is .m4v. If the extension is .mp4, the chapter text track is ignored.
To this end, I have made test.c detect .m4v as a file extension for mp4 too.
This change has required a substantial change to the mp4v2 library patch. Until the precompiled contrib binaries are updated by Prigaux, try doing "./configure" and then "./jam" (which will build the native contribs, but fail to build UB versions of the apps), and then try "make internal" to compile a native version of the apps.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@440 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.h | 3 | ||||
-rw-r--r-- | libhb/muxmp4.c | 47 |
2 files changed, 48 insertions, 2 deletions
diff --git a/libhb/common.h b/libhb/common.h index a2be02a87..14f0719a8 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -94,6 +94,9 @@ struct hb_job_s int chapter_start; int chapter_end; + /* Include chapter marker track in mp4? */ + int chapter_markers; + /* Picture settings: crop: must be multiples of 2 (top/bottom/left/right) deinterlace: 0 or 1 diff --git a/libhb/muxmp4.c b/libhb/muxmp4.c index 357551ec6..458de7be3 100644 --- a/libhb/muxmp4.c +++ b/libhb/muxmp4.c @@ -23,6 +23,7 @@ struct hb_mux_object_s /* Cumulated durations so far, in timescale units (see MP4Mux) */ uint64_t sum_dur; + }; struct hb_mux_data_s @@ -141,14 +142,17 @@ static int MP4Init( hb_mux_object_t * m ) if(!MP4SetBytesProperty(m->file, "moov.trak.tkhd.reserved3", nval, size)) { hb_log("Problem setting transform matrix"); } - + } } /* end of transformation matrix */ + /* firstAudioTrack will be used to reference the first audio track when we add a chapter track */ + MP4TrackId firstAudioTrack; + /* add the audio tracks */ for( i = 0; i < hb_list_count( title->list_audio ); i++ ) { audio = hb_list_item( title->list_audio, i ); @@ -160,8 +164,47 @@ static int MP4Init( hb_mux_object_t * m ) MP4SetAudioProfileLevel( m->file, 0x0F ); MP4SetTrackESConfiguration( m->file, mux_data->track, audio->config.aac.bytes, audio->config.aac.length ); + + /* store a reference to the first audio track, + so we can use it to feed the chapter text track's sample rate */ + if (i == 0) { + firstAudioTrack = mux_data->track; + } + } + if (job->chapter_markers) { + + /* add a text track for the chapters */ + MP4TrackId textTrack; + + textTrack = MP4AddChapterTextTrack(m->file, firstAudioTrack); + + /* write the chapter markers for each selected chapter */ + char markerBuf[13]; + hb_chapter_t * chapter; + MP4Duration chapterDuration; + float fOrigDuration, fTimescale; + float fTSDuration; + + for( i = job->chapter_start - 1; i <= job->chapter_end - 1; i++ ) + { + chapter = hb_list_item( title->list_chapter, i ); + + fOrigDuration = chapter->duration; + fTimescale = job->arate; + fTSDuration = (fOrigDuration / 90000) * fTimescale; + chapterDuration = (MP4Duration)fTSDuration; + + sprintf(markerBuf, " Chapter %03i", i + 1); + markerBuf[0] = 0; + markerBuf[1] = 11; // "Chapter xxx" + MP4WriteSample(m->file, textTrack, (u_int8_t*)markerBuf, 13, chapterDuration, 0, true); + + } + + } + return 0; } @@ -196,8 +239,8 @@ static int MP4End( hb_mux_object_t * m ) { #if 0 hb_job_t * job = m->job; -#endif char filename[1024]; memset( filename, 0, 1024 ); +#endif MP4Close( m->file ); |