From acd1ee1989549ecd48ee896a3e1d2158c92d6609 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 12 Apr 2015 14:26:39 +0200 Subject: Added support for exporting mp4 chapter marks The mp4 file format supports chapter marks using the so called mp4chaps format to enable chapter wise navigation in an mp4 file. The format is like hh:mm:ss.sss Chapter Title This commit adds the ability to export those kind of chapter marks along with TOC and CUE marks. The filename extension for the chapter mark file is "chapters.txt". The format specification description is "MP4ch". --- libs/ardour/export_handler.cc | 54 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'libs/ardour/export_handler.cc') diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc index b44c46e549..33e19d663f 100644 --- a/libs/ardour/export_handler.cc +++ b/libs/ardour/export_handler.cc @@ -305,6 +305,10 @@ ExportHandler::finish_timespan () export_cd_marker_file (current_timespan, fmt, filename, CDMarkerTOC); } + if (fmt->with_mp4chaps()) { + export_cd_marker_file (current_timespan, fmt, filename, MP4Chaps); + } + if (fmt->tag()) { AudiofileTagger::tag_file(filename, *SessionMetadata::Metadata()); } @@ -403,6 +407,11 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp track_func = &ExportHandler::write_track_info_cue; index_func = &ExportHandler::write_index_info_cue; break; + case MP4Chaps: + header_func = &ExportHandler::write_mp4ch_header; + track_func = &ExportHandler::write_track_info_mp4ch; + index_func = &ExportHandler::write_index_info_mp4ch; + break; default: return; } @@ -500,17 +509,19 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp string ExportHandler::get_cd_marker_filename(std::string filename, CDMarkerFormat format) { - /* do not strip file suffix because there may be more than one format, + /* do not strip file suffix because there may be more than one format, and we do not want the CD marker file from one format to overwrite another (e.g. foo.wav.cue > foo.aiff.cue) */ switch (format) { - case CDMarkerTOC: + case CDMarkerTOC: return filename + ".toc"; - case CDMarkerCUE: + case CDMarkerCUE: return filename + ".cue"; - default: + case MP4Chaps: + return filename + ".chapters.txt"; + default: return filename + ".marker"; // Should not be reached when actually creating a file } } @@ -589,6 +600,11 @@ ExportHandler::write_toc_header (CDMarkerStatus & status) status.out << " }" << endl << "}" << endl; } +void +ExportHandler::write_mp4ch_header (CDMarkerStatus & status) +{ +} + void ExportHandler::write_track_info_cue (CDMarkerStatus & status) { @@ -693,6 +709,14 @@ ExportHandler::write_track_info_toc (CDMarkerStatus & status) status.out << "START" << buf << endl; } +void ExportHandler::write_track_info_mp4ch (CDMarkerStatus & status) +{ + gchar buf[18]; + + frames_to_chapter_marks_string(buf, status.track_start_frame); + status.out << buf << " " << status.marker->name() << endl; +} + void ExportHandler::write_index_info_cue (CDMarkerStatus & status) { @@ -715,6 +739,11 @@ ExportHandler::write_index_info_toc (CDMarkerStatus & status) status.out << "INDEX" << buf << endl; } +void +ExportHandler::write_index_info_mp4ch (CDMarkerStatus & status) +{ +} + void ExportHandler::frames_to_cd_frames_string (char* buf, framepos_t when) { @@ -730,6 +759,23 @@ ExportHandler::frames_to_cd_frames_string (char* buf, framepos_t when) sprintf (buf, " %02d:%02d:%02d", mins, secs, frames); } +void +ExportHandler::frames_to_chapter_marks_string (char* buf, framepos_t when) +{ + framecnt_t remainder; + framecnt_t fr = session.nominal_frame_rate(); + int hours, mins, secs, msecs; + + hours = when / (3600 * fr); + remainder = when - (hours * 3600 * fr); + mins = remainder / (60 * fr); + remainder -= mins * 60 * fr; + secs = remainder / fr; + remainder -= secs * fr; + msecs = (remainder * 1000) / fr; + sprintf (buf, "%02d:%02d:%02d.%03d", hours, mins, secs, msecs); +} + std::string ExportHandler::toc_escape_cdtext (const std::string& txt) { -- cgit v1.2.3