Mitya
Mitya

Reputation: 34556

PHP/FFMPEG - why does my video conversion result in empty file?

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.

Upvotes: 1

Views: 2212

Answers (1)

llogan
llogan

Reputation: 133743

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).

Upvotes: 2

Related Questions