Reputation: 11
I have a cron setup to take locally uploaded videos, create a screengrab, compress the video and upload to online storage. I am using ffmpeg with php and have tried a few different ways but though it does compress the file size I keep getting a saved file of just the first second of the video. I tried delaying the process in case it just didn't have enough time to do the video and that was the cause but it didn't seem to do much. Here are some of the examples of the code I've tried all together (commented out as tried each but you can see the different ways):
try {
// compress video if needed
$bitrate = "5000k";
// $command = "ffmpeg -i ".($temp_dir."/".$folder."/".$sub_file)." -b:v $bitrate -bufsize $bitrate ".$temp_dir."/".$folder."/edit-".$sub_file;
// $command = "ffmpeg -i $temp_video -qscale 0 ".$temp_dir."/".$folder."/edit-".$sub_file;
$command = "ffmpeg -i ".($temp_dir."/".$folder."/".$sub_file)." -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 ".$temp_dir."/".$folder."/edit-".$sub_file;
//system($command);
$output=null;
$retval=null;
exec($command, $output, $retval);
$temp_video = $temp_dir."/".$folder."/edit-".$sub_file."";
} catch (Exception $e) {
// log output
}
Is there a known issue with this or something I'm missing?
Thanks
Upvotes: 1
Views: 148
Reputation: 68
I'm a new user, I can't write a comment.
Try looking at the log file. Sometimes you can read the cause of premature death there.
$command = "ffmpeg -i ".($temp_dir."/".$folder."/".$sub_file)." -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 ".$temp_dir."/".$folder."/edit-".$sub_file." > ".$temp_dir."/".$folder."/log-".$sub_file.".log 2>&1 ";
I also recommend you to use -y to overwrite result files.
$command = "ffmpeg -y -i ".($temp_dir."/".$folder."/".$sub_file)." -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 ".$temp_dir."/".$folder."/edit-".$sub_file." > ".$temp_dir."/".$folder."/log-".$sub_file.".log 2>&1 ";
Upvotes: 1