laravel-ffmpeg icon indicating copy to clipboard operation
laravel-ffmpeg copied to clipboard

Remove audio from HLS stream

Open Senya01 opened this issue 3 years ago • 2 comments

Hello,

How can I delete audio for hls? My code:

$lowBitrate = (new X264)->setKiloBitrate(250);
$midBitrate = (new X264)->setKiloBitrate(500);
$highBitrate = (new X264)->setKiloBitrate(1000);

FFMpeg::fromDisk($this->video->disk)
->open($this->video->path)
->exportForHLS()
->setSegmentLength(10)
->toDisk('streamable_video')
->addFormat($highBitrate, function ($media) {
    $media->scale(1920, 1080);
})
->addFormat($midBitrate, function ($media) {
    $media->scale(1280, 720);
})
->addFormat($lowBitrate, function ($media) {
    $media->scale(720, 480);
})
->save($this->video->id . '.m3u8');

Senya01 avatar Nov 21 '22 18:11 Senya01

I would very much want to see how you solve it... I ended up removing the audio from the video before generating the HLS files

This is my code

// the relative path of the video without output
$videoWithNoAudio =$this->video->id . '-no-audio.mp4';

// remove Audio from video before uploading
FFMpeg::fromFilesystem($this->video->disk)
    ->open($this->video->path)
    ->export()
    ->addFilter(['-an'])
    ->save($videoWithNoAudio);

// generate hls file
FFMpeg::fromFilesystem($this->video->disk)
    ->open($videoWithNoAudio)
    ->exportForHLS()
    ->setSegmentLength(10)
    ->toDisk('streamable_video')
    ->addFormat($highBitrate, function ($media) {
        $media->scale(1920, 1080);
    })
    ->addFormat($midBitrate, function ($media) {
        $media->scale(1280, 720);
    })
    ->addFormat($lowBitrate, function ($media) {
        $media->scale(720, 480);
    })
    ->save($this->video->id . '.m3u8');

I am sure there are better ways to do this.... but for now this is what works for me...

alhaji-aki avatar Dec 14 '22 12:12 alhaji-aki

        $convert->beforeSaving(function(array $commands) {
           dd($commands);

//Identify position relative to audio parameter, and substitute ex: $commands[99] = "-an" return $commands; });

alissonalberini avatar Jun 30 '23 00:06 alissonalberini