[英]Xamarin C# Transcode .mov to .mp4 with AVAsset Native IOS
Problem: Our cross platform application (IOS & Android) cannot play videos on Android that originate from IOS.问题:我们的跨平台应用程序(IOS 和 Android)无法在 Android 上播放源自 IOS 的视频。
Solution: Transcode .mov video files to .mp4 on client IOS applications prior to upload.解决方案:在上传之前,在客户端 IOS 应用程序上将 .mov 视频文件转码为 .mp4。
Issues: Unable to get the file location on IOS (string input is null).问题:无法在 IOS 上获取文件位置(字符串输入为空)。 Not sure if my native code / approach is sound.不确定我的本机代码/方法是否合理。
Exception: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"异常:错误域=AVFoundationErrorDomain 代码=-11800“操作无法完成”
Shared Code:共享代码:
try
{
MediaPickResult pickresult = await MediaGallery.PickAsync(1, MediaFileType.Video);
if (pickresult != null)
{
foreach (var video in pickresult.Files)
{
string guid = Guid.NewGuid().ToString();
blobupload.BlobID = guid + ".mp4";
string inputfilename = video.NameWithoutExtension + "." + video.Extension;
string input = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), inputfilename);
string output = Path.Combine(AzureStorage.localpath, guid + ".mp4");
if (File.Exists(input))
{
await IVideoConverter.ConvertVideo(input, output);
}
}
}
Native IOS:原生IOS:
public async Task ConvertVideo(string inputpath, string outputpath)
{
//string OutputFilePath = Path.ChangeExtension(outputpath, "mp4");
AVAsset asset = AVAsset.FromUrl(NSUrl.FromFilename(inputpath));
AVAssetExportSession export = new AVAssetExportSession(asset, AVAssetExportSession.PresetPassthrough);
export.OutputUrl = NSUrl.FromFilename(outputpath);
export.OutputFileType = AVFileType.Mpeg4;
export.ShouldOptimizeForNetworkUse = true;
var results = export.DetermineCompatibleFileTypesAsync();
try
{
export.ExportAsynchronously(() =>
{
if (export.Error != null)
{
System.Diagnostics.Debug.WriteLine(export.Error.LocalizedDescription);
}
});
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
I'd suggest我建议
ConvertVideo
将该本地副本的路径传递给ConvertVideo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.