1

I'm trying to convert a video that lives on my server from a .webm to a .mp4.

shell_exec('ffmpeg -i file.webm output.mp4');

However, this results in an empty mp4 (0 bytes - or, sometimes, and very weirdly, 28 bytes.) The input file exists, and is 45MB.

This answer recommended explicitly copying the input codec, but same result.

shell_exec('ffmpeg -i file.webm -vcodec copy -acodec-copy output.mp4');

What am I doing wrong?

[ ===== EDIT ===== ]

After trying a few more things, inspired by the comments, I'm still having no joy converting to MP4.

It seems I'm running FFMPEG v.2.8.15. This seems quite a lot lower than the current release of 4~, however I only installed this a week or so ago so I'm not sure why this is the case and I don't know how to update it (I'm on WHM Cpanel.)

Anyway, my problem is NOT to do with pathing, because the same command works fine if I change .mp4 to .webm - I get a successfully converted .webm file.

But when I run:

$foo = shell_exec('ffmpeg -i file.webm -vcodec copy -acodec copy output3.mp4 -report');

...I get this FFMPEG log output.

I've also tried:

shell_exec('ffmpeg -fflags +genpts -i file.webm -r 24 KKK.mp4 -report');

...from this answer, and

shell_exec('ffmpeg -i file.webm -c:v copy III.mp4');

...from this article.

Both result in the same problem, i.e. an 0-bytes .mp4 file.

Mitya
  • 33,629
  • 9
  • 60
  • 107
  • 1
    You'll need to show the complete log from the `ffmpeg` command. Either will do. – llogan Oct 31 '18 at 20:24
  • 1
    what is the output when you run over terminal w/o shell_exec? – Cemal Oct 31 '18 at 21:36
  • `-acodec -copy` not `-acodec-copy`. Better to make sure you also have an up to date ffmpeg and use the newer syntax: `-c:v copy` `-c:a copy` – video.baba Oct 31 '18 at 21:50
  • Sorry, typo above: I'll try again: `-acodec copy` not `-acodec-copy`. Better to make sure you also have an up to date ffmpeg and use the newer syntax: `-c:v copy` `-c:a copy` – video.baba Oct 31 '18 at 21:56
  • You probably need to specify the full paths to the files, and possibly the executable as well. – miken32 Oct 31 '18 at 22:47
  • Thanks for the feedback, guys. I'll have a look at what the log output is. @miken32 - I don't think so, because the same command is working fine if I convert to .webm rather than .mp4. And the file IS created, as I said - just with 0 bytes. – Mitya Nov 01 '18 at 10:45
  • You can use the -report option of ffmpeg in order to get the log output (or capture stderr which is a bit harder to do ;-)), this should tell you whats the problem is – Harry Nov 01 '18 at 16:55
  • Hey guys - please see question edit. Thanks. – Mitya Nov 02 '18 at 11:45

1 Answers1

2

Problem

You're trying to mux VP9 video and Opus audio into the MP4 container. Currently, muxing Opus into the MP4 container is considered experimental and requires -strict experimental (or -strict -2), but your ffmpeg is too old to support that. Download a new version.

Solutions

  • Do not mux typical WebM formats (VP9 or VP8 + Opus or Vorbis) into MP4. You can re-encode it to H.264 (or H.265) with AAC audio if you want a more common set of formats for MP4:

    ffmpeg -i input -c:v libx264 -c:a aac -movflags +faststart output.mp4
    
  • Or upgrade your ffmpeg and add the -strict experimental (or -strict -2) output option to your command if you know you want VP9 + Opus in MP4:

    ffmpeg -i input -c copy -strict experimental -movflags +faststart output.mp4
    
  • Or don't re-mux into MP4 in the first place. HTML5 video supports VP9 + Opus in WebM so just use the original file if it is supported by your target browser(s).

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thanks for this. I would upgrade FFMPEG but I don't know how as I have very little server admin knowledge and I'm restricted to what I can do in WHM, running Centos 7 (I don't have access to the physical server). Secondly, I'm converting to MP4 because Safari on Mac (inc. iPhone) [doesn't support WEBM](https://www.webmproject.org/users/) so the idea was to convert to a second format that is supported. – Mitya Nov 03 '18 at 11:54
  • Also the command you gave me under Solutions still resulted in a 0-bytes MP4 :-( The FFMPEG log says I need experimental for that; I turned it on, by appending -strict -2 to the command (I know you said my version was too old to use experimental, but I tried anyway) and I got the same result - 0 bytes and a complaint that I need to use experimental. – Mitya Nov 03 '18 at 12:07
  • @Utkanos Using `-strict -2`/`-strict experimental` is not a generic catch-all: it is needed when you are attempting to use specific experimental features. You are encountering two different cases. The old FFmpeg AAC encoder (`-c:a aac`) used to be considered experimental, so that is why your old `ffmpeg` requires `-strict -2` to use that. Modern version do not require `-strict` for that encoder. Your old `ffmpeg` does not support Opus in MP4, but modern versions do, but they require `-strict` for this. – llogan Nov 03 '18 at 17:39
  • Thanks, @LordNeckbeard. Lastly, is it straightforward for a server noob, in my situation, to update my version of ffmpeg? I've looked at the download page you linked, and I have no idea which link I'm supposed to click for my server build (Centos 7) or what I do with it. I'm more than happy to go learn, I just need a kickstart to point me in the right direction. – Mitya Nov 03 '18 at 18:17
  • @Utkanos I'll provide that answer in your [other question](https://superuser.com/questions/1372260/ffmpeg-why-do-i-end-up-with-old-version-after-installing) in a little while. This answer here will specifically address the Opus in MP4 issue. – llogan Nov 03 '18 at 18:20
  • Please see edit @LordNeckBeard - continued thanks for your help. – Mitya Nov 04 '18 at 15:41
  • Turns out the `-strict` flag has to go in a certain place, which certainly isn't made clear in the FFMPEG logs. [This answer](https://stackoverflow.com/a/35247468/1352288) cleared that up. So now I'm all good - huge thanks for your help along the way. – Mitya Nov 04 '18 at 16:48
  • @Utkanos Option order is important: `ffmpeg [global options] [input options] -i input [output options] output` and you should avoid trailing options as they are often ignored (as you experienced). – llogan Nov 04 '18 at 17:32