i want to merge some image files (jpeg,png) to a short stop motion video clip.
The User can upload the images and the webapp will do a short movie... Thats the plan.
I have tried some variations i found in www -> exec, shell_exec
The ffmpeg.exe is in my root Folder (xampp/htdocs/xxx/ffmpeg.exe)
I put a function in my controller to do the clip.
public function render() {
// Save the Session ID into the variable sessionId
$sessionId = $this->session->userdata('session_id');
// Path to the Userimage-Folder
$image_path = "C:\xampp\htdocs\xxx\uploads\$sessionId";
$command = "C:\xampp\htdocs\xxx\ffmpeg -framerate 1/5 -i".$image_path."/img_%03d.JPG -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4";
exec($command);
}
The images are already in the same format and have a consecutive numbering.
I'am still a beginner, so please help me.
regards :)
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 .
I am working on a simple video upload and compression system and I am currently using the following process.
First Step
I use a multipart/form-data to upload the original video file, which I store in /var/www/site/videos_pre/video.mp4. My public folder is var/www/site/public_html/. I store an entry in my database with the video information.
Second step
I have a converter process which is very basic, but does the job (at least in CLI).
It has the following code:
public function converter($content_id)
{
$content = $this->videos_m->get($content_id);
$id = uniqid();
$name_mp4 = $content->name_slug.'_'.$id.'.mp4';
$name_webm = $content->name_slug.'_'.$id.'.webm';
$command_mp4 = 'ffmpeg -i ../videos_pre/'.$content->original_file.' -b:v 1500k -bufsize 1500k ./videos/'.$name_mp4;
system($command_mp4);
$command_webm = 'ffmpeg -i ./videos/'.$name_mp4.' -c:v vp9 -c:a libvorbis ./videos/'.$name_webm;
system($command_webm);
$update_video = new stdClass();
$update_video->archivo_mp4 = $name_mp4;
$update_video->archivo_webm = $name_webm;
$this->db->where('content_id', $content_id);
$this->db->update('Videos', $update_video);
}
Third step - where the problem occurs
I have tested this on Windows 10 and Ubuntu 18.04. The code works on Windows 10 in both php and cli. The code on Ubuntu only works with cli.
The resulting commands are something like this:
// First command to reduce the bitrate of the mp4
ffmpeg -i /var/www/site/videos_pre/video.mp4 -b:v 1500k -bufsize 1500k /var/www/site/public_html/videos/video_5e757d3e0d762.mp4
// Second command to convert the mp4 to a webm to get both types
ffmpeg -i /var/www/site/public_html/videos/video_5e757d3e0d762.mp4 -c:v vp9 -c:a libvorbis /var/www/site/public_html/videos/video_5e757d3e0d762.webm
If I execute those commands they work perfectly. If I run the php script, be it in the browser or via CLI, literally nothing happens. No error messages nothing.
I am not sure if it's a permission issue, if there's something specific for php to run this, or some module I've not activated. I have enough execution time, I have it at 600 seconds, but as I said it doesn't even take time, it just does nothing.
I can even echo the commands and they appear. So, basically the problem is I need to be able to run those commands from PHP. I did it on Windows, but Ubuntu 18.04 won't let me. Both OSs have ffmpeg recently installed and I've been able to convert on both of them.
I tried changing paths from absolute to relative, no difference at all.
So, I managed to solve it, and it turns out it was a permission problem.
I had my /var/www/site folder with permissions like this: myuser:www-data. After checking this answer on a similar issue, I changed the folder permission to www-data:root and it worked instantly.
I hope that permission change doesn't affect the rest of things, but for now everything's working fine.
I am having a live video streaming website and I allow people to upload all the video files to the site till now everything is ok.
What I am doing is that I am using FFMPEG to convert the video to mp4 and also get a image out of the video after 20 seconds.
The code that I am using is that:
require 'vendor/autoload.php';
$getEXT_check=substr(#$_FILES['profileimage99']['name'],-3);
if($getEXT_check !='mp4' && $getEXT_check !='MP4'){
exec('ffmpeg -i '.$uploadfile.' -f mp4 -s 896x504 '.$new_flv.''); }
//execute ffmpeg and create thumb
exec('ffmpeg -i '.$uploadfile.' -ss 00:00:20 -vframes 1 '.$new_image_path);
$theduration=exec('ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 '.$uploadfile.' 2>&1');
$theduration_val=round($theduration/60, 2);
What issue I am having is that
sometimes the code dosent extract the image out of video
video conversation takes very long time for non mp4 video (I am not converting mp4 videos)
Some info what I have done on server. During the development of site I installed ffmpeg on my pc and downloaded the vendor directory by composer.json file. But I have not done these things on my server I have a dedicated server from bluehost and have ffmpeg installed at this location.
/usr/local/bin/ffmpeg
/usr/local/bin/mplayer
/usr/local/bin/mencoder
/usr/bin/flvtool2
/usr/local/bin/MP4Box
/usr/local/bin/yamdi
During uploading the site what I did is that I also uploaded the vendor directory and all the files and made the site live. I haven't used any of the path as given by my server admin after asking.
Please suggest me something where I am doing wrong.
I am using ubuntu 13.04
Version of ffmpeg is ffmpeg version N-61041-g52a2138
Through php, I am calling ffmpeg commands to extract images and do some modification in those images and again merge those images back to video.
While merging all images through ffmpeg command, I need to pass video bit rates.
Command is as below
public function mergeImagesToVideo($frame_no,$user_directory_name,$video_bit_rates,&$output,&$status){
/* merge all of frames to create one second video */
$user_frames_path=$GLOBALS["all_user_dir_path"].$user_directory_name."/";
$command= $GLOBALS['ffmpeg'].' -f image2 -r 30 -i '.
$user_frames_path.'f'.$frame_no.'_%d.png -r 30 -b:v '
.$video_bit_rates.'k '.$user_frames_path.'f'.$frame_no.'.mp4';
//echo $command;
exec($command,$output,$status);
return;
}
The call is made as below
$this->mergeImagesToVideo($start_second,$user_directory,$video_bit_rates,$output,$status);
if($status!=0){
echo "some thing went wrong in merging all images to create a video <br>";
}
Now When check bit rates through ffmpeg command output is like as below
ffmpeg -i f1.mp4
This command shows 7303 kb/s
While I right click the image and show properties, it shows 7295 kbps
Which is the correct one ?? Not getting correct line..
Thanks in advance.
Here's the situation. While uploading a video, I want to capture a screenshot of that video and save it as a video thumbnail. I currently can't install ffmpeg on my local machine (it will be installed on the production server of course) so I cannot test the following controller action helper I wrote for this purpose:
<?php
/**
* FlvThumbnail
*
* #author Richard Knop
*/
class My_Controller_Action_Helper_FlvThumbnail extends Zend_Controller_Action_Helper_Abstract
{
public function direct($flv, $thumbnail) {
$command = "ffmpeg -v 0 -y -i $flv -vframes 1 -ss 10 -vcodec mjpeg -f rawvideo -s 210x140 -aspect 16:9 $thumbnail";
return shell_exec($command);
}
}
$flv is path to the video (this action helper will be executed right after the video is uploaded)
$thumbnail is path where the thumbnail image should be saved
Could anyone please tell me if the above helper will work as I expect? I'm still not sure when will the production server be purchased but I would like to know in advance if this will work.
works OK for me