Reputation: 3914
I am using an app in which I am creating a video from my live stream and convert it to Mp4/Mov format and save it to documents directory.
I am using below command to create Mp4 file from video frames.
-loglevel trace -r 20 -i inputfile -c:v copy -f mp4 -y -r 20 outputfile
When video files are H264 then it is working but having issue when codec type is H265.
App is created in Xamarin iOS. Native code help will also work.
Now I want to save this video from documents directory to iPhone Gallery and share using UIActivityViewController.
It works fine when video codec is H264 but HEVC/H264 video gives me error saying
The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)
while saving to gallery.
I searched a lot and tried too many solutions but nothing works for me.
I am using the below code.
NSData videoData = NSData.FromUrl(NSUrl.FromString(mFilePath));
UIVideo.SaveToPhotosAlbum(mFilePath, (string path, NSError errdor) =>
{
mShareVideoUrl = NSUrl.FromString(path);
PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
{
//Save Clip to photo library...
PHAssetChangeRequest.FromVideo(mShareVideoUrl);
}, (bool success, NSError error) =>
{
if (success)
{
MxLogger.printLine(MxLogger.LOG_TAG.DEBUG, "Video Saved to gallery");
var options = new PHFetchOptions
{
FetchLimit = 1,
SortDescriptors = new[] { new NSSortDescriptor("creationDate", false) },
};
// Get that video url for Photo Library...
PHAsset phAsset = PHAsset.FetchAssets(options).FirstOrDefault() as PHAsset;
PHVideoRequestOptions requestOptions = new PHVideoRequestOptions();
requestOptions.Version = PHVideoRequestOptionsVersion.Original;
requestOptions.DeliveryMode = PHVideoRequestOptionsDeliveryMode.Automatic;
requestOptions.NetworkAccessAllowed = true;
PHImageManager.DefaultManager.RequestAvAsset(phAsset, requestOptions, (AVAsset asset, AVAudioMix audioMix, NSDictionary info) =>
{
NSError errorp;
AVUrlAsset avurlasset = (AVUrlAsset)asset;
mShareVideoUrl = NSUrl.FromFilename(mFilePath);
if (NSFileManager.DefaultManager.Copy(avurlasset.Url.AbsoluteString, mShareVideoUrl.AbsoluteString, out errorp))
{
//MxLogger.printLine(MxLogger.LOG_TAG.DEBUG, "Error : " + error);
}
MxLogger.printLine(MxLogger.LOG_TAG.DEBUG, "Video exported successfully : " + mShareVideoUrl);
MxLogger.printLine(MxLogger.LOG_TAG.DEBUG, "Video exported successfully");
}
else
{
MxLogger.printLine(MxLogger.LOG_TAG.DEBUG, "Video Saved to gallery error");
}
});
});
Please guide me what wrong I am doing.
Any help would be highly appreciated.
Thanks in advance.
Upvotes: 2
Views: 480