Search code examples
phpaudiovideoffmpegffmpeg-php

How to tell if video has audio?


I'm using FFmpeg-php to convert videos. When I want to convert a video that has no audio, it gives me an error on these lines:

$srcAB = $ffmpegObj->getAudioBitRate();
$srcAR = $ffmpegObj->getAudioSampleRate();

Is there a way within ffmpeg-php to know if a video has any audio, so I can skip the above lines above and give both $srcAB and $srcAR a value of 0?


Solution

  • I don't know a lot about FFMpeg, but a quick search gives me the API.

    Looks like there are methods for checking audio, see $movie->hasAudio(). Returns true if an audio stream is present.

    So then you'd be looking at something like if(ffmpegObj->hasAudio()){ //do something };