PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label ffmpeg-php. Show all posts
Showing posts with label ffmpeg-php. Show all posts

Tuesday, May 17, 2022

[FIXED] How to trim a video by 4 fragments to 4 seconds using the PHP-FFMpeg?

 May 17, 2022     ffmpeg, ffmpeg-php, php     No comments   

Issue

How to trim a video using the PHP-FFMpeg? I need to implement the following FFMpeg command:

ffmpeg -i 7207783801bb.mp4 -filter_complex \
"[0:v]trim=start=10:end=11,setpts=PTS-STARTPTS[a]; \
 [0:v]trim=start=20:end=21,setpts=PTS-STARTPTS[b]; \
  [a][b]concat[c]; \
 [0:v]trim=start=30:end=31,setpts=PTS-STARTPTS[d]; \
 [0:v]trim=start=40:end=41,setpts=PTS-STARTPTS[f]; \
   [d][f]concat[g]; \
 [c][g]concat[out1]" -map [out1] 7207783801bbout.mp4

When I use the following code:

$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('7207783801bb.mpg');
$video->filters()->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(10), FFMpeg\Coordinate\TimeCode::fromSeconds(11));
$video->filters()->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(20), FFMpeg\Coordinate\TimeCode::fromSeconds(21));
$video->filters()->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(30), FFMpeg\Coordinate\TimeCode::fromSeconds(31));
$video->filters()->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(40), FFMpeg\Coordinate\TimeCode::fromSeconds(41));
$video->save(new FFMpeg\Format\Video\X264(), '7207783801bbout.mp4');

then I get only 40 seconds of video. And I need to get 10-11, 20-21, 30-31, 40-41 seconds using the PHP-FFMpeg. Only 4 seconds.


Solution

I this case FFMpeg\Media\AdvancedMedia can be used

$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->openAdvanced(['7207783801bb.mp4']);
$video->filters()
    ->custom('[0:v]', 'trim=start=10:end=11,setpts=PTS-STARTPTS', '[a]')
    ->custom('[0:v]', 'trim=start=20:end=21,setpts=PTS-STARTPTS', '[b]')
    ->custom('[a][b]', 'concat', '[c]')
    ->custom('[0:v]', 'trim=start=30:end=31,setpts=PTS-STARTPTS', '[d]')
    ->custom('[0:v]', 'trim=start=40:end=41,setpts=PTS-STARTPTS', '[f]')
    ->custom('[d][f]', 'concat', '[g]')
    ->custom('[c][g]', 'concat', '[out1]')
;
$video
    ->map(['[out1]'], new \FFMpeg\Format\Video\X264(), '7207783801bbout.mp4')
    ->save();


Answered By - tarasikarius
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, January 24, 2022

[FIXED] i have installed composer and now need to install php_ffmpeg

 January 24, 2022     composer-php, ffmpeg, ffmpeg-php, php     No comments   

Issue

hey all i have successfully downloaded and installed composer on my windows7 64bit wamp server and i need to install php_ffmpeg by composer. i don't have any idea i have already read their documentation but it is not so clear ? please let me know the next step.

i got the details about the composer and php_ffmpeg from this link

https://github.com/PHP-FFMpeg/PHP-FFMpeg

here is the code that i get when i update,require and install composer by cmd

C:\Windows\system32>composer update
 Loading composer repositories with package information
Updating dependencies (including require-dev)
 Nothing to install or update
 Generating autoload files

 C:\Windows\system32>composer require php-ffmpeg/php-ffmpeg
    Using version ^0.6.0 for php-ffmpeg/php-ffmpeg
   ./composer.json has been updated
     Loading composer repositories with package information
     Updating dependencies (including require-dev)
     Nothing to install or update
      Generating autoload files

       C:\Windows\system32>composer install
      Loading composer repositories with package information
      Installing dependencies (including require-dev) from lock file
       Nothing to install or update
        Generating autoload files

here is the screenshot of my wamp server and installed modules

enter image description here


Solution

There are two ways to do that,

  1. From command line
composer require php-ffmpeg/php-ffmpeg
  1. Add to "require" section into your composer.json
  "require": {
      "php-ffmpeg/php-ffmpeg": "dev-master"
  }

and execute

composer install



Answered By - Eugene Nezhuta
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing