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.63k stars 194 forks source link

Convert ffmpeg command to laravel-ffmpeg (concat videos) #448

Closed truongbo17 closed 1 year ago

truongbo17 commented 1 year ago

I have some ffpmeg commands to join videos together :

mpeg -i 1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1.ts
ffmpeg -i 2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2.ts

ffmpeg -i "concat:temp1.ts|temp2.ts" -c copy -bsf:a aac_adtstoasc output.mp4

How can i convert to code using laravel-ffmpeg functions ?

I tried :

FFMpeg::fromDisk('video')
                ->open(['video1.mp4', 'video2.mp4'])
                ->export()
                ->toDisk('video_export')
                ->concatWithoutTranscoding()
                ->save('output.mp4');

It created new videos based on existing videos but the problem is that it has a lot of errors where it can't watch videos,

Jandelson commented 1 year ago

Hi @truongbo17 i use its as follows

FFMpeg::fromDisk(env('FROM_DISK', ''))

->open($data['array'])

->export()

->addFilter($data['filter'], 'concat=n=' . $data['countVideos'], ':v=1[v]')  // $in, $parameters, $out

->addFormatOutputMapping(
          $videoFormat->getInstanceObject(),
          Media::make('local', $data['file']),
          ['[v]', '0:a']
)->save();

where

$data['array'] = ['sound.mp3', 'video1.mp4','video2.mp4']
$data['filter'] = "[1:v],[2:v]"
$data['countVideos'] = 2
$data['file'] = 'newVideo.mp4'

in ['[v]', '0:a'] 0:a received the index 0 object array that represent sound.mp3

I hope to help you. Have a nice day!

truongbo17 commented 1 year ago

ohh , thank you , i will try it