Preserve the track matrix.
This commit is contained in:
5 files changed
+50
-64
No files matched your search
@@ -127,6 +127,8 @@
|
|||||||
videoTrack.width = naturalSize.width;
|
videoTrack.width = naturalSize.width;
|
||||||
videoTrack.height = naturalSize.height;
|
videoTrack.height = naturalSize.height;
|
||||||
|
|
||||||
|
videoTrack.transform = track.preferredTransform;
|
||||||
|
|
||||||
if (formatDescription) {
|
if (formatDescription) {
|
||||||
|
|
||||||
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
|
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
|
||||||
|
|||||||
+15
-20
@@ -332,7 +332,8 @@
|
|||||||
NSSize subSize = NSMakeSize(0, 0);
|
NSSize subSize = NSMakeSize(0, 0);
|
||||||
NSSize videoSize = NSMakeSize(0, 0);
|
NSSize videoSize = NSMakeSize(0, 0);
|
||||||
|
|
||||||
NSInteger vPlacement = [(MP42SubtitleTrack*)track verticalPlacement];
|
MP42SubtitleTrack *subTrack = (MP42SubtitleTrack *)track;
|
||||||
|
NSInteger vPlacement = subTrack.verticalPlacement;
|
||||||
|
|
||||||
for (id workingTrack in _workingTracks) {
|
for (id workingTrack in _workingTracks) {
|
||||||
if ([workingTrack isMemberOfClass:[MP42VideoTrack class]]) {
|
if ([workingTrack isMemberOfClass:[MP42VideoTrack class]]) {
|
||||||
@@ -354,8 +355,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!vPlacement) {
|
if (!vPlacement) {
|
||||||
if ([(MP42SubtitleTrack*)track trackHeight])
|
if (subTrack.trackHeight)
|
||||||
subSize.height = [(MP42SubtitleTrack*)track trackHeight];
|
subSize.height = subTrack.trackHeight;
|
||||||
else
|
else
|
||||||
subSize.height = 0.15 * videoSize.height;
|
subSize.height = 0.15 * videoSize.height;
|
||||||
}
|
}
|
||||||
@@ -367,16 +368,18 @@
|
|||||||
dstTrackId = MP4AddSubtitleTrack(_fileHandle, timeScale, videoSize.width, subSize.height);
|
dstTrackId = MP4AddSubtitleTrack(_fileHandle, timeScale, videoSize.width, subSize.height);
|
||||||
|
|
||||||
MP4SetTrackDurationPerChunk(_fileHandle, dstTrackId, timeScale / 8);
|
MP4SetTrackDurationPerChunk(_fileHandle, dstTrackId, timeScale / 8);
|
||||||
MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "tkhd.alternate_group", 2);
|
|
||||||
MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "tkhd.layer", -1);
|
MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "tkhd.layer", -1);
|
||||||
|
|
||||||
int32_t displayFlags = 0;
|
int32_t displayFlags = 0;
|
||||||
if (vPlacement)
|
if (vPlacement) {
|
||||||
displayFlags = 0x20000000;
|
displayFlags = 0x20000000;
|
||||||
if ([(MP42SubtitleTrack *)track someSamplesAreForced])
|
}
|
||||||
|
if (subTrack.someSamplesAreForced) {
|
||||||
displayFlags |= 0x40000000;
|
displayFlags |= 0x40000000;
|
||||||
if ([(MP42SubtitleTrack *)track allSamplesAreForced])
|
}
|
||||||
|
if (subTrack.allSamplesAreForced) {
|
||||||
displayFlags |= 0xC0000000;
|
displayFlags |= 0xC0000000;
|
||||||
|
}
|
||||||
|
|
||||||
MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.displayFlags", displayFlags);
|
MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.displayFlags", displayFlags);
|
||||||
|
|
||||||
@@ -400,21 +403,13 @@
|
|||||||
|
|
||||||
/* translate the track */
|
/* translate the track */
|
||||||
if (!vPlacement) {
|
if (!vPlacement) {
|
||||||
uint8_t* val;
|
CGAffineTransform transform = subTrack.transform;
|
||||||
uint8_t nval[36];
|
transform.ty = videoSize.height * 0.85;
|
||||||
uint32_t *ptr32 = (uint32_t*) nval;
|
subTrack.transform = transform;
|
||||||
uint32_t size;
|
|
||||||
|
|
||||||
MP4GetTrackBytesProperty(_fileHandle, dstTrackId, "tkhd.matrix", &val, &size);
|
|
||||||
memcpy(nval, val, size);
|
|
||||||
ptr32[7] = CFSwapInt32HostToBig( (videoSize.height * 0.85) * 0x10000);
|
|
||||||
|
|
||||||
MP4SetTrackBytesProperty(_fileHandle, dstTrackId, "tkhd.matrix", nval, size);
|
|
||||||
free(val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[(MP42SubtitleTrack*)track setTrackWidth:videoSize.width];
|
subTrack.trackWidth = videoSize.width;
|
||||||
[(MP42SubtitleTrack*)track setTrackHeight:subSize.height];
|
subTrack.trackHeight = subSize.height;
|
||||||
|
|
||||||
[helper->importer setActiveTrack:track];
|
[helper->importer setActiveTrack:track];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,26 +105,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self.edited && !self.muxed) {
|
if (self.edited && !self.muxed) {
|
||||||
float trackWidth, trackHeight;
|
|
||||||
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.width", &trackWidth);
|
|
||||||
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.height", &trackHeight);
|
|
||||||
|
|
||||||
self.trackWidth = trackWidth;
|
|
||||||
self.trackHeight = trackHeight;
|
|
||||||
|
|
||||||
uint8_t *val;
|
|
||||||
uint8_t nval[36];
|
|
||||||
uint32_t *ptr32 = (uint32_t*) nval;
|
|
||||||
uint32_t size;
|
|
||||||
|
|
||||||
MP4GetTrackBytesProperty(fileHandle ,self.trackId, "tkhd.matrix", &val, &size);
|
|
||||||
memcpy(nval, val, size);
|
|
||||||
self.offsetX = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
|
||||||
self.offsetY = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
|
||||||
free(val);
|
|
||||||
|
|
||||||
[super writeToFile:fileHandle error:outError];
|
[super writeToFile:fileHandle error:outError];
|
||||||
|
|
||||||
return self.trackId;
|
return self.trackId;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
@property(nonatomic, readwrite) float trackWidth;
|
@property(nonatomic, readwrite) float trackWidth;
|
||||||
@property(nonatomic, readwrite) float trackHeight;
|
@property(nonatomic, readwrite) float trackHeight;
|
||||||
|
|
||||||
|
@property(nonatomic, readwrite) CGAffineTransform transform;
|
||||||
|
|
||||||
@property(nonatomic, readwrite) uint16_t colorPrimaries;
|
@property(nonatomic, readwrite) uint16_t colorPrimaries;
|
||||||
@property(nonatomic, readwrite) uint16_t transferCharacteristics;
|
@property(nonatomic, readwrite) uint16_t transferCharacteristics;
|
||||||
@property(nonatomic, readwrite) uint16_t matrixCoefficients;
|
@property(nonatomic, readwrite) uint16_t matrixCoefficients;
|
||||||
@@ -33,9 +35,6 @@
|
|||||||
@property(nonatomic, readwrite) uint64_t vertOffN;
|
@property(nonatomic, readwrite) uint64_t vertOffN;
|
||||||
@property(nonatomic, readwrite) uint64_t vertOffD;
|
@property(nonatomic, readwrite) uint64_t vertOffD;
|
||||||
|
|
||||||
@property(nonatomic, readwrite) uint32_t offsetX;
|
|
||||||
@property(nonatomic, readwrite) uint32_t offsetY;
|
|
||||||
|
|
||||||
@property(nonatomic, readwrite) uint8_t origProfile;
|
@property(nonatomic, readwrite) uint8_t origProfile;
|
||||||
@property(nonatomic, readwrite) uint8_t origLevel;
|
@property(nonatomic, readwrite) uint8_t origLevel;
|
||||||
@property(nonatomic, readwrite) uint8_t newProfile;
|
@property(nonatomic, readwrite) uint8_t newProfile;
|
||||||
|
|||||||
+31
-22
@@ -31,9 +31,6 @@
|
|||||||
uint64_t _horizOffN, _horizOffD;
|
uint64_t _horizOffN, _horizOffD;
|
||||||
uint64_t _vertOffN, _vertOffD;
|
uint64_t _vertOffN, _vertOffD;
|
||||||
|
|
||||||
// Matrix
|
|
||||||
uint32_t _offsetX, _offsetY;
|
|
||||||
|
|
||||||
// H.264 profile
|
// H.264 profile
|
||||||
uint8_t _origProfile, _origLevel;
|
uint8_t _origProfile, _origLevel;
|
||||||
uint8_t _newProfile, _newLevel;
|
uint8_t _newProfile, _newLevel;
|
||||||
@@ -53,6 +50,8 @@
|
|||||||
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.width", &_trackWidth);
|
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.width", &_trackWidth);
|
||||||
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.height", &_trackHeight);
|
MP4GetTrackFloatProperty(fileHandle, self.trackId, "tkhd.height", &_trackHeight);
|
||||||
|
|
||||||
|
_transform = CGAffineTransformIdentity;
|
||||||
|
|
||||||
uint8_t *val;
|
uint8_t *val;
|
||||||
uint8_t nval[36];
|
uint8_t nval[36];
|
||||||
uint32_t *ptr32 = (uint32_t*) nval;
|
uint32_t *ptr32 = (uint32_t*) nval;
|
||||||
@@ -60,8 +59,12 @@
|
|||||||
|
|
||||||
MP4GetTrackBytesProperty(fileHandle ,self.trackId, "tkhd.matrix", &val, &size);
|
MP4GetTrackBytesProperty(fileHandle ,self.trackId, "tkhd.matrix", &val, &size);
|
||||||
memcpy(nval, val, size);
|
memcpy(nval, val, size);
|
||||||
_offsetX = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
_transform.a = CFSwapInt32BigToHost(ptr32[0]) / 0x10000;
|
||||||
_offsetY = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
_transform.b = CFSwapInt32BigToHost(ptr32[1]) / 0x10000;
|
||||||
|
_transform.c = CFSwapInt32BigToHost(ptr32[3]) / 0x10000;
|
||||||
|
_transform.d = CFSwapInt32BigToHost(ptr32[4]) / 0x10000;
|
||||||
|
_transform.tx = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
||||||
|
_transform.ty = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
||||||
free(val);
|
free(val);
|
||||||
|
|
||||||
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp")) {
|
if (MP4HaveTrackAtom(fileHandle, self.trackId, "mdia.minf.stbl.stsd.*.pasp")) {
|
||||||
@@ -116,6 +119,7 @@
|
|||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
self.mediaType = kMP42MediaType_Video;
|
self.mediaType = kMP42MediaType_Video;
|
||||||
|
_transform = CGAffineTransformIdentity;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -140,8 +144,12 @@
|
|||||||
|
|
||||||
MP4GetTrackBytesProperty(fileHandle ,self.trackId, "tkhd.matrix", &val, &size);
|
MP4GetTrackBytesProperty(fileHandle ,self.trackId, "tkhd.matrix", &val, &size);
|
||||||
memcpy(nval, val, size);
|
memcpy(nval, val, size);
|
||||||
ptr32[6] = CFSwapInt32HostToBig(_offsetX * 0x10000);
|
ptr32[0] = CFSwapInt32HostToBig(_transform.a * 0x10000);
|
||||||
ptr32[7] = CFSwapInt32HostToBig(_offsetY * 0x10000);
|
ptr32[1] = CFSwapInt32HostToBig(_transform.b * 0x10000);
|
||||||
|
ptr32[3] = CFSwapInt32HostToBig(_transform.c * 0x10000);
|
||||||
|
ptr32[4] = CFSwapInt32HostToBig(_transform.d * 0x10000);
|
||||||
|
ptr32[6] = CFSwapInt32HostToBig(_transform.tx * 0x10000);
|
||||||
|
ptr32[7] = CFSwapInt32HostToBig(_transform.ty * 0x10000);
|
||||||
MP4SetTrackBytesProperty(fileHandle, self.trackId, "tkhd.matrix", nval, size);
|
MP4SetTrackBytesProperty(fileHandle, self.trackId, "tkhd.matrix", nval, size);
|
||||||
|
|
||||||
free(val);
|
free(val);
|
||||||
@@ -229,15 +237,9 @@
|
|||||||
self.edited = YES;
|
self.edited = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setOffsetX:(uint32_t)offsetX
|
- (void)setTransform:(CGAffineTransform)transform
|
||||||
{
|
{
|
||||||
_offsetX = offsetX;
|
_transform = transform;
|
||||||
self.edited = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setOffsetY:(uint32_t)offsetY
|
|
||||||
{
|
|
||||||
_offsetY = offsetY;
|
|
||||||
self.edited = YES;
|
self.edited = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +316,8 @@
|
|||||||
copy->_trackWidth = _trackWidth;
|
copy->_trackWidth = _trackWidth;
|
||||||
copy->_trackHeight = _trackHeight;
|
copy->_trackHeight = _trackHeight;
|
||||||
|
|
||||||
|
copy->_transform = _transform;
|
||||||
|
|
||||||
copy->_colorPrimaries = _colorPrimaries;
|
copy->_colorPrimaries = _colorPrimaries;
|
||||||
copy->_transferCharacteristics = _transferCharacteristics;
|
copy->_transferCharacteristics = _transferCharacteristics;
|
||||||
copy->_matrixCoefficients = _matrixCoefficients;
|
copy->_matrixCoefficients = _matrixCoefficients;
|
||||||
@@ -330,9 +334,6 @@
|
|||||||
copy->_vertOffN = _vertOffN;
|
copy->_vertOffN = _vertOffN;
|
||||||
copy->_vertOffD = _vertOffD;
|
copy->_vertOffD = _vertOffD;
|
||||||
|
|
||||||
copy->_offsetX = _offsetX;
|
|
||||||
copy->_offsetY = _offsetY;
|
|
||||||
|
|
||||||
copy->_origLevel = _origLevel;
|
copy->_origLevel = _origLevel;
|
||||||
copy->_origProfile = _origProfile;
|
copy->_origProfile = _origProfile;
|
||||||
copy->_newProfile = _newProfile;
|
copy->_newProfile = _newProfile;
|
||||||
@@ -368,8 +369,12 @@
|
|||||||
[coder encodeInt64:_hSpacing forKey:@"hSpacing"];
|
[coder encodeInt64:_hSpacing forKey:@"hSpacing"];
|
||||||
[coder encodeInt64:_vSpacing forKey:@"vSpacing"];
|
[coder encodeInt64:_vSpacing forKey:@"vSpacing"];
|
||||||
|
|
||||||
[coder encodeInt32:_offsetX forKey:@"offsetX"];
|
[coder encodeDouble:_transform.a forKey:@"transformA"];
|
||||||
[coder encodeInt32:_offsetY forKey:@"offsetY"];
|
[coder encodeDouble:_transform.b forKey:@"transformB"];
|
||||||
|
[coder encodeDouble:_transform.c forKey:@"transformC"];
|
||||||
|
[coder encodeDouble:_transform.d forKey:@"transformD"];
|
||||||
|
[coder encodeDouble:_transform.tx forKey:@"offsetX"];
|
||||||
|
[coder encodeDouble:_transform.ty forKey:@"offsetY"];
|
||||||
|
|
||||||
[coder encodeInt:_origProfile forKey:@"origProfile"];
|
[coder encodeInt:_origProfile forKey:@"origProfile"];
|
||||||
[coder encodeInt:_origLevel forKey:@"origLevel"];
|
[coder encodeInt:_origLevel forKey:@"origLevel"];
|
||||||
@@ -395,8 +400,12 @@
|
|||||||
_hSpacing = [decoder decodeInt64ForKey:@"hSpacing"];
|
_hSpacing = [decoder decodeInt64ForKey:@"hSpacing"];
|
||||||
_vSpacing = [decoder decodeInt64ForKey:@"vSpacing"];
|
_vSpacing = [decoder decodeInt64ForKey:@"vSpacing"];
|
||||||
|
|
||||||
_offsetX = [decoder decodeInt32ForKey:@"offsetX"];
|
_transform.a = [decoder decodeDoubleForKey:@"transformA"];
|
||||||
_offsetY = [decoder decodeInt32ForKey:@"offsetY"];
|
_transform.b = [decoder decodeDoubleForKey:@"transformB"];
|
||||||
|
_transform.c = [decoder decodeDoubleForKey:@"transformC"];
|
||||||
|
_transform.d = [decoder decodeDoubleForKey:@"transformD"];
|
||||||
|
_transform.tx = [decoder decodeDoubleForKey:@"offsetX"];
|
||||||
|
_transform.ty = [decoder decodeDoubleForKey:@"offsetY"];
|
||||||
|
|
||||||
_origProfile = [decoder decodeIntForKey:@"origProfile"];
|
_origProfile = [decoder decodeIntForKey:@"origProfile"];
|
||||||
_origLevel = [decoder decodeIntForKey:@"origLevel"];
|
_origLevel = [decoder decodeIntForKey:@"origLevel"];
|
||||||
|
|||||||
Reference in new issue
Block a user