| Q | A
| -------------- | ---
| Bug? | no
| New Feature? | no
| Version Used | dev-master#c11b79ab5b0174aa1a56c54c67491169e78a4c17
| FFmpeg Version | 4.0.2
| OS | MacOS High Sierra 10.13.6
I am trying to concat two videos, but I am getting the following error:
ffmpeg failed to execute command '/usr/local/bin/ffmpeg' '-f' 'concat' '-safe' '0' '-i' '/private/var/folders/dw/919v2nds7s78pz_qhp7z9rcm0000gn/T/ffmpeg-concateaHp0L' '-c' 'copy' '/Users/francescomussi/Desktop/Apps/cameraProject/back-end/camera-laravel/storage/app/public/videos/output.mp4'
This is a dump of the commands:

I expected the command to be executed.
For the code I am following the docs:
$video = $ffmpeg->open( $path1 );
$video
->concat(array($path1, $path2))
->saveFromSameCodecs($path_output, TRUE);
EDIT:
I have tried a basic resizing and conversion and it worked fine.
So it should everything alright with the installation of the library and the installation of FFMpeg in the system.
So it may be just related with some details concerning the concat.
EDIT2:
I have opened a SO question: https://stackoverflow.com/questions/52593866/php-ffmpeg-how-to-properly-concatenate-two-videos
And it seems that another user (this time on windows) encounter the same issue.
Could you please be so kind to test if the concat function it is still working properly?
Thanks!
I got the same error on windows. Changing the following line in the library
https://github.com/PHP-FFMpeg/PHP-FFMpeg/blob/fc8dbd6f02d1682c8db810b30897bf0bc5219db0/src/FFMpeg/Media/Concat.php#L108
to
$line .= "file '" . $videoPath . "'";
fixed the error for me. But I am not sure about the correct escaping.
Here the contents of the temp file not working
file C:\Users\Roland\Documents\MyStuff\programmieren\test/big_buck_bunny.mp4
file C:\Users\Roland\Documents\MyStuff\programmieren\test/big_buck_bunny.mp4
and here the working version
file 'C:\Users\Roland\Documents\MyStuff\programmieren\test/big_buck_bunny.mp4'
file 'C:\Users\Roland\Documents\MyStuff\programmieren\test/big_buck_bunny.mp4'
I think I have found the cause.
When I am trying to concat using the command line:
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
I get this error:

And that may be because the two video files have audio opus codec.
So if I run this commands it works:
ffmpeg -f concat -safe 0 -i mylist.txt -c:v copy -c:a aac output.mp4
The video is properly created as a concatenation of the two videos.
Do you know how can change the code, in order to convert the output file to aac?
Do you know how can change the code, in order to convert the output file to aac?
Not supported directly, yet. Although it sounds very decent for a new version(1.x).
Thanks for replying @jens1o.
I am now try a simple concat using two files mp4 with aac audio codec.
It should work but it doesn't :(
Everytime I get this error:
ffmpeg failed to execute command '/usr/local/bin/ffmpeg' '-f' 'concat' '-safe' '0' '-i' '/private/var/folders/dw/919v2nds7s78pz_qhp7z9rcm0000gn/T/ffmpeg-concatVZ6Ncg' '-c' 'copy' '/Users/francescomussi/Desktop/Apps/cameraProject/back-end/camera-laravel/storage/app/public/videos/output.mp4'
Do you know why? What can be the reason ffmpeg cannot execute the command?
Did somebody encounter a similar problem?
Do you have some hints for more debugging.. I am totally out of ideas...
Please send us the hole output of /usr/local/bin/ffmpeg -f concat -safe 0 -i /private/var/folders/dw/919v2nds7s78pz_qhp7z9rcm0000gn/T/ffmpeg-concatVZ6Ncg -c copy /Users/francescomussi/Desktop/Apps/cameraProject/back-end/camera-laravel/storage/app/public/videos/output.mp4
This is the output:
/private/var/folders/dw/919v2nds7s78pz_qhp7z9rcm0000gn/T/ffmpeg-concatVZ6Ncg: No such file or directory

This is what happen inside the folder /private/var/folders/dw/919v2nds7s78pz_qhp7z9rcm0000gn/T/ right after I run the command:

Something is being created and deleted soon afterwards
Okay, more debugging here. Could you give me a full list of files(with their respective filepath) you want to concat?
These are the paths of the two mp4 videos and the output:

If I can exclude with certainty some reasons for the failure I would say:
What else can be?
The library has been installed through the laravel bundle: https://github.com/pascalbaljetmedia/laravel-ffmpeg
In the composer.json of that bundle, the PHP-FFMpeg library is included as following:
"php-ffmpeg/php-ffmpeg": "dev-master#c11b79ab5b0174aa1a56c54c67491169e78a4c17",
Is that correct? I am not sure which version is that..
And actually this is the whole code:
$disk = FFMpeg::fromDisk('local');
$video1 = $disk->open('public/videos/test3.mp4');
$video2 = $disk->open('public/videos/test4.mp4');
$output = $disk->open('public/videos/output.mp4');
$path1 = $video1->getPathfile();
$path2 = $video2->getPathfile();
$output_path = $output->getPathfile();
$result = $video1
->concat([$path1, $path2])
->saveFromSameCodecs($output_path, TRUE);
return response()->json(compact('result'));
The issue has been finally been resolved!
The problem was that I totally misunderstood about the output file.
I thought it had to exists and with video and audio coded of the other videos.
I don't remember where I read it or if I dream about.
That was the reason why it was failing...
If the output doesn't exists then everything works perfectly!!
Thank you very much for your time and sorry for trivial error!
By the way is it possible to improve that error message in the source code.
For example:
before executing the commands - check that there is no existing file in the output_path given.
If it exists then give error: 'output file already exists in the path given. Commands cannot be executed'
Something like that.
Otherwise ffmpeg failed to execute command ... is generic and difficult to identify the actual cause.
If is possible would be great!
Great! Yeah, giving users a hint what could have failed is on track #310 :)
Ah great! That will be perfect!
If anyone is still encountering this problem (on Window at least), consider the following code :
// Creating the files to work with
// $this->storage --> \Illuminate\Support\Facades\Storage::disk('testing')
if (!$this->storage->exists('ffmpeg/file-to-concat-1.mp4')) {
$this->storage->copy('ffmpeg/some-file.mp4', 'ffmpeg/file-to-concat-1.mp4');
}
if (!$this->storage->exists('ffmpeg/file-to-concat-2.mp4')) {
$this->storage->copy('ffmpeg/some-file.mp4', 'ffmpeg/file-to-concat-2.mp4');
}
if (!$this->storage->exists('ffmpeg/file-to-concat-3.mp4')) {
$this->storage->copy('ffmpeg/some-file.mp4', 'ffmpeg/file-to-concat-3.mp4');
}
$basePath = storage_path('app/testing/ffmpeg');
// $this->ffmpeg --> \Pbmedia\LaravelFFMpeg\FFMpegFacade
$this->ffmpeg::fromDisk('testing')->open('ffmpeg/file-to-concat-1.mp4')
->concat([
str_replace('\\', '/', $basePath . '/file-to-concat-2.mp4'),
str_replace('\\', '/', $basePath . '/file-to-concat-3.mp4')
])
->saveFromSameCodecs(str_replace('\\', '/', $basePath . '/' . time() . '-concatenated-file.mp4'), true);
The important things to note here are :
str_replace('\\', '/', 'full-path-to-file-to-concat.mp4')saveFromSameCodecs(str_replace('\\', '/', 'full-path-to-concatenated-file-uniquely-named.mp4'), true);Explication
My code kept throwing the _"Unable to save concatenated video"_ error and it was impossible to figure out why from the this PHP package side of things. So I in my terminal I had to reproduce what the Concat.php#L82 was doing, which is (for those too lazy to read the code) :
Create a _file-to-concat-list.txt_ with the following content :
file C:/[...]/file-to-concat-2.mp4
file C:/[...]/file-to-concat-3.mp4
_replacing all the \ with /_, otherwise you'll get an Impossible to open 'file-to-concat-2.mp4'.
And finally running the command :
"C:/ffmpeg/bin/ffmpeg.exe" -f concat -safe 0 -i C:/[...]/file-to-concat-list.txt -c copy "C:/[...]/concatinated-file.mp4"
After some trials and errors I adapted my code to one that finally work as posted above.
Oh and yeah, make sure the output file does not exist otherwise you'll get an other error.
Hope it helps 馃憣
Most helpful comment
If anyone is still encountering this problem (on Window at least), consider the following code :
The important things to note here are :
str_replace('\\', '/', 'full-path-to-file-to-concat.mp4')saveFromSameCodecs(str_replace('\\', '/', 'full-path-to-concatenated-file-uniquely-named.mp4'), true);Explication
My code kept throwing the _"Unable to save concatenated video"_ error and it was impossible to figure out why from the this PHP package side of things. So I in my terminal I had to reproduce what the Concat.php#L82 was doing, which is (for those too lazy to read the code) :
Create a _file-to-concat-list.txt_ with the following content :
_replacing all the
\with/_, otherwise you'll get anImpossible to open 'file-to-concat-2.mp4'.And finally running the command :
After some trials and errors I adapted my code to one that finally work as posted above.
Oh and yeah, make sure the output file does not exist otherwise you'll get an other error.
Hope it helps 馃憣