ffmpeg Getting image or thumbnail from video error

2019-08-05 14:48发布

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

标签: php ffmpeg cmd
1条回答
干净又极端
2楼-- · 2019-08-05 15:23

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.
查看更多
登录 后发表回答