Fix raw h.264 frame rate.
This commit is contained in:
1 parent
1d100a1db0
commit
d449f75d15
6 files changed
+136
-25
No files matched your search
@@ -13,11 +13,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@class MP42SampleBuffer;
|
@class MP42SampleBuffer;
|
||||||
@class MP42AudioTrack;
|
@class MP42AudioTrack;
|
||||||
@class MP42ConversionSettings;
|
@class MP42AudioConversionSettings;
|
||||||
|
|
||||||
@interface MP42AudioConverter : NSObject <MP42ConverterProtocol>
|
@interface MP42AudioConverter : NSObject <MP42ConverterProtocol>
|
||||||
|
|
||||||
- (instancetype)initWithTrack:(MP42AudioTrack *)track settings:(MP42ConversionSettings *)settings error:(NSError **)error;
|
- (instancetype)initWithTrack:(MP42AudioTrack *)track settings:(MP42AudioConversionSettings *)settings error:(NSError **)error;
|
||||||
|
|
||||||
- (void)addSample:(MP42SampleBuffer *)sample;
|
- (void)addSample:(MP42SampleBuffer *)sample;
|
||||||
- (nullable MP42SampleBuffer *)copyEncodedSample;
|
- (nullable MP42SampleBuffer *)copyEncodedSample;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#pragma mark - Init
|
#pragma mark - Init
|
||||||
|
|
||||||
- (instancetype)initWithTrack:(MP42AudioTrack *)track settings:(MP42ConversionSettings *)settings error:(NSError **)error
|
- (instancetype)initWithTrack:(MP42AudioTrack *)track settings:(MP42AudioConversionSettings *)settings error:(NSError **)error
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@interface MP42ConversionSettings : NSObject <NSCopying, NSSecureCoding>
|
@interface MP42ConversionSettings : NSObject <NSCopying, NSSecureCoding>
|
||||||
|
|
||||||
+ (instancetype)audioConversionWithBitRate:(NSUInteger)bitrate mixDown:(NSString *)mixDown drc:(float)drc;
|
|
||||||
+ (instancetype)subtitlesConversion;
|
+ (instancetype)subtitlesConversion;
|
||||||
|
|
||||||
@property (nonatomic, readonly) FourCharCode format;
|
@property (nonatomic, readonly) FourCharCode format;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MP42AudioConversionSettings : MP42ConversionSettings <NSCopying, NSSecureCoding>
|
||||||
|
|
||||||
|
+ (instancetype)audioConversionWithBitRate:(NSUInteger)bitrate mixDown:(NSString *)mixDown drc:(float)drc;
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSUInteger bitRate;
|
@property (nonatomic, readonly) NSUInteger bitRate;
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSString *mixDown;
|
@property (nonatomic, readonly) NSString *mixDown;
|
||||||
@@ -23,4 +29,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface MP42RawConversionSettings : MP42ConversionSettings <NSCopying, NSSecureCoding>
|
||||||
|
|
||||||
|
+ (instancetype)rawConversionWithFrameRate:(NSUInteger)frameRate;
|
||||||
|
|
||||||
|
@property (nonatomic, readonly) NSUInteger frameRate;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
+112
-17
@@ -11,24 +11,16 @@
|
|||||||
|
|
||||||
@implementation MP42ConversionSettings
|
@implementation MP42ConversionSettings
|
||||||
|
|
||||||
+ (instancetype)audioConversionWithBitRate:(NSUInteger)bitRate mixDown:(NSString *)mixDown drc:(float)drc
|
|
||||||
{
|
|
||||||
return [[MP42ConversionSettings alloc] initWitFormat:kMP42AudioCodecType_MPEG4AAC bitRate:bitRate mixDown:mixDown drc:drc];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (instancetype)subtitlesConversion
|
+ (instancetype)subtitlesConversion
|
||||||
{
|
{
|
||||||
return [[MP42ConversionSettings alloc] initWitFormat:kMP42SubtitleCodecType_3GText bitRate:0 mixDown:SBNoneMixdown drc:0];
|
return [[MP42ConversionSettings alloc] initWitFormat:kMP42SubtitleCodecType_3GText];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWitFormat:(FourCharCode)format bitRate:(NSUInteger)bitRate mixDown:(NSString *)mixDown drc:(float)drc
|
- (instancetype)initWitFormat:(FourCharCode)format
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
_format = format;
|
_format = format;
|
||||||
_bitRate = bitRate;
|
|
||||||
_mixDown = [mixDown copy];
|
|
||||||
_drc = drc;
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -41,9 +33,6 @@
|
|||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
copy->_format = _format;
|
copy->_format = _format;
|
||||||
copy->_bitRate = _bitRate;
|
|
||||||
copy->_mixDown = [_mixDown copy];
|
|
||||||
copy->_drc = _drc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
@@ -59,11 +48,7 @@
|
|||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
[coder encodeInt:1 forKey:@"MP42ConversionSettingsVersion"];
|
[coder encodeInt:1 forKey:@"MP42ConversionSettingsVersion"];
|
||||||
|
|
||||||
[coder encodeInteger:_format forKey:@"format"];
|
[coder encodeInteger:_format forKey:@"format"];
|
||||||
[coder encodeInteger:_bitRate forKey:@"bitRate"];
|
|
||||||
[coder encodeObject:_mixDown forKey:@"mixDown"];
|
|
||||||
[coder encodeFloat:_drc forKey:@"drc"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)decoder
|
- (id)initWithCoder:(NSCoder *)decoder
|
||||||
@@ -71,6 +56,63 @@
|
|||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
_format = [decoder decodeIntegerForKey:@"format"];
|
_format = [decoder decodeIntegerForKey:@"format"];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MP42AudioConversionSettings
|
||||||
|
|
||||||
|
+ (instancetype)audioConversionWithBitRate:(NSUInteger)bitRate mixDown:(NSString *)mixDown drc:(float)drc
|
||||||
|
{
|
||||||
|
return [[MP42AudioConversionSettings alloc] initWitFormat:kMP42AudioCodecType_MPEG4AAC bitRate:bitRate mixDown:mixDown drc:drc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWitFormat:(FourCharCode)format bitRate:(NSUInteger)bitRate mixDown:(NSString *)mixDown drc:(float)drc
|
||||||
|
{
|
||||||
|
self = [super initWitFormat:format];
|
||||||
|
if (self) {
|
||||||
|
_bitRate = bitRate;
|
||||||
|
_mixDown = [mixDown copy];
|
||||||
|
_drc = drc;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - NSCopying
|
||||||
|
|
||||||
|
- (instancetype)copyWithZone:(NSZone *)zone
|
||||||
|
{
|
||||||
|
MP42AudioConversionSettings *copy = [super copyWithZone:zone];
|
||||||
|
|
||||||
|
if (copy) {
|
||||||
|
copy->_bitRate = _bitRate;
|
||||||
|
copy->_mixDown = [_mixDown copy];
|
||||||
|
copy->_drc = _drc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - NSSecureCoding
|
||||||
|
|
||||||
|
+ (BOOL)supportsSecureCoding
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
|
{
|
||||||
|
[coder encodeInteger:_bitRate forKey:@"bitRate"];
|
||||||
|
[coder encodeObject:_mixDown forKey:@"mixDown"];
|
||||||
|
[coder encodeFloat:_drc forKey:@"drc"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)initWithCoder:(NSCoder *)decoder
|
||||||
|
{
|
||||||
|
self = [super initWithCoder:decoder];
|
||||||
|
|
||||||
_bitRate = [decoder decodeIntegerForKey:@"bitRate"];
|
_bitRate = [decoder decodeIntegerForKey:@"bitRate"];
|
||||||
_mixDown = [decoder decodeObjectOfClass:[NSString class] forKey:@"mixDown"];
|
_mixDown = [decoder decodeObjectOfClass:[NSString class] forKey:@"mixDown"];
|
||||||
_drc = [decoder decodeFloatForKey:@"drc"];
|
_drc = [decoder decodeFloatForKey:@"drc"];
|
||||||
@@ -79,3 +121,56 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation MP42RawConversionSettings
|
||||||
|
|
||||||
|
+ (instancetype)rawConversionWithFrameRate:(NSUInteger)frameRate
|
||||||
|
{
|
||||||
|
return [[MP42RawConversionSettings alloc] initWitFormat:kMP42VideoCodecType_H264 frameRate:frameRate];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWitFormat:(FourCharCode)format frameRate:(NSUInteger)frameRate
|
||||||
|
{
|
||||||
|
self = [super initWitFormat:format];
|
||||||
|
if (self) {
|
||||||
|
_frameRate = frameRate;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - NSCopying
|
||||||
|
|
||||||
|
- (instancetype)copyWithZone:(NSZone *)zone
|
||||||
|
{
|
||||||
|
MP42RawConversionSettings *copy = [super copyWithZone:zone];
|
||||||
|
|
||||||
|
if (copy) {
|
||||||
|
copy->_frameRate = _frameRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - NSSecureCoding
|
||||||
|
|
||||||
|
+ (BOOL)supportsSecureCoding
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
|
{
|
||||||
|
[coder encodeInteger:_frameRate forKey:@"frameRate"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)initWithCoder:(NSCoder *)decoder
|
||||||
|
{
|
||||||
|
self = [super initWithCoder:decoder];
|
||||||
|
|
||||||
|
_frameRate = [decoder decodeIntegerForKey:@"frameRate"];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@@ -1429,12 +1429,14 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
|||||||
MP42Track *track = self.inputTracks.lastObject;
|
MP42Track *track = self.inputTracks.lastObject;
|
||||||
MP4TrackId trackId = track.sourceId;
|
MP4TrackId trackId = track.sourceId;
|
||||||
|
|
||||||
framerate_t * framerate;
|
framerate_t *framerate;
|
||||||
int64_t currentSize = 0;
|
int64_t currentSize = 0;
|
||||||
|
|
||||||
for (framerate = (framerate_t*) framerates; framerate->code; framerate++)
|
for (framerate = (framerate_t *)framerates; framerate->code; framerate++) {
|
||||||
if([track sourceId] == framerate->code)
|
if ([track.conversionSettings frameRate] == framerate->code) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
timescale = framerate->timescale;
|
timescale = framerate->timescale;
|
||||||
mp4FrameDuration = framerate->duration;
|
mp4FrameDuration = framerate->duration;
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@
|
|||||||
// Setup the converters
|
// Setup the converters
|
||||||
if ([track isMemberOfClass:[MP42AudioTrack class]] && track.conversionSettings) {
|
if ([track isMemberOfClass:[MP42AudioTrack class]] && track.conversionSettings) {
|
||||||
MP42AudioConverter *audioConverter = [[MP42AudioConverter alloc] initWithTrack:(MP42AudioTrack *)track
|
MP42AudioConverter *audioConverter = [[MP42AudioConverter alloc] initWithTrack:(MP42AudioTrack *)track
|
||||||
settings:track.conversionSettings
|
settings:(MP42AudioConversionSettings *)track.conversionSettings
|
||||||
error:outError];
|
error:outError];
|
||||||
|
|
||||||
if (audioConverter == nil) {
|
if (audioConverter == nil) {
|
||||||
|
|||||||
Reference in new issue
Block a user