5

I use the following code to convert .webm videos to .mp4 using the FFMPEG library:

ffmpeg -i video.webm -vcodec h264 -acodec aac -strict experimental video.mp4

This works flawless when playing the converted video in Windows (Chrome/Firefox), Mac (Safari/Chrome), Android (Chrome) but it does not work when watching through iOS (Safari/Chrome).

At first I thought it might be an mp4 problem? But then I played without any problems in my iOS Safari this video https://www.w3schools.com/html/mov_bbb.mp4 which is also a mp4.

So this tells me that something is not quite right about the conversion.

What am I missing in the conversion?

Log from PuTTy: https://pastebin.com/VLSPL0nC

Linesofcode
  • 5,327
  • 13
  • 62
  • 116
  • Show the complete log from your command. – llogan Jan 23 '19 at 21:07
  • @llogan added the log – Linesofcode Jan 23 '19 at 21:13
  • Your `ffmpeg` is ancient. [Download](https://johnvansickle.com/ffmpeg/) or [compile](https://trac.ffmpeg.org/wiki/CompilationGuide/Centos) a new version. Then remove `-strict experimental` (that's only needed for really old builds), add `-movflags +faststart`, and try again. If it still fails add `-profile:v main`. – llogan Jan 23 '19 at 21:17
  • @llogan thank you, will do. I just tried with `-profile:v main -level 3.1` and it worked. And I just saw that `-strict experimental` was removed in 2015 or something!! – Linesofcode Jan 23 '19 at 21:24
  • I doubt you need `-level`. – llogan Jan 23 '19 at 21:26
  • how to convert you third-party library or standalone library now browser support convent with library – Rajesh Smartwebtech May 08 '21 at 08:11

2 Answers2

9
  1. Your ffmpeg is ancient. Download or compile a new version.
  2. Remove -strict experimental (that's only needed for really old builds).
  3. Add -movflags +faststart so it can begin playback faster.
  4. Add -vf format=yuv420p for a compatible pixel format.
  5. Output AAC audio (-c:a aac) instead of MP3 (-c:a libmp3lame).
  6. If it still fails it may be due to the device not supporting High profile. Add -profile:v main. You don't need to add this if your device supports High profile.

Example:

ffmpeg -i input -c:v libx264 -profile:v main -vf format=yuv420p -c:a aac -movflags +faststart output.mp4
  • Refer to the specifications of your target device to determine the appropriate -profile:v (and possibly -level).

  • See FFmpeg Wiki: H.264 for more info.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Hey, dou you happen to know how do I update my current FFMPEG version through shell? Is there any command, like `yum FFMPEG update`? – Linesofcode Jan 24 '19 at 13:58
  • @Linesofcode If yum supplies ffmpeg then it would probably be outdated. If you download a build from my first link then you can move the ffmpeg executable file into `/usr/local/bin` (or `~/bin` if you don't have permission). If you follow the second link and compile the instructions will do everything for you. – llogan Jan 24 '19 at 19:15
  • Hey @llogan can you check this question, please? https://stackoverflow.com/questions/69662784/videos-created-with-ffmpeg-do-not-play-on-ios-safari – Murat Colyaran Oct 21 '21 at 13:28
0

In addition to the arguments provided by @llogan, I found that lowering the frame rate of my videos was the key to playback in browser on IOS. I had success after adding fps=30 as a video filter.

Note: If there are multiple video filters, such as format=yuv420p then the filters need to be surrounded by quotes and separated by commas, like so:

-vf "format=yuv420p, fps=30"

Peter King
  • 11
  • 3