Question

Let me first appologize if this is a re-post/similar-post as I did my best to search for a specific solution to my issue within the already created posts on here, and on google, but could not.

I am using ffmpeg on localhost on win64 system to create/test video conversion scripts prior to uploading them to the server.

I am able to successfully convert to/from mp4/flv/wmv/mov without issue, however, whenever I try to convert to .ogg from any other format, I run into issues.

First I tried this:

exec($ffmpegPath." -i ".$srcFile." ".$destFile);

but ended up with a corrupt file without video/sound. Then I did some reading that and found some posts that said that you must explicitly enable libvorbis/libtheora when converting to .ogg, so I tried this:

$aCodec = ' -acodec libvorbis';
$vCodec = ' -vcodec libtheora';
exec($ffmpegPath." -i ".$srcFile.$aCodec.$vCodec." ".$destFile);

This time I got a valid .ogg file, with sound, however, the video output is VERY choppy. In hopes to try and find the issue, I started making edits to the exec line and ended up with this:

$ffmpegObj = new ffmpeg_movie($srcFile);
$srcVB = intval($ffmpegObj->getVideoBitRate());
$vCodec = ' -vcodec libtheora';
exec($ffmpegPath." -i ".$srcFile.$vCodec." -vb ".$srcVB." ".$destFile);

which outputs the .ogg video in good quality but without sound.

Any ideas as to what else may be this issue prior to needing to install further software (ffmpeg2theora), etc.?

Also, if it helps, I echoed out the output from ffmpeg and when approach #2 above is used and many errors are displayed.

100 buffers queued in output stream 0:1, something may be wrong.
[ogg @ 00000000024bf780] st:0 PTS: 6743 DTS: 6743 < 7745 invalid, clipping
[ogg @ 00000000024bf780] st:0 PTS: 6871 DTS: 6871 < 7746 invalid, clipping
[ogg @ 00000000024bf780] st:0 PTS: 6999 DTS: 6999 < 7747 invalid, clipping
[ogg @ 00000000024bf780] st:0 PTS: 7127 DTS: 7127 < 7748 invalid, clipping
[ogg @ 00000000024bf780] st:0 PTS: 7255 DTS: 7255 < 7749 invalid, clipping
[ogg @ 00000000024bf780] st:0 PTS: 7383 DTS: 7383 < 7750 invalid, clipping

It seems that libvorbis and libtheora are not playing nice together?

Finally, I have changed ffmpeg.exe builds several times and still receive the same issue.

Thanks in advance.

EDIT: As a possible workaround, is there a way I can simply encode the video / audio separately and then slap them back together? Would this cause possible audio/video sync issues?

Was it helpful?

Solution

As usual, upon posting my question here (after countless hours of troubleshooting), I believe I may have corrected the issue. I needed to specify, not only the audio/video codecs for converting the file, but also the audio/video bitrate for the outputted .ogg video:

//CREATE CLASS INSTANCE
$ffmpegObj = new ffmpeg_movie($srcFile);
//GET AUDIO BITRATE FROM SOURCE FILE
$srcAB = intval($ffmpegObj->getAudioBitRate());
//GET VIDEO BITRATE FROM SOURCE FILE
$srcVB = intval($ffmpegObj->getVideoBitRate());

//SET THE AUDIO CODEC TO LIBVORBIS
$aCodec = ' -acodec libvorbis';
//SET THE VIDEO CODEC TO LIBTHEORA
$vCodec = ' -vcodec libtheora';

exec($ffmpegPath." -i ".$srcFile.$vCodec." -vb ".$srcVB." -ab ".$srcAB." ".$destFile);

This outputs a video/audio with quality very close to that of the original video format.

Obviously anyone who is trying to utilize the above code would need to add the references to $ffmpegPath/$srcFile/$destFile and have the ffmpeg class available to their script.

Also, upon initially viewing the .ogg video in firefox locally on my pc, the video would freeze when it first started playing and then jump to the correct position (relative to the audio) after a few seconds, however, if replayed from start would play without issue. I am assuming my video card is just not up to par; which would explain the issue upon first viewing the file after conversion.

In any case, the above code should work for any others who were having issues converting to the .ogg format properly using ffmpeg and php.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top