📜 ⬆️ ⬇️

Getting statistics and screenshots of the video using php5-ffmpeg

We continue to do youtube habrahabr.ru/post/171225

An open question - with the departure of ffmpeg from Ubuntu, what will replace the php5-ffmpeg module? Report in the comments if you know something.

Under the cat is a small function written in PHP5, using the php5-ffmpeg module, which extracts screenshots and statistics from the video.

')
Installing the php5-ffmpeg module in Ubuntu

sudo apt-get install php5-ffmpeg 


The function takes parameters
$ video - full server path to the (uploaded) video
$ screens_path - pass the full server path to take screenshots
$ screens_count - number of screenshots

 function movie_progress($video,$screens_path = FALSE,$screens_count = 10) { $movie = new ffmpeg_movie($video); if ( ! $movie) { return; } $frame_count = $movie->getFrameCount(); //   $screens = FALSE; if ($screens_path) { //  ,      $step = floor($frame_count / ($screens_count)); $screens = array(); //  ,      for ($i = $step; $i < $frame_count; $i += $step) { $filename = $path.md5(rand()).'.png'; $frame = $movie->getFrame($i); $image = $frame->toGDImage(); imagepng($image,$filename); if (is_file($filename)) { $screens[] = $filename; } } } //      return array( 'width' => $movie->getFrameWidth(), //    'height' => $movie->getFrameHeight(), //    'frame_count' => $frame_count, //   'bitrate' => $movie->getBitRate(), //  'video_bitrate' => $movie->getVideoBitRate(), 'video_codec' => $movie->getVideoCodec(), 'audio_codec' => $movie->getAudioCodec(), 'screens' => $screens, //    ); } 


You can modify in any way, at your discretion.

The $ movie-> getAuthor (), $ movie-> getCopyright (), $ movie-> getArtist (), $ movie-> getGenre (), and similar methods for unknown reasons cause a fatal error that is not caught by PHP.

Documentation for the module ffmpeg-php.sourceforge.net/doc/api/index.php

Format conversion and watermark overlay habrahabr.ru/post/171225

Source: https://habr.com/ru/post/171239/


All Articles