PHP Classes

PHP Screen Recorder: Capture videos of the current screen with ffmpeg

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 73%Total: 495 All time: 5,859 This week: 54Up
Version License PHP version Categories
phpscreenrecorder 1.0.1MIT/X Consortium ...5PHP 5, Graphics, Debug, Audio, Video
Description 

Author

This class can capture videos of the current screen with ffmpeg.

It executes the ffmpeg program passing some options to configure details of the recording such as the screen size to capture.

The video file is saved to a configurable file in Flash Video.

Innovation Award
PHP Programming Innovation award nominee
August 2017
Number 2


Prize: PhpStorm IDE 1 year individual subscription
Capturing videos from the user computer screen is useful to help developers understand the way users are interacting with their applications.

This class can capture the current screen by using the ffmpeg program.

Manuel Lemos
Picture of Dawood Ikhlaq
  Performance   Level  
Name: Dawood Ikhlaq <contact>
Classes: 8 packages by
Country: Italy Italy
Age: 30
All time rank: 194476 in Italy Italy
Week rank: 159 Up2 in Italy Italy Up
Innovation award
Innovation award
Nominee: 4x

Recommendations

Example

<?php
/**
 * Created by PhpStorm.
 * User: dawood.ikhlaq
 * Date: 7/17/2017
 * Time: 12:44
 */

include "../vendor/autoload.php";

use
dawood\PhpScreenRecorder\ScreenRecorder;




$screenRecorder=new ScreenRecorder();
$screenRecorder->setScreenSizeToCapture(1920,1080);

$screenRecorder->startRecording(__DIR__.DIRECTORY_SEPARATOR.'myVideo');
sleep(5+2);
$screenRecorder->stopRecording();


print
"video is saved at :\"".$screenRecorder->getVideo().'"'.PHP_EOL;


Details

PHP Screen Recorder

A lightweight php wrapper around ffmpeg to record the screen, best for recording your acceptance tests using selenium, it's easy to use and clean OOP interface.

History

I was given a task to make an acceptance test suite which included recording videos of the tests. I was using selenium for the task and for the video recording, however, I was unable to find an elegant solution which is why i created this library.

Usage

One of the best features of this library is its ease of use.

The startRecording method is called when the user wants to start the recording after which this library will start the video recording in the background. When the user has completed their task they can call stopRecording to stop the recording .

Installation

The library is easily installed as a package through composer:

composer require dawood/phpscreenrecorder

that's it, nothing else is required for the installation

Examples

There are examples provided in examples folder as well.

Make sure, that you include the composer autoloader somewhere in your codebase.

Capture the screen


include "../vendor/autoload.php";

use dawood\PhpScreenRecorder\ScreenRecorder;

$screenRecorder=new ScreenRecorder();
$screenRecorder->setScreenSizeToCapture(1920,1080);

$screenRecorder->startRecording(__DIR__.DIRECTORY_SEPARATOR.'myVideo');
sleep(5+2);//doing random stuff
//when done stop recording
$screenRecorder->stopRecording();

print "video is saved at :\"".$screenRecorder->getVideo().'"'.PHP_EOL;

Selenium test example


public function testLoginUserCorrectly()
{
    $this->screenRecorder->setScreenSizeToCapture(1920,1080);
    $this->screenRecorder->startRecording(__DIR__."/videos/loginCorrectly.flv",2);
    $loginInput = [
        'username' => 'test',
        'password' => 'password'
    ];
    $this->visit('/')
        ->submitForm("#loginform > form",$loginInput)
        ->wait(3)
        ->see("Logout")
        ->wait(2);
    $this->screenRecorder->stopRecording(0);

}

Setting options

The ffmpeg shell command can accept different options: for a complete list of options you can visit: http://ffmpeg.org/ffmpeg.html

Wrapper Methods

* setOptions accepts the options in the array. You can provide any option in following way:

       $options['-show_region'=>'1']
       $screenRecorder->setOptions($options);

> Note: you have to write complete option including "-" , i had to do this way because there are some options which need "-" this and some which not so it's difficult to know for which option i have to set that that's why you have to provide complete option.

  • `setScreenSizeToCapture` screen size to capture, it accepts two arguments the first being the width and other being the height.
  • `startRecording` call this method after you have set all the desired options, this will start the screen recording. The method accepts two optional arguments, firstly the desired location to save the video file and secondly the number of seconds to sleep after starting the process. This is useful because ffmpeg takes 1-2 seconds to start the recording, the default value for this is 2 seconds. You can may change this according to your requirements.
  • `stopRecording` this will stop the screen recording. The method can also take one optional argument, the number of seconds to sleep after starting the process. This is useful because ffmpeg takes 1-2 seconds to start the recording.
  • `getVideo` returns the saved video file.
  • `setBinary` for this library you do not require any binary as everything is already included, however, if you need to use any other binary you can provide it using this method.
  • `getCommandToRun` returns the generated command that will be executed by library. This is useful to check how you have set the options or to debug.
  • `getOptions` returns an array of all the set options.
  • `getBinary` returns the currently set binary file i.e ffmpeg.

License

The PHP Screen Recorder is open-sourced software licensed under the MIT license.

Contribution

Thanks to all of the contributors , fork this repository and send me a pull request

Author

Dawood Ikhlaq and Open source community


  Files folder image Files (6)  
File Role Description
Files folder imageexamples (1 file)
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (6)  /  examples  
File Role Description
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (6)  /  src  
File Role Description
  Plain text file ScreenRecorder.php Class Class source

  Files folder image Files (6)  /  tests  
File Role Description
  Plain text file ScreenRecorderTestSuite.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:495
This week:0
All time:5,859
This week:54Up
User Ratings User Comments (3)
 All time
Utility:93%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:87%StarStarStarStarStar
Tests:-
Videos:-
Overall:73%StarStarStarStar
Rank:148
 
good
5 years ago (Lee H)
80%StarStarStarStarStar
good
5 years ago (Lee H)
80%StarStarStarStarStar
thank you
6 years ago (Sinan Çak?ro?lu)
60%StarStarStarStar