Skip to content

Commit

Permalink
Add function for setting chapter info
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzoua committed Jun 11, 2010
1 parent 7ded52c commit 18d9f2c
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
38 changes: 38 additions & 0 deletions AudioBookBinder.xcodeproj/project.pbxproj
Expand Up @@ -37,9 +37,14 @@
9F86C0CF1023D99300E65B00 /* MP4Atom.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F86C0CE1023D99300E65B00 /* MP4Atom.m */; };
9F86C0D21023DAC000E65B00 /* MP4File.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F86C0D11023DAC000E65B00 /* MP4File.m */; };
9F95914211658710001C2433 /* iAudiobook256.icns in Resources */ = {isa = PBXBuildFile; fileRef = 9F95914111658710001C2433 /* iAudiobook256.icns */; };
9FA52D9211C2F100003FD879 /* AudioFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F6FA4A8111E56090047728F /* AudioFile.m */; };
9FAB146D11619F9F00A2F36A /* ExpandedPathToIconTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FAB146A11619F9F00A2F36A /* ExpandedPathToIconTransformer.m */; };
9FAB146E11619F9F00A2F36A /* ExpandedPathToPathTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FAB146C11619F9F00A2F36A /* ExpandedPathToPathTransformer.m */; };
9FAB14821161A51400A2F36A /* PrefsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FAB14811161A51400A2F36A /* PrefsController.m */; };
9FB4DE0711C05C0E007B3DDE /* MetaEditor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9FB4DE0611C05C0E007B3DDE /* MetaEditor.mm */; };
9FB4DE0811C05C0E007B3DDE /* MetaEditor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9FB4DE0611C05C0E007B3DDE /* MetaEditor.mm */; };
9FB4DE3A11C0610F007B3DDE /* libmp4v2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FB4DE3911C0610F007B3DDE /* libmp4v2.a */; };
9FB4DE3B11C0610F007B3DDE /* libmp4v2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FB4DE3911C0610F007B3DDE /* libmp4v2.a */; };
9FBCBF46102A6A2C0067AE9F /* ConsoleDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FBCBF45102A6A2C0067AE9F /* ConsoleDelegate.m */; };
9FFED9901128C1AD00C3AFE6 /* NSOutlineView_Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FFED98F1128C1AD00C3AFE6 /* NSOutlineView_Extension.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -109,6 +114,9 @@
9FAB146C11619F9F00A2F36A /* ExpandedPathToPathTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExpandedPathToPathTransformer.m; sourceTree = "<group>"; };
9FAB14801161A51400A2F36A /* PrefsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrefsController.h; sourceTree = "<group>"; };
9FAB14811161A51400A2F36A /* PrefsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrefsController.m; sourceTree = "<group>"; };
9FB4DE0511C05C0E007B3DDE /* MetaEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MetaEditor.h; sourceTree = "<group>"; };
9FB4DE0611C05C0E007B3DDE /* MetaEditor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MetaEditor.mm; sourceTree = "<group>"; };
9FB4DE3911C0610F007B3DDE /* libmp4v2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmp4v2.a; path = /opt/local/lib/libmp4v2.a; sourceTree = "<absolute>"; };
9FBCBF44102A6A2C0067AE9F /* ConsoleDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConsoleDelegate.h; sourceTree = "<group>"; };
9FBCBF45102A6A2C0067AE9F /* ConsoleDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConsoleDelegate.m; sourceTree = "<group>"; };
9FFED98E1128C1AD00C3AFE6 /* NSOutlineView_Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSOutlineView_Extension.h; sourceTree = "<group>"; };
Expand All @@ -125,6 +133,7 @@
9F02CE19101EABCD00AE315D /* AudioToolbox.framework in Frameworks */,
9F02CE4C101EBB9600AE315D /* CoreServices.framework in Frameworks */,
9F02D007102161FD00AE315D /* QTKit.framework in Frameworks */,
9FB4DE3B11C0610F007B3DDE /* libmp4v2.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -137,6 +146,7 @@
9F6FA3A211191A4D0047728F /* CoreServices.framework in Frameworks */,
9F6FA3A311191A4D0047728F /* QTKit.framework in Frameworks */,
9F8238B71166B69000F6D1D8 /* Sparkle.framework in Frameworks */,
9FB4DE3A11C0610F007B3DDE /* libmp4v2.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -188,13 +198,16 @@
9FFED98F1128C1AD00C3AFE6 /* NSOutlineView_Extension.m */,
9F62872A1194D502000D3A05 /* CoverImageView.h */,
9F62872B1194D502000D3A05 /* CoverImageView.m */,
9FB4DE0511C05C0E007B3DDE /* MetaEditor.h */,
9FB4DE0611C05C0E007B3DDE /* MetaEditor.mm */,
);
name = Source;
sourceTree = "<group>";
};
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
9FB4DE3911C0610F007B3DDE /* libmp4v2.a */,
9F02D006102161FD00AE315D /* QTKit.framework */,
9F02CE4B101EBB9600AE315D /* CoreServices.framework */,
9F02CE18101EABCD00AE315D /* AudioToolbox.framework */,
Expand Down Expand Up @@ -334,6 +347,8 @@
9F86C0CF1023D99300E65B00 /* MP4Atom.m in Sources */,
9F86C0D21023DAC000E65B00 /* MP4File.m in Sources */,
9FBCBF46102A6A2C0067AE9F /* ConsoleDelegate.m in Sources */,
9FB4DE0811C05C0E007B3DDE /* MetaEditor.mm in Sources */,
9FA52D9211C2F100003FD879 /* AudioFile.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -354,6 +369,7 @@
9FAB146E11619F9F00A2F36A /* ExpandedPathToPathTransformer.m in Sources */,
9FAB14821161A51400A2F36A /* PrefsController.m in Sources */,
9F62872C1194D502000D3A05 /* CoverImageView.m in Sources */,
9FB4DE0711C05C0E007B3DDE /* MetaEditor.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -393,6 +409,10 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = AudioBookBinder_Prefix.pch;
INSTALL_PATH = /usr/local/bin;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
/opt/local/lib,
);
PRODUCT_NAME = abbinder;
};
name = Debug;
Expand All @@ -406,6 +426,10 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = AudioBookBinder_Prefix.pch;
INSTALL_PATH = /usr/local/bin;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
/opt/local/lib,
);
PRODUCT_NAME = abbinder;
};
name = Release;
Expand All @@ -419,8 +443,11 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = NO;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /opt/local/include/;
LIBRARY_SEARCH_PATHS = /opt/local/lib/;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO;
PRODUCT_NAME = AudioBookBinder;
SDKROOT = macosx10.5;
};
Expand All @@ -433,7 +460,10 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /opt/local/include/;
LIBRARY_SEARCH_PATHS = /opt/local/lib/;
PREBINDING = NO;
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO;
PRODUCT_NAME = abbinder;
SDKROOT = macosx10.5;
};
Expand All @@ -456,6 +486,10 @@
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
INFOPLIST_FILE = "AudioBookBinder-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
/opt/local/lib,
);
OTHER_LDFLAGS = (
"-framework",
Foundation,
Expand Down Expand Up @@ -483,6 +517,10 @@
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
INFOPLIST_FILE = "AudioBookBinder-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
/opt/local/lib,
);
OTHER_LDFLAGS = (
"-framework",
Foundation,
Expand Down
19 changes: 19 additions & 0 deletions MetaEditor.h
@@ -0,0 +1,19 @@
/*
* MetaEditor.h
* AudioBookBinder
*
* Created by Oleksandr Tymoshenko on 10-06-09.
* Copyright 2010 Bluezbox Software. All rights reserved.
*
*/
#ifndef __METAEDITOR__
#define __METAEDITOR__

typedef struct {
uint32_t duration; // milliseconds
char title[1024];
} Chapter;

int addChapters(const char *mp4, Chapter *chapters, int count);

#endif // __METAEDITOR__
84 changes: 84 additions & 0 deletions MetaEditor.mm
@@ -0,0 +1,84 @@
/*
* MetaEditor.cpp
* AudioBookBinder
*
* Created by Oleksandr Tymoshenko on 10-06-09.
* Copyright 2010 Bluezbox Software. All rights reserved.
*
*/

extern "C" {
#include "MetaEditor.h"
};
#include <vector>
#include <mp4v2/mp4v2.h>

using namespace std;
const double CHAPTERTIMESCALE = 1000.0;

extern "C" int setBookInfo(const char *mp4, const char *author, const char *title)
{
MP4FileHandle h = MP4Modify( mp4 );
fprintf( stderr, "Begin\n");
if ( h == MP4_INVALID_FILE_HANDLE ) {
fprintf( stderr, "Could not open '%s'... aborting\n", mp4 );
return -1;
}
/* Read out the existing metadata */
const MP4Tags* mdata = MP4TagsAlloc();
MP4TagsFetch(mdata, h);
MP4TagsSetArtist(mdata, author);
/* Write out all tag modifications, free and close */
MP4TagsStore( mdata, h );
MP4TagsFree( mdata );
MP4Close( h );
fprintf( stderr, "Done\n");

return 0;
}

int addChapters(const char *mp4, Chapter *chapters, int count)
{
MP4FileHandle h = MP4Modify( mp4 );

if( h == MP4_INVALID_FILE_HANDLE )
return -1;


MP4TrackId refTrackId = MP4_INVALID_TRACK_ID;
uint32_t trackCount = MP4GetNumberOfTracks( h );

for( uint32_t i = 0; i < trackCount; ++i )
{
MP4TrackId id = MP4FindTrackId( h, i );
const char* type = MP4GetTrackType( h, id );
if( MP4_IS_AUDIO_TRACK_TYPE( type ) )
{
refTrackId = id;
break;
}
}

if( !MP4_IS_VALID_TRACK_ID(refTrackId) )
return -1;

MP4Duration trackDuration = MP4GetTrackDuration( h, refTrackId );
uint32_t trackTimeScale = MP4GetTrackTimeScale( h, refTrackId );
NSLog(@"duration: %ld scale: %d", trackDuration, trackTimeScale);
trackDuration /= trackTimeScale;
vector<MP4Chapter_t> mp4chapters;

for (int i = 0; i < count; i++)
{
MP4Chapter_t chap;
chap.duration = chapters[i].duration;
strncpy(chap.title, chapters[i].title, sizeof(chap.title)-1);

mp4chapters.push_back( chap );
}

MP4SetChapters(h, &mp4chapters[0], mp4chapters.size(), MP4ChapterTypeQt);
MP4Close(h);

return 0;
}

0 comments on commit 18d9f2c

Please sign in to comment.