Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This fixes the problem of transcoding HEVC encoded videos, leading to error code -1150 #164

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-video-editor",
"version": "1.1.3",
"version": "1.1.4",
"description": "Cordova Video Editor Plugin",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-video-editor" version="1.1.3" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-plugin-video-editor" version="1.1.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>VideoEditor</name>
<description>A plugin to assist in video editing tasks</description>
<keywords>cordova,video,editing,transcoding,encoding</keywords>
Expand Down
56 changes: 31 additions & 25 deletions src/ios/VideoEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ - (void) transcodeVideo:(CDVInvokedUrlCommand*)command
AVVideoCompressionPropertiesKey: @
{
AVVideoAverageBitRateKey: [NSNumber numberWithInt: videoBitrate],
AVVideoProfileLevelKey: AVVideoProfileLevelH264High40
AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel
}
};
encoder.audioSettings = @
Expand Down Expand Up @@ -338,31 +338,37 @@ - (void) getVideoInfo:(CDVInvokedUrlCommand*)command
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:fileURL options:nil];

NSArray *tracks = [avAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *track = [tracks objectAtIndex:0];
CGSize mediaSize = track.naturalSize;

float videoWidth = mediaSize.width;
float videoHeight = mediaSize.height;
float aspectRatio = videoWidth / videoHeight;

// for some portrait videos ios gives the wrong width and height, this fixes that
NSString *videoOrientation = [self getOrientationForTrack:avAsset];
if ([videoOrientation isEqual: @"portrait"]) {
if (videoWidth > videoHeight) {
videoWidth = mediaSize.height;
videoHeight = mediaSize.width;
aspectRatio = videoWidth / videoHeight;
}
}


// check if there are tracks, if not return
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSNumber numberWithFloat:videoWidth] forKey:@"width"];
[dict setObject:[NSNumber numberWithFloat:videoHeight] forKey:@"height"];
[dict setValue:videoOrientation forKey:@"orientation"];
[dict setValue:[NSNumber numberWithFloat:track.timeRange.duration.value / 600.0] forKey:@"duration"];
[dict setObject:[NSNumber numberWithLongLong:size] forKey:@"size"];
[dict setObject:[NSNumber numberWithFloat:track.estimatedDataRate] forKey:@"bitrate"];


unsigned long arrSize = [tracks count];
if (arrSize > 0) {
AVAssetTrack *track = [tracks objectAtIndex:0];
CGSize mediaSize = track.naturalSize;

float videoWidth = mediaSize.width;
float videoHeight = mediaSize.height;
float aspectRatio = videoWidth / videoHeight;

// for some portrait videos ios gives the wrong width and height, this fixes that
NSString *videoOrientation = [self getOrientationForTrack:avAsset];
if ([videoOrientation isEqual: @"portrait"]) {
if (videoWidth > videoHeight) {
videoWidth = mediaSize.height;
videoHeight = mediaSize.width;
aspectRatio = videoWidth / videoHeight;
}
}

[dict setObject:[NSNumber numberWithFloat:videoWidth] forKey:@"width"];
[dict setObject:[NSNumber numberWithFloat:videoHeight] forKey:@"height"];
[dict setValue:videoOrientation forKey:@"orientation"];
[dict setValue:[NSNumber numberWithFloat:track.timeRange.duration.value / 600.0] forKey:@"duration"];
[dict setObject:[NSNumber numberWithLongLong:size] forKey:@"size"];
[dict setObject:[NSNumber numberWithFloat:track.estimatedDataRate] forKey:@"bitrate"];
}

[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dict] callbackId:command.callbackId];
}

Expand Down