Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
695 views
in Technique[技术] by (71.8m points)

ffmpeg - react native: only mp4 files

I have an react-native app for both android and ios. In this app, users can upload a video (from the cameraroll or directly from the camera). I'm using react-native-camera for this.

On android, the video output is mp4. On ios, the video output is mov.

I'm using react-native-video to display the videos.

On android, there is no problem, but on IOS, the mov videos are played with a switched orientation. You can find a bug report here about this. There are also some other reports where this issue is discussed. Some people state that it's fixed with ios 14.2 (some even say with 14.1), but for me, the issue still exists. I even opened a topic myself for this myself, on the react-native-camera repo: https://github.com/react-native-camera/react-native-camera/issues/2994. You can see some screenshots there.

I found out that, when playing mp4-video's on IOS, this problem does not occur. I figured out that, by converting all mov-files to mp4-files, I would overcome this problem.

My current strategy is like this:

  • record a movie in mov-format (or get one from the cameraroll)
  • copy this file to a "readable" location with react-native-fs copyAssetsVideoIOS.
  • convert this mov-file to an mp4-file using FFMPEG. Command: -i input.mov -preset ultrafast -vcodec h264 -acodec mp2 output.mp4.
  • delete the first mov copy.
  • upload the mp4-file to the server for display.

This strategy works, and an extra is that I now only have mp4-files on my server storage (both from android and ios). I'm using the preset ultrafast in my ffmpeg command because otherwise it takes a long time to convert a 30 second mov-file to an mp4-file, and I don't see a big loss in quality.

The question is: I'm scared that converting every mov-file to an mp4-file will take a lot of resources from the device. There problably is a reason that react-native-camera creates mov-files instead of mp4-files on ios, and now I'm converting them. Will my strategy have an impact on (future) behavior of the videoplayer?

question from:https://stackoverflow.com/questions/65641517/react-native-only-mp4-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...