protonemedia / laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
https://protone.media/en/blog/how-to-use-ffmpeg-in-your-laravel-projects
MIT License
1.66k stars 194 forks source link

Remove audio from HLS stream #453

Open Senya01 opened 1 year ago

Senya01 commented 1 year ago

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');
alhaji-aki commented 1 year ago

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...

alissonalberini commented 1 year ago
        $convert->beforeSaving(function(array $commands) {
           dd($commands);

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