Save MP4 video without audio - Ffmpeg-PHP

Asked

Viewed 194 times

2

I would like to know how I could save a clip(video) in MP4 by the Ffmpeg-PHP library without the audio, as it will not be necessary and I would also like to decrease the file size.

I’m using the following logic:

$frame = $segundos/6;
    for($i = 1 ; $i <= 5 ; $i++){
        $format = new \FFMpeg\Format\Video\X264();
        $format->setAudioCodec('libmp3lame');
        $clip = $video->clip(\FFMpeg\Coordinate\TimeCode::fromSeconds($frame*$i), \FFMpeg\Coordinate\TimeCode::fromSeconds(2.5));
        $clip->filters()->resize(new \FFMpeg\Coordinate\Dimension(320, 240), \FFMpeg\Filters\Video\ResizeFilter::RESIZEMODE_INSET, true);
        $clip->save($format,TEMPDIR.DS.'thumb.'.$filename.'_'.$i.'.mp4');
    }


$video->concat([TEMPDIR.DS.'thumb.'.$filename.'_1.mp4',
                TEMPDIR.DS.'thumb.'.$filename.'_2.mp4',
                TEMPDIR.DS.'thumb.'.$filename.'_3.mp4',
                TEMPDIR.DS.'thumb.'.$filename.'_4.mp4',
                TEMPDIR.DS.'thumb.'.$filename.'_5.mp4'])
      ->saveFromSameCodecs(TEMPDIR.DS.'thumb.'.$filename.'.mp4', TRUE);

But I have not seen anything in the documentation about saving without something audio, because to save the clip is required to set an Audiocodec if not encoding error.

  • Does not work, error: Uncaught Error: Call to Undefined method Ffmpeg Format Video X264::addFilter()

1 answer

3


You remove audio using the flag -an.

ffmpeg -i example.mkv -c copy -an example-nosound.mkv

Use the code below to remove audio with Simplefilter.

$customFilter = '-an';
\FFMpeg::fromDisk($disk)
->open($input)
->addFilter(new FFMpeg\Filters\Audio\SimpleFilter([$customFilter]))
->export()
->toDisk([$outputdisk])
->inFormat(new \FFMpeg\Format\Video\X264('libmp3lame', 'libx264'))
->save($output);

References

Proper use of setAdditionalParameters to remove audio?

Remove audio from video file with Ffmpeg

Note

Converting Audio into Different Formats / Sample Rates

Documentation PHP-Ffmpeg

  • In this case, what would enter $disk and $outputdisk? $Input I believe is the real path to the correct media?

  • It is an example of using simplefilter, export, save, fromdisk, are functions used in Windows, focus on filters and formats and try your code. But I believe it would be easier to do in cli this audio withdrawal.

  • 1

    I was able to save the video without audito add the line: $clip->addFilter(new Ffmpeg Filters Audio Simplefilter(['-an'])); Thank you Darlei.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.