Php specifies a frame as an image for video capturing. _ PHP Tutorial

Source: Internet
Author: User
Tags learn php programming
Php specifies a frame for video capturing as an image ,. Php specifies a video frame as an image and a video frame as an image. the phpffmpeg extension has been perfectly implemented: $ movienewffmpeg_movie ($ video_filePath ); $ ff_frame $ movie-getFrame (1. specify the video captured by php as an image,

Specify a frame as an image for video capturing. The php ffmpeg extension has been perfectly implemented:

$movie = new ffmpeg_movie($video_filePath);$ff_frame = $movie->getFrame(1);$gd_image = $ff_frame->toGDImage();$img="./test.jpg";imagejpeg($gd_image, $img);imagedestroy($gd_image);

However, the problem is that the video taken by the smartphone will be rotated with the meta information rotate due to different shooting directions. when you intercept a frame image from a video, if a video with rotate information is rotated, the frame must be rotated accordingly.

The php ffmpeg extension does not know the rotation information (php ffmpeg extension document), but can be obtained through the ffmpeg command line:

/Usr/local/ffmpeg/bin/ffprobe test.mp4-show_streams | grep rotate
Php is encapsulated as follows:

function get_video_orientation($video_path) {  $cmd = "/usr/local/ffmpeg/bin/ffprobe " . $video_path . " -show_streams 2>/dev/null";  $result = shell_exec($cmd);   $orientation = 0;  if(strpos($result, 'TAG:rotate') !== FALSE) {    $result = explode("\n", $result);    foreach($result as $line) {      if(strpos($line, 'TAG:rotate') !== FALSE) {        $stream_info = explode("=", $line);        $orientation = $stream_info[1];      }    }  }  return $orientation;}

Use the imagerotate () function to rotate:

$movie = new ffmpeg_movie($video_filePath);$frame = $movie->getFrame(1);$gd = $frame->toGDImage();if ($orientation = $this->get_video_orientation($video_filePath)) {  $gd = imagerotate($gd, 360-$orientation, 0);}$img="./test.jpg";imagejpeg($gd, $img);imagedestroy($gd_image);

Finally, there is another annoyance. not all players and browsers can recognize orientation and automatically rotate video. if you want to rotate the video, you can use the ffmpeg command to solve the problem:

/Usr/local/ffmpeg/bin/ffmpeg-I input.mp4-vf 'transpose = 3'-metadata: s: v: 0 rotate = 0

The above is all the content of this article. I hope it will help you learn php programming.

Specifies the frame to be captured as an image. php ffmpeg extension has been perfectly implemented: $ movie = new ffmpeg_movie ($ video_filePath); $ ff_frame = $ movie-getFrame (1...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.