3

I am using ffmpeg to convert audio and video on my website. Ffmpeg is properly converting to other formats like mp3, mp4, etc. but not converting properly to ogg. Although ffmpeg is creating the ogg file but the newly created ogg file is corrupted and too much bigger in size than the original one. I am using the following PHP code to convert to ogg.

exec("/usr/bin/ffmpeg -i ".$_FILES['thefile1']['tmp_name']." ./ogg/$file_name".".ogg");
pb2q
  • 58,613
  • 19
  • 146
  • 147
Rizwan
  • 31
  • 1
  • 3

1 Answers1

5

I'm going to assume that you're looking for ogg video, not audio. If you wanted audio, just remove the vcodec stuff.

Add the following parameters:

vcodec libtheora
acodec libvorbis

So your command would become:

exec("/usr/bin/ffmpeg -i ".$_FILES['thefile1']['tmp_name']." -vcodec libtheora -acodec libvorbis ./ogg/$file_name".".ogg");

You have to make sure that you have libtheora and libvorbis installed. ffmpeg will throw an error if you execute that command and you don't have them installed. You can check using

ffmpeg -codecs

and searching for libtheora and libvorbis.

matzahboy
  • 3,004
  • 20
  • 25
  • Thanks a lot for your reply. My problem is half solved as a result of your reply. I have used the following code. exec("/usr/bin/ffmpeg -i ".$_FILES['thefile1']['tmp_name']." -vcodec libtheora -acodec libvorbis ./ogg/$file_name".".ogg"); Now it is converting audio files perfectly to ogg but not video files. And as far as video files are concerned, it is not converting them properly to neither of mp4 and ogg. Can you please guide further? – Rizwan Aug 03 '11 at 12:11
  • Are you getting any error messages? If so, can you tell me them? – matzahboy Aug 03 '11 at 14:13
  • No error message given and file created successfully but the resulting ogg file is of 0 kb and the mp4 file is also too smaller in size and doesn't played back. – Rizwan Aug 04 '11 at 04:09
  • For video files, I am using the following code. exec("/usr/bin/ffmpeg -i ".$_FILES['thefile1']['tmp_name']." ./ogg/$file_name".".ogg"); as the following coded is working fine with audio but not creating any file when used with video. exec("/usr/bin/ffmpeg -i ".$_FILES['thefile1']['tmp_name']." -vcodec libtheora -acodec libvorbis ./ogg/$file_name".".ogg"); – Rizwan Aug 04 '11 at 04:56
  • Can you try running the video converting command outside of php (i.e. on the command line) with a test input file and see what the output is? One guess I can think of is that the output file already exists (and you'd need to add the -y option to overwrite it). – matzahboy Aug 04 '11 at 14:07
  • Fixed the issue with me; oggs created with ffmepg didn't work with Firefox and now I found the reason & fix. Thanks! – Touko Mar 06 '12 at 19:10