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.
Related
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 .
hello all i am having this code in my php and i want to get an image after 50% of the duration of the video and also get the duration of the video in a variable i have installed ffmpeg in my php and computer
the page has following code
require 'vendor/autoload.php';
//ececute ffmpeg generate mp4
exec('ffmpeg -i '.$uploadfile.' -f mp4 -s 896x504 '.$new_flv.'');
//execute ffmpeg and create thumb
exec('ffmpeg -i '.$uploadfile.' -f mjpeg -vframes 71 -s 768x432 -an '.$new_image_path.'');
i want an image after 50% of the duration of the video and also store the video duration in a variable
please give me some suggestions i am stuck over here
First you need to get the video duration in second
and then you need to multiply total second to 0.5 to get the half.
Try this one:
$total_sec = exec("ffprobe -loglevel error -show_streams inputFile.mp4 | grep duration | cut -f2 -d=");
$total_half_sec = $total_sec * 0.5;
exec("ffmpeg -i source.mp4 -f mjpeg -vframes $total_half_sec -s 768x432 -an destination.jpg");
For more info here https://www.ffmpeg.org/ffmpeg-all.html
I have a php script which is creating a list of images (usually around 400) to feed to ffmpeg via an exec command, it breaks. Is there another way to send multiple images?
Sample code below
$imgs4vid = "'dir/img1.jpg' 'dir/img2.jpg' 'dir/img3.jpg' 'dir/img4.jpg' 'dir/img5.jpg' etc.."
exec("ffmpeg -r 1/5 -pattern_type glob -i ".$imgs4vid." -c:v libx264 -r 30 -pix_fmt yuv420p ".$vid_name.".mp4 2>&1", $output);
var_dump($output);
I have a way to do with -f concat -i (generatoe a list of files and put her)
Seems like a long way to do it though, must be an easier solution?
Thanks
You can use patterns for input (and output) file names:
ffmpeg -i /dir/img%d.jpg -s 640x480 -vcodec mjpeg /tmp/out.avi
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.
I have series of jpegs , i want to make flv or mpg from all the images . How can i do it with using imagemagik and php .
exec(convert image1.jpg image2.jpg one.flv) make blank flv
Well I would jump stright into using ffmpeg. You can also do it using ImageMagick; however the docs state you need ffmpeg installed, so why have the middleman?
I haven't tested this, fair warning.
/* cmd img series codec bitrate framerate optional -s WidthxHeight and output filename */
exec(ffmpeg -f image2 -i image%d.jpg -vcodec mpeg4 -b 800k -r 12 video.avi);
/* For Mpeg4 *
/*For FLV */
exec(ffmpeg -f image2 -i image%d.jpg -vcodec flv -b 800k -r 12 video.flv);
If you want to use the outdated mpeg2 or mpeg1 formats you can do that as well.
I would suggest connecting via ssh and testing these commands, and hopefully you have ffmpeg installed.
a ffmpeg -formats will show you which formats are supported:
See the docs:
http://ffmpeg.org/ffmpeg.html#Video-and-Audio-file-format-conversion
and this great answer which I stole various things from:
Image sequence to video quality