Moved some functions to the public MP42Utilities.

This commit is contained in:
Damiano Galassi committed 2013-11-16 14:01:14 +01:00
1 parent 08e32323ce
commit 7611af9ce4
5 files changed
+92 -97

No files matched your search

+1 -9
View File
@@ -8,6 +8,7 @@
*/
#import <Foundation/Foundation.h>
#import "MP42Utilities.h"
#include "mp4v2.h"
typedef enum { TRACK_DISABLED = 0x0,
@@ -18,8 +19,6 @@ typedef enum { TRACK_DISABLED = 0x0,
} track_header_flags;
NSString* SRTStringFromTime( long long time, long timeScale , const char separator);
NSString* SMPTEStringFromTime(long long time, long timeScale);
MP4Duration TimeFromSMPTEString( NSString* SMPTE_string, MP4Duration timeScale );
int MP4SetTrackEnabled(MP4FileHandle fileHandle, MP4TrackId trackId);
int MP4SetTrackDisabled(MP4FileHandle fileHandle, MP4TrackId trackId);
@@ -28,7 +27,6 @@ int updateTracksCount(MP4FileHandle fileHandle);
void updateMoovDuration(MP4FileHandle fileHandle);
uint64_t getTrackSize(MP4FileHandle fileHandle, MP4TrackId trackId);
int isHdVideo(uint64_t width, uint64_t height);
MP4TrackId findChapterTrackId(MP4FileHandle fileHandle);
MP4TrackId findChapterPreviewTrackId(MP4FileHandle fileHandle);
@@ -50,12 +48,6 @@ CFDataRef createDescExt_XiphFLAC(UInt32 codecPrivateSize, const void * codecPriv
int readAC3Config(uint64_t acmod, uint64_t lfeon, UInt32 *channelsCount, UInt32 *channelLayoutTag);
BOOL isTrackMuxable(NSString * formatName);
BOOL trackNeedConversion(NSString * formatName);
NSArray *supportedFileFormat();
BOOL isFileFormatSupported(NSString * fileExt);
int64_t getTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id);
void setTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id, int64_t offset);
int copyTrackEditLists (MP4FileHandle fileHandle, MP4TrackId srcTrackId, MP4TrackId dstTrackId);
-83
View File
@@ -41,42 +41,6 @@ NSString* SRTStringFromTime( long long time, long timeScale , const char separat
return SRT_string;
}
NSString* SMPTEStringFromTime( long long time, long timeScale )
{
NSString *SMPTE_string;
int hour, minute, second, frame;
long long result;
result = time / timeScale; // second
frame = (time % timeScale) / 10;
second = result % 60;
result = result / 60; // minute
minute = result % 60;
result = result / 60; // hour
hour = result % 24;
SMPTE_string = [NSString stringWithFormat:@"%d:%02d:%02d:%02d", hour, minute, second, frame]; // h:mm:ss:ff
return SMPTE_string;
}
MP4Duration TimeFromSMPTEString( NSString* SMPTE_string, MP4Duration timeScale )
{
int hour, minute, second, frame;
MP4Duration timeval;
sscanf([SMPTE_string UTF8String], "%d:%02d:%02d:%02d",&hour, &minute, &second, &frame);
timeval = hour * 60 * 60 + minute * 60 + second;
timeval = timeScale * timeval + ( frame * 10 );
return timeval;
}
int MP4SetTrackEnabled(MP4FileHandle fileHandle, MP4TrackId trackId)
{
return MP4SetTrackIntegerProperty(fileHandle, trackId, "tkhd.flags", (TRACK_ENABLED | TRACK_IN_MOVIE));
@@ -127,16 +91,6 @@ uint64_t getTrackSize(MP4FileHandle fileHandle, MP4TrackId trackId)
return dataLength;
}
int isHdVideo(uint64_t width, uint64_t height)
{
if ((width > 1280) || (height > 720))
return 2;
else if (((width >= 960) && (height >= 720)) || width >= 1280)
return 1;
return 0;
}
MP4TrackId findChapterTrackId(MP4FileHandle fileHandle)
{
MP4TrackId trackId = 0;
@@ -695,43 +649,6 @@ int readAC3Config(uint64_t acmod, uint64_t lfeon, UInt32 *channelsCount, UInt32
return 1;
}
BOOL isTrackMuxable(NSString * formatName)
{
NSArray* supportedFormats = [NSArray arrayWithObjects:MP42VideoFormatH264, MP42VideoFormatMPEG4Visual, MP42AudioFormatAAC, MP42AudioFormatALAC, MP42AudioFormatAC3, MP42AudioFormatDTS, MP42SubtitleFormatTx3g, MP42SubtitleFormatText, MP42ClosedCaptionFormatCEA608, MP42VideoFormatJPEG, MP42SubtitleFormatVobSub, nil];
for (NSString* type in supportedFormats)
if ([formatName isEqualToString:type])
return YES;
return NO;
}
BOOL trackNeedConversion(NSString * formatName) {
NSArray* supportedConversionFormats = [NSArray arrayWithObjects:MP42AudioFormatVorbis, MP42AudioFormatFLAC, MP42AudioFormatMP3, MP42AudioFormatTrueHD, MP42SubtitleFormatSSA, MP42SubtitleFormatText, MP42SubtitleFormatPGS, nil];
for (NSString* type in supportedConversionFormats)
if ([formatName isEqualToString:type])
return YES;
return NO;
}
NSArray *supportedFileFormat()
{
return [NSArray arrayWithObjects:@"scc", @"smi", @"txt", @"m4v", @"mp4", @"m4a", @"m4a", @"mov", @"mts", @"m2ts",
@"mkv", @"mka", @"mks", @"h264", @"264", @"idx", @"aac", @"ac3", @"srt", nil];
}
BOOL isFileFormatSupported(NSString * fileExt) {
NSArray *supportedFormat = supportedFileFormat();
for (NSString *type in supportedFormat)
if ([fileExt caseInsensitiveCompare:type] == NSOrderedSame)
return YES;
return NO;
}
int64_t getTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id)
{
int64_t offset = 0;
+1
View File
@@ -8,6 +8,7 @@
#import "MP42Track.h"
#import "MP42PrivateUtilities.h"
#import "MP42Utilities.h"
#import "MP42FileImporter.h"
#import "MP42Sample.h"
#import "MP42Fifo.h"
+10 -3
View File
@@ -6,8 +6,15 @@
// Copyright (c) 2013 Damiano Galassi. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MP42MediaFormat.h"
@interface MP42Utilities : NSObject
NSString * SMPTEStringFromTime(long long time, long timeScale);
MP42Duration TimeFromSMPTEString(NSString *SMPTE_string, MP42Duration timeScale);
@end
NSArray *supportedFileFormat();
BOOL isFileFormatSupported(NSString *fileExt);
BOOL isTrackMuxable(NSString * formatName);
BOOL trackNeedConversion(NSString * formatName);
int isHdVideo(uint64_t width, uint64_t height);
+80 -2
View File
@@ -8,6 +8,84 @@
#import "MP42Utilities.h"
@implementation MP42Utilities
NSString * SMPTEStringFromTime(long long time, long timeScale)
{
NSString *SMPTE_string;
int hour, minute, second, frame;
long long result;
@end
result = time / timeScale; // second
frame = (time % timeScale) / 10;
second = result % 60;
result = result / 60; // minute
minute = result % 60;
result = result / 60; // hour
hour = result % 24;
SMPTE_string = [NSString stringWithFormat:@"%d:%02d:%02d:%02d", hour, minute, second, frame]; // h:mm:ss:ff
return SMPTE_string;
}
MP42Duration TimeFromSMPTEString(NSString* SMPTE_string, MP42Duration timeScale)
{
int hour, minute, second, frame;
MP42Duration timeval;
sscanf([SMPTE_string UTF8String], "%d:%02d:%02d:%02d",&hour, &minute, &second, &frame);
timeval = hour * 60 * 60 + minute * 60 + second;
timeval = timeScale * timeval + ( frame * 10 );
return timeval;
}
NSArray *supportedFileFormat()
{
return [NSArray arrayWithObjects:@"scc", @"smi", @"txt", @"m4v", @"mp4", @"m4a", @"m4a", @"mov", @"mts", @"m2ts",
@"mkv", @"mka", @"mks", @"h264", @"264", @"idx", @"aac", @"ac3", @"srt", nil];
}
BOOL isFileFormatSupported(NSString * fileExt) {
NSArray *supportedFormat = supportedFileFormat();
for (NSString *type in supportedFormat)
if ([fileExt caseInsensitiveCompare:type] == NSOrderedSame)
return YES;
return NO;
}
BOOL isTrackMuxable(NSString * formatName)
{
NSArray* supportedFormats = [NSArray arrayWithObjects:MP42VideoFormatH264, MP42VideoFormatMPEG4Visual, MP42AudioFormatAAC, MP42AudioFormatALAC, MP42AudioFormatAC3, MP42AudioFormatDTS, MP42SubtitleFormatTx3g, MP42SubtitleFormatText, MP42ClosedCaptionFormatCEA608, MP42VideoFormatJPEG, MP42SubtitleFormatVobSub, nil];
for (NSString* type in supportedFormats)
if ([formatName isEqualToString:type])
return YES;
return NO;
}
BOOL trackNeedConversion(NSString * formatName) {
NSArray* supportedConversionFormats = [NSArray arrayWithObjects:MP42AudioFormatVorbis, MP42AudioFormatFLAC, MP42AudioFormatMP3, MP42AudioFormatTrueHD, MP42SubtitleFormatSSA, MP42SubtitleFormatText, MP42SubtitleFormatPGS, nil];
for (NSString* type in supportedConversionFormats)
if ([formatName isEqualToString:type])
return YES;
return NO;
}
int isHdVideo(uint64_t width, uint64_t height)
{
if ((width > 1280) || (height > 720))
return 2;
else if (((width >= 960) && (height >= 720)) || width >= 1280)
return 1;
return 0;
}