1

Here is my code:

$format = new X264('aac', 'libx264');
$format->setKiloBitrate(500);

but when videos transcode with pascalbaljetmedia/laravel-ffmpeg, this package sets audio codec to mp3 by default instead aac.

How solve this problem?

Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68

1 Answers1

0

I told you about the libfaac encoder. But I figured out this one was deprecated in 2016. Because there are other better encoders out there such as aac, libfdk_aac, aac_at etc. Check out more here.

You should first check those encoders out on your command line tool to make sure your ffmpeg was compiled with those encoders. Let's use aac encoder because it is included by default in all ffmpeg versions.

ffmpeg -i real_audio.mp3 -c:a aac converted_audio.aac

I used the laravel-ffmpeg with aac encoder to convert mp3 to aac. It worked like a charm. See the following code:

<?php

namespace App\Http\Controllers;

use FFMpeg\Format\Video\X264;
use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg;

class TestController extends Controller
{
    public function index() 
    {
        echo "<p>Converting...</p>";

        FFMpeg::fromDisk('public')
            ->open('audio.mp3')
            ->export()
            ->toDisk('public')
            ->inFormat(new X264('aac'))
            ->save('converted_audio.aac');
    }
}

To know more about aac encoder use the following command:

ffmpeg -h encoder=aac

My laravel-ffmpeg package version is

"pbmedia/laravel-ffmpeg": "^7.0"

and ffmpeg version is

ffmpeg version 3.4.6

Hope this helps you!

unclexo
  • 3,691
  • 2
  • 18
  • 26
  • tnx for answer, i use aac same as you, but when pbmedia/laravel-ffmpeg transcodes video, audio codec change to libmp3lame by default.problem is here! – vahid zolfaghari Jun 10 '20 at 11:59
  • No! I tried both video mp4 to audio aac and audio mp3 to audio aac and both work fine. It may happens because libfaac is deprecated now, and X264 takes libfaac as default audio codec, (I'm not sure) it may be a fallback to libmp3lame. So you need to specify the codec while converting audio to video and vice versa. – unclexo Jun 10 '20 at 13:59
  • my code works on local very well but when using that on server change audio format to libmp3lame by default!!! – vahid zolfaghari Jun 13 '20 at 05:29
  • That's why I told you to check out whether or not one of `aac`, `libfdk_aac`, `aac_at` etc. codec is installed (on your server). Therefore, is `FFMPEG` complied with the codec that you need? Check `FFMPEG`'s version. New versions of it get compiled with `aac` codec by default. If it's not possible digging into your server, then ask hosting provider about that. – unclexo Jun 13 '20 at 05:49
  • i am using laravel 5.8 in my project and last version of pbmedia/laravel-ffmpeg compatible with that is 4.0 – vahid zolfaghari Jun 13 '20 at 06:15
  • The version `pbmedia/laravel-ffmpeg` of it is not important here but the version of `ffmpeg` on your server. Because you've to figure out (to know why it's being fallback to `libmp3lame`) with what codes the `ffmpeg` compiled on your server. – unclexo Jun 13 '20 at 06:46
  • ffmpeg version 4.2.2 on server – vahid zolfaghari Jun 13 '20 at 06:52
  • Well, then it should be OK. Can you share your code via pastebin.com or something else? – unclexo Jun 13 '20 at 07:06
  • https://github.com/pascalbaljetmedia/laravel-ffmpeg/issues/205 – vahid zolfaghari Jun 13 '20 at 07:10
  • Your code seems quite OK to me but one thing is the version of `pbmedia/laravel-ffmpeg`. Why is its version 4.0 as your `ffmpeg`'s version is 4.2.2? Are you able to check codecs/formats on your server? If so, try `ffmpeg -formats` or `ffmpeg -codecs`. It may help you. – unclexo Jun 13 '20 at 09:15
  • because i used laravel 5.8 in my project and latest version is 4.0.ffmpeg - formats and -codecs is ok – vahid zolfaghari Jun 13 '20 at 10:14