Search code examples
phpffmpegffmpeg-php

Extract frame from video - PHP-FFMpeg


I am using php ffmpeg in a laravel project, to do multiple things probe, extract frame and encode. I am having an issue when creating a frame from the uploaded video file. This is how the frame is created:

    $video = $ffmpeg->open($destinationPath.'/'.$filename);

    $video
        ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
        ->save(public_path().$frame_path);

This is sometimes working and creates the frame but other times is not. I noticed that this bug comes up when I am trying to open a .mov file.


Solution

  • It's possible that your version of ffmpeg does not support the codec that is used in the source video file, and hence it is not able to decompress the video and extract an image.

    You could try processing the file from the command line to see if you can extract an image that way, and ffmpeg may give you some more information on the problem.

    An example command line to extract a png frame from a video file

    ffmpeg -y -ss 30 -i [source_file] -vframes 1 [target_file]
    

    Add -f image2 as an output option if your output name is a variable.