summaryrefslogtreecommitdiffstats
path: root/libhb/muxmp4.c
diff options
context:
space:
mode:
authormaurj <[email protected]>2007-03-23 16:08:12 +0000
committermaurj <[email protected]>2007-03-23 16:08:12 +0000
commitd247bba2cb6161ada13d4930116f5a090eae9f51 (patch)
tree37ace515ac76830b9933f1f7b16131457017197c /libhb/muxmp4.c
parentaac0c8376178c6c60c93edb018a328e9b5b20ac3 (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/muxmp4.c')
-rw-r--r--libhb/muxmp4.c47
1 files changed, 45 insertions, 2 deletions
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 );