iOS 13.0 的 IONIC 中的视频转码问题
Video transcoding problem in IONIC with iOS 13.0
我们有一个现有的 IONIC 应用程序,并且由于 iOS 13.0 已经发布,我们 运行 遇到了 t运行 编码视频的问题。
当从 camera.getPicture(使用 sourceType=PHOTOLIBRARY)读取文件路径并传递给 videoEditor.transcodeVideo() 时,它会无限期地继续调用值为 0 的进度回调。它不会抛出任何错误并且它会赢' 调用完成回调。
videoEditor.transcodeVideo() 不适用于 iPhone 设备 iOS 13.0 +.
我在 iOS 13.0 的模拟器上尝试了相同的代码,令人惊讶的是它有效。
我尝试了不同的文件 URLs 传递给 t运行scodeVideo() - 无论是规范化还是完整 URL - 没有机会!
我尝试对从相机拍摄的视频进行编码(而不是从照片库 - captureVideo() 函数),并且效果很好。
openFromLibrary() { //DOES NOT WORK
const optionsFiles: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.FILE_URI,
mediaType: this.camera.MediaType.VIDEO,
targetWidth: 450,
targetHeight: 450,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
}
this.camera.getPicture(optionsFiles).then((data) => {
let model = {
fullPath: data,
name: data.substring(data.lastIndexOf('/') + 1)
}
//model.fullPath is something like:
//file:///private/var/mobile/Containers/Data/PluginKitPlugin/DE8E75E9-BF8B-4990-8F01-3874169D65E0/tmp/trim.4F8792C3-D9EC-450D-9E05-2D96C1CF5AE5.MOV
this.TranscodeVideo(model);
}, (err) => {
console.log(err)
})
}
captureVideo() { //WORKS
let options: CaptureVideoOptions = { limit: 1, quality: 1 };
this.mediaCapture.captureVideo(options).then((data: MediaFile[]) => {
this.TranscodeVideo(data[0]);
},
(err: CaptureError) => console.error(err)
);
}
TranscodeVideo(data: any) {
let fileUri = data.fullPath;
let outputFileName = this.removeExtension(data.name) + new Date().getMilliseconds() + '_transcoded-output';
console.log("fileUri: " + fileUri);
console.log("outputFileName: " + outputFileName);
this.videoEditor.transcodeVideo({
fileUri: fileUri,
outputFileName: outputFileName,
outputFileType: this.videoEditor.OutputFileType.MPEG4,
progress: (info: number) => {
//This gets called indefinitely ... with info = 0
console.log('progress' + info)
}
}).then(
(fileUri: string) => {
//This never gets called
console.log('completed')
}
).catch((error: any) => {
//This never gets called
alert(error)
});
}
预期的结果是我从模拟器的输出中得到的:
**2019-10-01 13:41:34.518254-0700 MyApp[1120:13425] fileUri: file:///Users/admin/Library/Developer/CoreSimulator/Devices/6E600D79-C397-4B55-B776-DE036DBFCA7C/data/Containers/Data/PluginKitPlugin/5F323D37-2DE5-4440-BCC0-C07D91F7F77E/tmp/trim.2BB1FF35-883B-4CFE-8EC0-2482E4A09321.MOV**
**2019-10-01 13:41:34.518505-0700 MyApp[1120:13425] outputFileName: trim.2BB1FF35-883B-4CFE-8EC0-2482E4A09321501_transcoded-output**
**2019-10-01 13:41:34.642996-0700 MyApp[1120:13425] input videoWidth: 360.000000**
**2019-10-01 13:41:34.643182-0700 MyApp[1120:13425] input videoHeight: 480.000000**
**2019-10-01 13:41:34.643264-0700 MyApp[1120:13425] output newWidth: 360**
**2019-10-01 13:41:34.643323-0700 MyApp[1120:13425] output newHeight: 480**
**2019-10-01 13:41:34.643522-0700 MyApp[1120:13425] THREAD WARNING: ['VideoEditor'] took '124.734131' ms. Plugin should use a background thread.**
**2019-10-01 13:41:34.662540-0700 MyApp[1120:13538] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000033c4600> F8BB1C28-BAE8-11D6-9C31-00039315CD46**
**2019-10-01 13:41:34.667810-0700 MyApp[1120:13538] [ddagg] AggregateDevice.mm:776 couldn't get default input device, ID = 0, err = 0!**
**2019-10-01 13:41:34.701108-0700 MyApp[1120:13425] progress0**
**2019-10-01 13:41:34.889640-0700 MyApp[1120:13530] Video export succeeded**
**2019-10-01 13:41:34.890443-0700 MyApp[1120:13425] progress100**
**2019-10-01 13:41:34.894357-0700 MyApp[1120:13425] completed**
但我得到的是无限数量的进度 = 0,这是我从 iPhone 设备 iOS 13.0:
记录的内容
**2019-10-01 13:46:40.599042-0700 MyApp[458:25050] fileUri: file:///private/var/mobile/Containers/Data/PluginKitPlugin/DE8E75E9-BF8B-4990-8F01-3874169D65E0/tmp/trim.521777DB-3325-4E83-98F6-BEDF14EBDC9C.MOV**
**2019-10-01 13:46:40.599279-0700 MyApp[458:25050] outputFileName: trim.521777DB-3325-4E83-98F6-BEDF14EBDC9C594_transcoded-output**
**2019-10-01 13:46:40.617653-0700 MyApp[458:25050] input videoWidth: 360.000000**
**2019-10-01 13:46:40.617717-0700 MyApp[458:25050] input videoHeight: 480.000000**
**2019-10-01 13:46:40.617747-0700 MyApp[458:25050] output newWidth: 360**
**2019-10-01 13:46:40.617780-0700 MyApp[458:25050] output newHeight: 480**
**2019-10-01 13:46:40.617903-0700 MyApp[458:25050] THREAD WARNING: ['VideoEditor'] took '17.159912' ms. Plugin should use a background thread.**
**2019-10-01 13:46:40.624098-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:40.624256-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:41.633175-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:42.639211-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:43.642919-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:44.649573-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:45.653984-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:46.661094-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:47.665412-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:48.669655-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:49.674255-0700 MyApp[458:25050] progress0**
...
使用的插件有:VideoEditor,Camera
我找到了答案,它可能会帮助 运行 遇到类似问题的人。问题不在于VideoEditor插件中的转码功能,而是因为Camera插件returns在调用camera.getPicture()时文件路径不正确。
路径是这样的:
file:///private/var/mobile/Containers/Data/PluginKitPlugin/DE8E75E9-BF8B-4990-8F01-3874169D65E0/tmp/trim.521777DB-3325-4E83-98F6-BEDF14EBDC9C.MOV
因此,对于那些迫不及待要为 iOS 13.0 更新此插件的用户,这里是解决方案:
在 XCode 中找到相机插件源文件 - CDVCamera.m 和
变化:
(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}
收件人:
(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSArray* spliteArray = [moviePath componentsSeparatedByString: @"/"];
NSString* lastString = [spliteArray lastObject];
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:lastString];
[fileManager copyItemAtPath:moviePath toPath:filePath error:&error];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}
此更改将电影复制到 App 文档目录,以便我们以后使用它。
感谢 litiobat 在 GitHub 上:
Source
自 2020 年 12 月 14 日起,此问题已在 cordova-plugin-camera 5.0.1 版中修复
"cordova-plugin-camera": "5.0.1",
我们有一个现有的 IONIC 应用程序,并且由于 iOS 13.0 已经发布,我们 运行 遇到了 t运行 编码视频的问题。 当从 camera.getPicture(使用 sourceType=PHOTOLIBRARY)读取文件路径并传递给 videoEditor.transcodeVideo() 时,它会无限期地继续调用值为 0 的进度回调。它不会抛出任何错误并且它会赢' 调用完成回调。
videoEditor.transcodeVideo() 不适用于 iPhone 设备 iOS 13.0 +.
我在 iOS 13.0 的模拟器上尝试了相同的代码,令人惊讶的是它有效。
我尝试了不同的文件 URLs 传递给 t运行scodeVideo() - 无论是规范化还是完整 URL - 没有机会!
我尝试对从相机拍摄的视频进行编码(而不是从照片库 - captureVideo() 函数),并且效果很好。
openFromLibrary() { //DOES NOT WORK
const optionsFiles: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.FILE_URI,
mediaType: this.camera.MediaType.VIDEO,
targetWidth: 450,
targetHeight: 450,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
}
this.camera.getPicture(optionsFiles).then((data) => {
let model = {
fullPath: data,
name: data.substring(data.lastIndexOf('/') + 1)
}
//model.fullPath is something like:
//file:///private/var/mobile/Containers/Data/PluginKitPlugin/DE8E75E9-BF8B-4990-8F01-3874169D65E0/tmp/trim.4F8792C3-D9EC-450D-9E05-2D96C1CF5AE5.MOV
this.TranscodeVideo(model);
}, (err) => {
console.log(err)
})
}
captureVideo() { //WORKS
let options: CaptureVideoOptions = { limit: 1, quality: 1 };
this.mediaCapture.captureVideo(options).then((data: MediaFile[]) => {
this.TranscodeVideo(data[0]);
},
(err: CaptureError) => console.error(err)
);
}
TranscodeVideo(data: any) {
let fileUri = data.fullPath;
let outputFileName = this.removeExtension(data.name) + new Date().getMilliseconds() + '_transcoded-output';
console.log("fileUri: " + fileUri);
console.log("outputFileName: " + outputFileName);
this.videoEditor.transcodeVideo({
fileUri: fileUri,
outputFileName: outputFileName,
outputFileType: this.videoEditor.OutputFileType.MPEG4,
progress: (info: number) => {
//This gets called indefinitely ... with info = 0
console.log('progress' + info)
}
}).then(
(fileUri: string) => {
//This never gets called
console.log('completed')
}
).catch((error: any) => {
//This never gets called
alert(error)
});
}
预期的结果是我从模拟器的输出中得到的:
**2019-10-01 13:41:34.518254-0700 MyApp[1120:13425] fileUri: file:///Users/admin/Library/Developer/CoreSimulator/Devices/6E600D79-C397-4B55-B776-DE036DBFCA7C/data/Containers/Data/PluginKitPlugin/5F323D37-2DE5-4440-BCC0-C07D91F7F77E/tmp/trim.2BB1FF35-883B-4CFE-8EC0-2482E4A09321.MOV**
**2019-10-01 13:41:34.518505-0700 MyApp[1120:13425] outputFileName: trim.2BB1FF35-883B-4CFE-8EC0-2482E4A09321501_transcoded-output**
**2019-10-01 13:41:34.642996-0700 MyApp[1120:13425] input videoWidth: 360.000000**
**2019-10-01 13:41:34.643182-0700 MyApp[1120:13425] input videoHeight: 480.000000**
**2019-10-01 13:41:34.643264-0700 MyApp[1120:13425] output newWidth: 360**
**2019-10-01 13:41:34.643323-0700 MyApp[1120:13425] output newHeight: 480**
**2019-10-01 13:41:34.643522-0700 MyApp[1120:13425] THREAD WARNING: ['VideoEditor'] took '124.734131' ms. Plugin should use a background thread.**
**2019-10-01 13:41:34.662540-0700 MyApp[1120:13538] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000033c4600> F8BB1C28-BAE8-11D6-9C31-00039315CD46**
**2019-10-01 13:41:34.667810-0700 MyApp[1120:13538] [ddagg] AggregateDevice.mm:776 couldn't get default input device, ID = 0, err = 0!**
**2019-10-01 13:41:34.701108-0700 MyApp[1120:13425] progress0**
**2019-10-01 13:41:34.889640-0700 MyApp[1120:13530] Video export succeeded**
**2019-10-01 13:41:34.890443-0700 MyApp[1120:13425] progress100**
**2019-10-01 13:41:34.894357-0700 MyApp[1120:13425] completed**
但我得到的是无限数量的进度 = 0,这是我从 iPhone 设备 iOS 13.0:
记录的内容**2019-10-01 13:46:40.599042-0700 MyApp[458:25050] fileUri: file:///private/var/mobile/Containers/Data/PluginKitPlugin/DE8E75E9-BF8B-4990-8F01-3874169D65E0/tmp/trim.521777DB-3325-4E83-98F6-BEDF14EBDC9C.MOV**
**2019-10-01 13:46:40.599279-0700 MyApp[458:25050] outputFileName: trim.521777DB-3325-4E83-98F6-BEDF14EBDC9C594_transcoded-output**
**2019-10-01 13:46:40.617653-0700 MyApp[458:25050] input videoWidth: 360.000000**
**2019-10-01 13:46:40.617717-0700 MyApp[458:25050] input videoHeight: 480.000000**
**2019-10-01 13:46:40.617747-0700 MyApp[458:25050] output newWidth: 360**
**2019-10-01 13:46:40.617780-0700 MyApp[458:25050] output newHeight: 480**
**2019-10-01 13:46:40.617903-0700 MyApp[458:25050] THREAD WARNING: ['VideoEditor'] took '17.159912' ms. Plugin should use a background thread.**
**2019-10-01 13:46:40.624098-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:40.624256-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:41.633175-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:42.639211-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:43.642919-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:44.649573-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:45.653984-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:46.661094-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:47.665412-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:48.669655-0700 MyApp[458:25050] progress0**
**2019-10-01 13:46:49.674255-0700 MyApp[458:25050] progress0**
...
使用的插件有:VideoEditor,Camera
我找到了答案,它可能会帮助 运行 遇到类似问题的人。问题不在于VideoEditor插件中的转码功能,而是因为Camera插件returns在调用camera.getPicture()时文件路径不正确。
路径是这样的: file:///private/var/mobile/Containers/Data/PluginKitPlugin/DE8E75E9-BF8B-4990-8F01-3874169D65E0/tmp/trim.521777DB-3325-4E83-98F6-BEDF14EBDC9C.MOV
因此,对于那些迫不及待要为 iOS 13.0 更新此插件的用户,这里是解决方案: 在 XCode 中找到相机插件源文件 - CDVCamera.m 和
变化:
(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}
收件人:
(CDVPluginResult*)resultForVideo:(NSDictionary*)info
{
NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSArray* spliteArray = [moviePath componentsSeparatedByString: @"/"];
NSString* lastString = [spliteArray lastObject];
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:lastString];
[fileManager copyItemAtPath:moviePath toPath:filePath error:&error];
return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
}
此更改将电影复制到 App 文档目录,以便我们以后使用它。
感谢 litiobat 在 GitHub 上: Source
自 2020 年 12 月 14 日起,此问题已在 cordova-plugin-camera 5.0.1 版中修复
"cordova-plugin-camera": "5.0.1",