1

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.

Manthan
  • 3,856
  • 1
  • 27
  • 58
  • "gives me error" - what is the error? Why have you not included this highly relevant information in your post? – Jason Nov 16 '21 at 13:09
  • @Jason: Updated the question. Please help if you can. – Manthan Nov 16 '21 at 13:13
  • 2
    If you are using `H265` (your title does not match your problem statement), then you need to encode to an `hvc1` , not `avc1` or `hev1` – SushiHangover Nov 16 '21 at 17:36
  • @SushiHangover: Thank you for the guide. The above tags were the key you mentioned. https://stackoverflow.com/questions/32152090/encode-h265-to-hvc1-codec – Manthan Nov 17 '21 at 09:10
  • 1
    Same thing is happening for Mjpeg4. Is that any tag related to that as well? – Manthan Nov 18 '21 at 04:18

0 Answers0