FFMPEG command not running from php but working in cmd - php

i have this function in my laravel controller
foreach ($arrayi['audio'] as $i => $audioFile) {
// Loop through the audio files and image files
// Create a new video with the audio file and image file
$dimensions = "1024x1024";
// Set the audio and image file paths
$audioPath = public_path("storage/{$arrayi['audio'][$i]}");
$imagePath = public_path("storage/{$arrayi['links'][$i]}");
$duration = exec("ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 {$audioPath}");
// Set the command to create the video
$command =exec("ffmpeg -loop 1 -i {$audioPath} -i {$imagePath} -t {$duration} -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p output_{$i}.mp4");
// Add the output video to the array of output videos
$outputVideos[] = public_path("storage/output_{$i}.mp4");
}
which is supposed to create multiple videos by running the ffmpeg command one by one for each image and audio. this is all done after clicking a button in browser.
I've tried printing the $command and then running it in cmd in windows and it all works fine but when i do it through the browser nothing happens. the $duration command works fine it passes the duration to the ffmpeg command .

Related

merging images to create video using ffmpeg

I am creating a video from images using ffmpeg. I am using a file that contains the list of images as
file 'C:\wamp64\www\test\public\userFolder\media\nature3.jpg'
file 'C:\wamp64\www\test\public\userFolder\media\img_001.jpg'
file 'C:\wamp64\www\test\public\userFolder\media\img_003.jpg'
file 'C:\wamp64\www\test\public\userFolder\media\img_006.jpg'
file 'C:\wamp64\www\test\public\userFolder\media\nature3.jpg'
file 'C:\wamp64\www\test\public\userFolder\media\nature4.jpg'
I am using the following command to create video
ffmpeg.exe -y -r 1/10 -f concat -safe 0 -i "imagepaths.txt" -c:v libx264 -s 920x640 "Jawedout.mp4"
The video is being created but the start of video is blank. The video show dark black screen for few secs then show the first image mentioned in file.
However, if the change the command to
ffmpeg.exe -y -f concat -safe 0 -i "imagepaths.txt" -c:v libx264 -vf "fps=25,format=yuv420p" -s 920x640 "Jawedout.mp4"
Then in video I am not seeing first image and last image.

FFMPEG image resize not working

FFmpeg version 0.6.5 is installed on my web server.
In my website mp4 videos allowed to upload, that part is done.
Now i am working on create a thumbnail of the video and then resize it.
The following links are I referred.
https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg
This is the command i used to create a thumbnail from video, this command is working.
$cmd = "ffmpeg -i test.mp4 -ss 0 -vframes 1 out.png";
After creating the thumbnail, I tried the following the command to resize it, but this is not working.
$cmd = 'ffmpeg -i out.png -vf scale=210:-1 output_320x240.png';
And Some other commands i have tried
$cmd = "ffmpeg -ss 10 -i test.mp4 -vframes 1 -filter scale=-1:150,crop=200:150 output.jpg";
$cmd = "ffmpeg -itsoffset -1 -i test.mp4 -vframes 1 -filter:v scale=280:-1 output.jpg";
In my localhost I used the following command to create thumbnail and resize in a single command, but this is also not working in the server.
$ffmpeg = 'C:\\ffmpeg\\bin\\ffmpeg';
$video = 'test.mp4';
$cmd = "$ffmpeg -itsoffset -1 -i $video -vframes 1 -filter:v scale=\"210:-1\" thumbnail.png";
Thanks to all

swf action script convert into flv

this is a action script : symmetrydigital-labs.com/junior/kazim/portal/flv/Shahid_Kapoor_07.swf
image is call outside from server.
i want to convert this .swf file into .flv and generate thumbnail.
Problem :
1: .swf file converts only video not with image (call from outsource) .swf
2: code was not run in server run only in localhost.
and i am try to using this command
$ffmpeg = 'C:\FFmpeg\ffmpeg-20130614-git-6fe419b-win32-static\bin\ffmpeg';
$ffmpeg = '/usr/bin/ffmpeg';
$cmd = "$ffmpeg -i Shahid_Kapoor_07.swf Shahid_Kapoor_07.flv";
$image = "$ffmpeg -i Shahid_Kapoor_07.swf -an -ss 00:00:03 -an -r 1 -vframes 1 -y abc.jpg";
shell_exec($cmd);
shell_exec($image);

ffmpeg Getting image or thumbnail from video error

i have a simple site on which people upload videos, so i want to generate a simple thumbnail from an uploaded video. i have tried every trick and way to do this from a number of websites but i am failing to make the command run without problems.
$video = $_FILES['vpopupdropin']["tmp_name"];
$ffmpeg = "C:\\Ffmpeg\\ffmpeg-20130605-git-3289670-win64-static\\bin";
$image = "manu.jpg";
$second = 12;
$size = "150x90";
$command = "$ffmpeg -i $video -an -ss $second -s $size -vcodec mjpeg $image";
echo $command;
shell_exec($command);
if(shell_exec($command)){
echo 'okay';
echo '<img src="'.$image.'"/ >';
}
else{
echo ' Problem';
}
i Echoed the the command from PHP and this is what i got:
C:\Ffmpeg\ffmpeg-20130605-git-3289670-win64-static\bin -i C:\xampp\tmp\php27F1.tmp -an -ss 12 -s 150x90 -vcodec mjpeg manu.jpg Problem
so i took the Command above and entered it in Cmd and got this error
[image2 # 00000000000000003d87580] Could not open file : manu.jpg
av_interleaved_write_frame(): Input/output error. the uploaded file transfers well to where iam saving it and plays well on the site meaning the file is not corrupt. but the thumbnail command seems to fail, i have even checked the other questions on this site but i seem to fail to get the right solution. the paths in the Command are correct and i have verified that at least
You did not give ffmpeg a name :-) So you tried to execute a \\bin folder !
$ffmpeg = "C:\\Ffmpeg\\ffmpeg-20130605-git-3289670-win64-static\\bin";
you forget ffmpeg.exe
$ffmpeg = "C:\\Ffmpeg\\ffmpeg-20130605-git-3289670-win64-static\\bin\\ffmpeg";
I do it for a .avi with following command
ffmpeg -i Echo2012.avi -r 1 -s 1024x576 -f image2 -vframes 1 foo-001.jpg
Don't execute your command twice !
$command = "$ffmpeg -i $video -an -ss $second -s $size -vcodec mjpeg $image";
echo $command;
shell_exec($command);
if(shell_exec($command)){
EDIT :
your command string :
ffmpeg -i upload.tmp -an -ss 12 -s 150x90 -vcodec mjpeg manu.jpg
-vcodec codec (output) : Set the video output codec. It's a switch for a output video. You want as output an image.
-an : You can disable Audio stream. You don't need Audio for an image.
-ss : position (input/output) When used as an input option (before -i), seeks in this input file to position.
my command string :
ffmpeg -i Echo2012.avi -r 1 -s 1024x576 -f image2 -vframes 1 foo-001.jpg
-r : fps (input/output,per-stream) . Set frame rate (Hz value, fraction or abbreviation).
As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps.
-f image2 : Force output file format image2. The format is normally auto detected guessed from the file extension for output files.
-vframes number (output) : Set the number of video frames to record.

Create thumbnail image from video in server in php

In my website I have a option to upload video file by the user. In that I want to create a thumbnail image of that video. I have tried in local system with some coding it is working fine. I tried same coding in to service it is not working. I checked for ffmpeg enabled in server, it was disabled. Is their any other option to creating thumbnail in server with out enabling the ffmpeg? Please help me to find the solution.
you can use ffmpeg ( Form you tag i guess you knew )
What you needed to pass to ffmpeg is
-i = input file
-deinterlace = deinterlace pictures
-an = disable audio recording
-ss = start time in the video (seconds)
-t = duration of the recording (seconds)
-r = set frame rate
-y = overwrite existing file
-s = resolution size
-f = force format
Example
// where ffmpeg is located
$ffmpeg = '/usr/bin/ffmpeg';
//video dir
$video = 'path/to/video';
//where to save the image
$image = 'path/to/image.jpg';
//time to take screenshot at
$interval = 5;
//screenshot size
$size = '640x480';
//ffmpeg command
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";
exec($cmd);
Or try
$second = 15;
$cmd = "$ffmpeg -itsoffset -$second -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s $size $image";
exec($cmd);
Think you should also look at detail dissuasion on possible issues
ffmpeg-php to create thumbnail of video
If you don't want to use ffmpeg you could use mencoder as an alternative too. But in the end you will need to install ffmpeg/mencoder and then use that to render the thumbnail as PHP has no built in functionality to handle video.
If you're on a shared webhost you might want to look into services like zencoder that can generate you converted streams of video including thumbnails:
https://app.zencoder.com/docs/api/encoding/thumbnails

Categories