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

GallerySaver.saveVideo() fails when the video is encoded with x.265 on IOS #190

Open
rlueders opened this issue Sep 25, 2022 · 2 comments
Open

Comments

@rlueders
Copy link

GallerySaver.saveVideo() silently fails when the video is encoded with x.265 on IOS. No errors in the log, but the call returns false. The same video encoded with x.264 works fine IOS and both 265 and 264 work fine in Android. Anyone run into this?

@Ketul3012
Copy link

+1

@xieenming
Copy link

xieenming commented Mar 3, 2023

+1

This is not the problem of the third-party library ( GallerySaver ) we use, but a fact that iOS does not support hev1 codec tagged MP4.
iOS supports hvc1 codec tagged MP4, only hvc1 tagged MP4 works in iOS 11 beta and above.

H.265 and HEVC (High Efficiency Video Coding) is the same thing.

When using ffmpeg to mux H.265/HEVC to MP4, we can use codec tag hvc1 or hev1 (or others), default when codec tag not set, it will use hev1.

hev1 and hvc1 are two codec tags, indicating different packaging methods of the HEVC stream in the MP4 container. Quicktime Player and iOS do not support hev1 tagged mp4.

  • hvc1 parameter sets are stored out-of-band in the sample entry (i.e. below the Sample Description Box ( stsd ) box)
  • hev1 parameter sets are stored out-of-band in the sample entry and/or in-band in the samples (i.e. SPS/PPS/VPS NAL units in the bitstream/ mdat box)

hvc1 codec tagged MP4 info

hev1 codec tagged MP4 info

Reference:
http://ffmpeg.org/pipermail/ffmpeg-devel/2017-June/212577.html
https://stackoverflow.com/questions/32152090/encode-h265-to-hvc1-codec


So if a video is muxed from HEVC to MP4 with codec tag not being hvc1, when GallerySaver calls Swift code PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url) to save the MP4 video file to iOS Gallery, it will throw an error : error Error? domain: "PHPhotosErrorDomain" - code: 3302 , see https://developer.apple.com/documentation/photokit/phphotoserror/code/invalidresource

error code 3302 means invalidResource :
An error that indicates the asset resource validation fails.

2023-03-13 19 02 04


If you use the command mentioned in https://stackoverflow.com/questions/32152090/encode-h265-to-hvc1-codec
ffmpeg -i input-hev1.mp4 -c:v copy -tag:v hvc1 -c:a copy output-hvc1.mp4 to convert your input-hev1.mp4 to output-hvc1.mp4, the output-hvc1.mp4 file will be able to be put in Gallery of iOS and be played with QuickTime Player.

2023-03-14 14 26 28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants