kodfire
kodfire

Reputation: 1783

ffmpeg - how to remove audio from video in laravel

ffmpeg -i input_file.mp4 -an -vcodec copy output_file.mp4

How can I change it to something like this below?

FFMpeg::fromDisk('local')
->open($filePath.$fileName)
->export()
->toDisk('local')
->inFormat(new \FFMpeg\Format\Video\X264('libmp3lame', 'libx264'))
->save($converted);

Upvotes: 0

Views: 1581

Answers (1)

Nick Mitchell
Nick Mitchell

Reputation: 1277

1. Which one is better? Too subjective, depends on your requirements. I'd go with .mp4 as support is much better across most (modern) browsers

-i is the input file e.g. input_file.mp4
-an Disable audio recording.
-c is codec. basically -c copy says copy without reencoding
copy ... well, copies to output file e.g. output_file.mp4
-vcodec sets the vide encoder. 

If used together with -vcodec copy, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists.

2. How to use in Laravel A few options:

I'd prob check out this library first: https://github.com/pascalbaljetmedia/laravel-ffmpeg

or if you want to roll your own...

Laravel is forked from Symfony so you can use the built in Process runner found here: http://symfony.com/doc/current/components/process.html

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

$cmd = 'ffmpeg -i input_file.mp4 -an -vcodec copy output_file.mp4';
$process = new Process($cmd);
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}

echo $process->getOutput();

Upvotes: 1

Related Questions