how to extract images from a video file using ffmp

2019-09-07 02:52发布

I need to get one image out of an video to use as a thumbnail
So I am trying this:

ffmpeg -ss 00:05:34.05 -i input.avi -vframes 1 -sameq output.jpg  

This works just fine however every once in a while I come across a file where this fails with the following error message

av_interleaved_write_frame(): I/O error occurred  

Usually that means that input file is truncated and/or corrupted.

What are my options if any ?
Thanks

标签: ffmpeg
4条回答
倾城 Initia
2楼-- · 2019-09-07 03:09

yes it is possible using ffmpeg.

-install ffmpeg in your server.
-check below example code.

extension_loaded('ffmpeg') or die('Error in loading ffmpeg');

// $vid = realpath('./video/Wildlife.wmv');

$video_url = 'http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4';

$image_filename = 'images/' . time() . ".jpg";

$movie = new ffmpeg_movie($video_url, false);

$frameCount = $movie->getFrameCount();

$capPos = ceil($frameCount / 4);

$frameObject = $movie->getFrame($capPos);

if ($frameObject) {

    $frameObject->resize(500, 250, 0, 0, 0, 0);

    imagejpeg($frameObject->toGDImage());

} else {

    echo 'error';

}
查看更多
时光不老,我们不散
3楼-- · 2019-09-07 03:25

I think is easier if you extract one of the first frames as a thumbnail.

Instead of -ss I use -vf thumbnail=num_frame

ffmpeg -i input.avi -vf thumbnail=25 -vframes 1 -sameq output.jpg
查看更多
冷血范
4楼-- · 2019-09-07 03:27

Try this command

ffmpeg -ss 5 -i sample.mp4 -vframes 1 -s 320x240 -f image2 -y sample.jpg;

always set -ss before -i in order to optimize performance while grabbing thumbs from long length videos.

查看更多
爷、活的狠高调
5楼-- · 2019-09-07 03:32

ok this seemed to work for me ffmpeg -itsoffset -4 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg

查看更多
登录 后发表回答