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

Sunday, November 13, 2022

[FIXED] how to install ffmpeg php extension on plesk centos7

 November 13, 2022     centos, centos7, ffmpeg, php, plesk     No comments   

Issue

please help me installing FFMEPG, i have instilled it but there is no extension in php setting.

in php.d ffmepg is not there.

anyone one know how to install it.


Solution

For PHP >=7.0, simply use composer:

# /opt/plesk/php/7.2/bin/php /usr/lib64/plesk-9.0/composer.phar install php-ffmpeg/php-ffmpeg

For earlier PHP versions:

1. Make sure EPEL is enabled:

# yum repolist | grep epel
*epel/x86_64 Extra Packages for Enterprise Linux 7 - 12559

If it is not, enable it as follows:

# yum install epel* -y

2. Enable RPM Fusion:

# yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
# yum localinstall --nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm

3. Install FFmpeg and dependencies:

# sudo yum install ffmpeg ffmpeg-devel mplayer mencoder flvtool2 libogg libvorbis lame
# sudo yum install make plesk-php56-devel gcc glibc-devel zlib-devel

4. Download ffmpeg-php:

# git clone https://github.com/nilsringersma/ffmpeg-php
# cd ffmpeg-php 
# /opt/plesk/php/5.6/bin/phpize

5. Do configure & make:

# ./configure --with-php-config=/opt/plesk/php/5.6/bin/php-config --enable-skip-gd-check
# make 
# make install

6. Enable the extension:

# echo "extension=ffmpeg.so" > /opt/plesk/php/5.6/etc/php.d/ffmpeg.ini
# plesk bin php_handler --reread

For more general instructions, refer to this guide.



Answered By - Elvis Plesky
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, September 29, 2022

[FIXED] How do you display closed caption format of HLS video stream from an m3u8 URL

 September 29, 2022     closed-captions, ffmpeg, tvos, video, video-streaming     No comments   

Issue

I'm working on a Roku and TVOS app that is going to play HLS videos (VOD and live) as well as MP4. According to the Roku docs EIA-608 is supported on both and should also work on TVOS.

My question is, given URL to the m3u8 how can I tell what specific format (EIA-608,WebVTT etc) of closed captioning is being used in each stream?

Contents of the main m3u8 (note 1st stream says no CC, but it really does have it):

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=380000,RESOLUTION=400x228,CODECS="avc1.66.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
http://d.com/i/video/2426832/2426832_,350,640,1000,2000,.mp4.csmil/index_0_av.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=750000,RESOLUTION=640x360,CODECS="avc1.77.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
http://d.com/i/video/2426832/2426832_,350,640,1000,2000,.mp4.csmil/index_1_av.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1044000,RESOLUTION=1280x720,CODECS="avc1.64001f, mp4a.40.2",CLOSED-CAPTIONS=NONE
http://d.com/i/video/2426832/2426832_,350,640,1000,2000,.mp4.csmil/index_2_av.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2127000,RESOLUTION=1280x720,CODECS="avc1.64001f, mp4a.40.2",CLOSED-CAPTIONS=NONE
http://d.com/i/video/2426832/2426832_,350,640,1000,2000,.mp4.csmil/index_3_av.m3u8

Contents of the 1st stream's m3u8

#EXTM3U
#EXT-X-TARGETDURATION:4
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:4.000,
http://d.com/i/video/2426832/2426832_,350,640,1000,2000,.mp4.csmil/segment1_0_av.ts
...

I can use ffprobe -hide_banner to show the 1st program's stream has closed captioning. Ex:

Duration: 00:02:36.76, start: 0.100511, bitrate: 0 kb/s
  Program 0
    Metadata:
      variant_bitrate : 380000
    Stream #0:0: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 400x228 [SAR 1:1 DAR 100:57], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Metadata:
      variant_bitrate : 380000
    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 48 kb/s
    Metadata:
      variant_bitrate : 380000

However, as you can see, Program 0 > Stream 0 just says that is has Closed captions - it does not list the type/spec of closed captioning technology being used.

How do I display the format of the Closed Captions?


Solution

WebVTT is what is know as a 'side car', or 'out of band' format. Meaning captions are in a separate file that you must download. You can see the URL for this file in the m3u8. Here the caption are part of the video stream itself. The only supported format in this case is EIA-608. ffmpeg support for 608 is pretty limited. The best tool I know of to for dealing with 608 is libcaption (full disclosure, I wrote it). I recently added a ts2srt example program. Fair warning its still sorta betaish.



Answered By - szatmary
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, September 19, 2022

[FIXED] How to set up a cron job for ffmpeg in centOS 6

 September 19, 2022     cron, ffmpeg, imagick, linux, php     No comments   

This summary is not available. Please click here to view the post.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, August 13, 2022

[FIXED] How to hide the output of yt-dl in CMD? python

 August 13, 2022     console, ffmpeg, output, python, ytdl     No comments   

Issue

I'm coding program that download mp3 audio from youtube videos but I have an issue that yt-dl show some output in console

my code:

with open('Links.txt') as f:
    content = f.readlines()
    for links in content:

        ydl_opts = {
            'format': 'bestaudio/best',
            'postprocessors': [{
                'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '192',
            }],
        }
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([links])

photo of output: enter image description here

and i need the option or some way to hide the output.


Solution

Try adding "quiet": true, to your ydl_opts

If that doesn't work maybe add

"external_downloader_args": ['-loglevel', 'panic']


Answered By - Ron Serruya
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, August 5, 2022

[FIXED] How to catch a FFMPEG exception with subprocess?

 August 05, 2022     exception, ffmpeg, python, subprocess     No comments   

Issue

I'm doing some work on subtitles and some videos have 1 subtitle track, others have 2 subtitle tracks. For those that have 2, I use the 2nd one (index = 1). I'm trying to automate it with python.

For files with with 2 subtitle tracks, I use:

-vf "subtitles='file.mkv':si=1

and for those with 1 subtitle track, I use:

-vf "subtitles='file.mkv':si=0

I'm using this code:

for mkv in all_mkvs:
    try:
      subprocess.call(f'ffmpeg -i ... -vf "subtitles='file.mkv':si=1 ...')
    except:
      subprocess.call(f'ffmpeg -i ... -vf "subtitles='file.mkv':si=0 ...')

But it doesn't seem to care about the exception and just ends the loop whenever it meets a file with 1 subtitle and gives me the error anyway.

Press [q] to stop, [?] for help
[Parsed_subtitles_0 @ 0000011af4912880] Shaper: FriBidi 1.0.10 (SIMPLE) HarfBuzz-ng 2.7.2 (COMPLEX)
[Parsed_subtitles_0 @ 0000011af4912880] Unable to locate subtitle stream in ./test/349.mkv
[AVFilterGraph @ 0000011af623d880] Error initializing filter 'subtitles' with args './test/349.mkv:si=1'
Error reinitializing filters!
Failed to inject frame into filter network: Operation not permitted
Error while processing the decoded data for stream #0:3
Conversion failed!

As you can see in the error message above, it says: "Error initializing filter .... si=1" because it should be si=0 in the case of that specific file, which is why I added the exception, but it doesn't seem to care about it.

enter image description here

So I'm trying to catch that error and say "ok, in that case, let's do si=0 instead".


Solution

subprocess.call returns the returncode, it never raises.

You probably want check_call, which will raise a subprocess.CalledProcessError on non-zero returncodes.

https://docs.python.org/3/library/subprocess.html

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None, **other_popen_kwargs)

Run the command described by args. Wait for command to complete, then return the returncode attribute.

subprocess.check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None, **other_popen_kwargs)

Run command with arguments. Wait for command to complete. If the return code was zero then return, otherwise raise CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute. If check_call() was unable to start the process it will propagate the exception that was raised.



Answered By - Cireo
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, July 27, 2022

[FIXED] How to cheaply "undo" a mosaic (i.e. split an image into halves or quadrants) with ffmpeg?

 July 27, 2022     crop, ffmpeg, image-segmentation     No comments   

Issue

FFMPEG makes it easy to take multiple inputs and stack them into a mosaic video. I am looking for a way to do the opposite, specifically I would like take a video stream that is composed of four streams stacked into quadrants and split it into four separate videos consisting of the coordinates

video1 = [0, 0.5*w, 0, 0.5*h]
video2 = [0.5*w, w, 0, 0.5*h]
video3 = [0, 0.5*w, 0.5*h, h]
video4 = [0.5*w, w, 0.5*h, h]

I know that I can do this with four separate ffmpeg calls using the crop filter but this seems to be unnecessarily expensive. Is there a way to do this in a single call?


Solution

crop filter

You can use four crop filters in one command:

ffmpeg -i input -filter_complex "[0]crop=iw/2:ih/2:0:0[tl];[0]crop=iw/2:ih/2:ow:0[tr];[0]crop=iw/2:ih/2:0:oh[bl];[0]crop=iw/2:ih/2:ow:oh[br]" -map "[tl]" topleft.mp4 -map "[tr]" topright.mp4 -map "[bl]" bottomleft.mp4 -map "[br]" bottomright.mp4

bitstream filter

A bitstream filter is different than a normal filter. A normal filter requires decoding and encoding. A bitstream filter operates on the encoded stream data, and performs bitstream level modifications without performing decoding.

The h264_metadata and hevc_metadata bitstream filters can edit the window cropping offsets in the SPS for H.264 and H.265/HEVC. What this means is that it can change these values without needing to re-encode the video. The file size will remain the same but the player will crop the video according to the crop values you set.

Example for H.264 320x240 input:

ffmpeg -i input.mp4 -bsf:v h264_metadata=crop_right=160:crop_bottom=120 -c copy topleft.mp4 -bsf:v h264_metadata=crop_left=160:crop_bottom=120 -c copy topright.mp4  -bsf:v h264_metadata=crop_right=160:crop_top=120 -c copy bottomleft.mp4 -bsf:v h264_metadata=crop_left=160:crop_top=120 -c copy bottomright.mp4

These fields are set in pixels. Note that some sizes may not be representable if the chroma is subsampled (it basically means you should only use even values for your typical video).

To script this you can use ffprobe to get the width and height.



Answered By - llogan
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to crop a mp3 from x to x+n using ffmpeg?

 July 27, 2022     crop, ffmpeg, mp3     No comments   

Issue

Following this question I decided to use ffmpeg to crop MP3s. On another question I found this way of doing it:

ffmpeg -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3

The problem is that I don't want to crop the first 30 seconds, I want to crop from x to x+n, like from 30s to 100s. How would I go and do this?

I'm reading the man for ffmpeg but this is not really straightforward, especially since I just discovered about ffmpeg and I'm not familiar with audio/video editing softwares, so any pointers would be appreciated.


Solution

Take a look at the -t and -ss arguments. They should do what you want.

-t duration

Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported.

-ss position'

Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported.

For example, ffmpeg -ss 30 -t 70 -i inputfile.mp3 -acodec copy outputfile.mp3 should do the trick for the range you mentioned (30s-100s).



Answered By - Michael Madsen
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 18, 2022

[FIXED] How to create an animated GIF using FFMPEG with an interval?

 July 18, 2022     animated-gif, ffmpeg, gif     No comments   

Issue

Hello fellow overflowers,

A brief overview of what I'm trying to accomplish; I have a site that will accept video uploads, uploads get converted into the mp4 format to be uniformed and playable on the web using one of the many available players. That part is all fine and dandy.

The problem now is I want to show the user a short scaled preview (animated gif) of the video before they click to play it. The code I'm working with now is

ffmpeg -i test.mp4 -vf scale=150:-1 -t 10 -r 1 test.gif

Which works for creating a scaled animated gif with a fixed width of 150px at a rate of 1 frame per second but its only an animation of the first 10 seconds of the video. I'm trying to do something that spreads out the frame gap to cover the whole video length but create an animated gift that's no more then 10 seconds long.

For example say I have a video that's 30 seconds I want the gif to be 10 seconds long but cover frames of the entire 30 seconds so it might start at frame 3 or 3 seconds in and create a frame in the gif, then at 6 seconds in the video create another frame, then 9 seconds in another, and so forth where the final outcome is

    example video 30 seconds long          example video 1 minute 45 second long 

video position - gif frame/per second      video position - gif frame/per second
      00:03:00   1                               00:10:50   1
      00:06:00   2                               00:21:00   2
      00:09:00   3                               00:31:50   3
      00:12:00   4                               00:42:00   4
      00:15:00   5                               00:52:50   5
      00:18:00   6                               01:03:00   6
      00:21:00   7                               01:13:50   7
      00:24:00   8                               01:24:00   8
      00:27:00   9                               01:34:50   9
      00:30:00   10                              01:45:00   10

  3 second interval between frames         10.5 second interval between frames

Where you end up with an animated gif that's 10 seconds long showing a preview of the entire video no matter the length of it. Which basically just boils down to video length / 10 (length of desired animated gif) = interval to use between frames but I don't know how I can use that data to accomplish my problem...

So does anyone have an idea or suggestion on how this can be accomplished with relative ease? I can probably do it by calculating the length through code and running a command to extract each individual frame from the video that's needed then generate a gif from the images but I'd like to be able to do it all with just one command. Thanks.


Solution

So I ended up just doing this by code having found this script (http://www.alberton.info/video_preview_as_animated_gif_with_ffmpeg_and_spl.html#.UxnU_IXYNyI) which made it easy where you can simply specify the position in the video by percentage on the frame to extract along with the interval between frames I can accomplish my problem above using the following.

// where ffmpeg is located, such as /usr/sbin/ffmpeg
$ffmpeg = '/usr/bin/ffmpeg';

// the input video file
$video = 'sample.avi';

// extract one frame at 10% of the length, one at 20% and so on
$frames = array('10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%');

// set the delay between frames in the output GIF in ms (60 = 1 min)
$joiner = new Thumbnail_Joiner(60);

// loop through the extracted frames and add them to the joiner object specifying 
// the max width/height to make the thumb based on the dimensions of the video
foreach (new Thumbnail_Extractor($video, $frames, '150x150', $ffmpeg) as $key => $frame) {
    $joiner->add($frame);
}

$joiner->save('sample.gif');

The above will go 10% into the length of the video, grab the frame for the first image of the animated GIF, create a 60ms/1sec delay, go 20% into the length of the video and repeat the process for each percentage specified which results in a video of any length having an animated GIF that's 10 seconds long containing 10 frames within the video at 10% intervals in length that show for 1 second each.



Answered By - Jeff Wilbert
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 17, 2022

[FIXED] How to fix .gif with corrupted alpha channel (stuck pixels) collected with Graphicsmagick?

 July 17, 2022     encode, ffmpeg, gif, graphics, graphicsmagick     No comments   

Issue

I want to convert an .avi with alpha channel into a .gif.
Firstly, I use

ffmpeg -i source.avi -vf scale=720:-1:flags=lanczos,fps=10 frames/ffout%03d.png

to convert .avi to sequence of .png's with aplha channel.
Then, I use

gm convert -loop 0 frames/ffout*.png output.gif

to collect a .gif.
But it seems that pixels of the output.gif just get stuck when something opaque is rendered on top of the transparent areas.

Here's an example:

img

As you can see the hearts and explosions do not get derendered.

P.S. FFMPEG output (collection on .png's) is fine.


Solution

I do not use Graphicsmagick but your GIF has image disposal mode 0 (no animation). You should use disposal mode 2 (clear with background) or 3 (restore previous image) both works for your GIF. The disposal is present in gfx extension of each frame in the Packed value.

So if you can try to configure encoder to use disposal = 2 or 3 or write script that direct stream copy your GIF and change the Packed value of gfx extension chunk frame by frame. Similar to this:

  • GIF Image getting distorted on interlacing

If you need help with the script then take a look at:

  • How to find where does Image Block start in GIF images?
  • Decode data bytes of GIF87a raster data stream

When I tried this (C++ script) on your GIF using disposal 2 I got this result:

disposal=2

The disposal is changed in C++ like this:

struct __gfxext
    {
    BYTE Introducer;        /* Extension Introducer (always 21h) */
    BYTE Label;             /* Graphic Control Label (always F9h) */
    BYTE BlockSize;         /* Size of remaining fields (always 04h) */
    BYTE Packed;            /* Method of graphics disposal to use */
    WORD DelayTime;         /* Hundredths of seconds to wait    */
    BYTE ColorIndex;        /* Transparent Color Index */
    BYTE Terminator;        /* Block Terminator (always 0) */
    __gfxext(){}; __gfxext(__gfxext& a){ *this=a; }; ~__gfxext(){}; __gfxext* operator = (const __gfxext *a) { *this=*a; return this; }; /*__gfxext* operator = (const __gfxext &a) { ...copy... return this; };*/
    };

__gfxext p;
p.Packed&=255-(7<<2);   // clear old disposal and leave the rest as is
p.Packed|=     2<<2;    // set new disposal=2 (the first 2 is disposal , the <<2 just shifts it to the correct position in Packed)

It is a good idea to leave other bits of Packed as are because no one knows what could be encoded in there in time ...



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

[FIXED] How to create a gif from an image sequence without dither with FFMPEG?

 July 17, 2022     ffmpeg, gif, image-processing, video     No comments   

Issue

I'm able to create a gif from the image sequence, but I'm struggling to remove the dither from it.

This is the command I'm using to create the gif:

ffmpeg -f image2 -framerate 24 -y -i image_%d.png -loop -1 "C:\Users\agetr\Documents\_tmp\__giuf.gif"

And I've tried to use the paletteuse=dither=none filter in different ways with no luck.

P.S.: I'm very new to the ffmpeg cli


Solution

You need to use -sws_dither none (after the -i $file argument, and before the output file). I've tried this on current git/master of FFmpeg and it works as expected, but on older builds (e.g. 4.4.1) this doesn't work. I don't know why exactly, so use a recent (5.0 or any version from 2022, if possible) version/build.



Answered By - Ronald S. Bultje
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, May 19, 2022

[FIXED] How to stop ffmpeg live stream to youtube over cron?

 May 19, 2022     ffmpeg, python, web-services     No comments   

Issue

I want to stream a video to youtube,

But don't know what to do to stop that live stream, like I want to stop in case wrong video gets streamed.

Like if i do a python subprocess or via cron not attached to the output, How can I stop the streaming and probably kill ffmpeg.


Solution

On Linux & macOS you can use:

kill $(pgrep ffmpeg)

Note that this will stop all ffmpeg instances. If you want to be more discriminate see ffmpeg How to end a specific process?, or look into creating a PID file for each process.



Answered By - llogan
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

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, May 16, 2022

[FIXED] How to get video duration, dimension and size in PHP?

 May 16, 2022     duration, ffmpeg, php, video     No comments   

Issue

I want to know how to get the duration, dimension and size of uploaded video file in PHP. The file can be in any video format.


Solution

getID3 supports video formats. See: http://getid3.sourceforge.net/

Edit: So, in code format, that'd be like:

include_once('pathto/getid3.php');
$getID3 = new getID3;
$file = $getID3->analyze($filename);
echo("Duration: ".$file['playtime_string'].
" / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
" / Filesize: ".$file['filesize']." bytes<br />");

Note: You must include the getID3 classes before this will work! See the above link.

Edit: If you have the ability to modify the PHP installation on your server, a PHP extension for this purpose is ffmpeg-php. See: http://ffmpeg-php.sourceforge.net/



Answered By - aendra
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, May 15, 2022

[FIXED] how to check if video is landscape or portrait using ffmpeg php?

 May 15, 2022     ffmpeg, php, ubuntu     No comments   

Issue

I have to check the video is landscape or portrait before rotate using ffmpge . please help me.


Solution

using ffmpeg we cant check the video is taken landscape mode or portrite mode in iphone.

we need to install mediainfo or exiftool

if we install exiftool use the below commands

exec('exiftool path/to/filename/ | grep Rotation');

from this we can get the rotation of the videos

if rotation is 90° the videos taken in portraite mode in iphone

if rotation is 0° the videos taken in landscape mode in iphone



Answered By - skythanigai
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, May 5, 2022

[FIXED] How to create a video from images with FFmpeg?

 May 05, 2022     ffmpeg, image, slideshow     No comments   

Issue

ffmpeg -r 1/5 -start_number 2 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

This line worked fine but I want to create a video file from images in another folder. Image names in my folder are:

img001.jpg
img002.jpg
img003.jpg
...

How could I input images files from a different folder? Example: C:\mypics

I tried this command but ffmpeg generated a video with the first image (img001.jpg) only.

ffmpeg -r 1/5 -start_number 0 -i C:\myimages\img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

Solution

See the Create a video slideshow from images – FFmpeg

If your video does not show the frames correctly If you encounter problems, such as the first image is skipped or only shows for one frame, then use the fps video filter instead of -r for the output framerate

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4

Alternatively the format video filter can be added to the filter chain to replace -pix_fmt yuv420p like "fps=25,format=yuv420p". The advantage of this method is that you can control which filter goes first

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf "fps=25,format=yuv420p" out.mp4

I tested below parameters, it worked for me

"e:\ffmpeg\ffmpeg.exe" -r 1/5 -start_number 0 -i "E:\images\01\padlock%3d.png" -c:v libx264 -vf "fps=25,format=yuv420p" e:\out.mp4

below parameters also worked but it always skips the first image

"e:\ffmpeg\ffmpeg.exe" -r 1/5 -start_number 0 -i "E:\images\01\padlock%3d.png" -c:v libx264 -r 30 -pix_fmt yuv420p e:\out.mp4

making a video from images placed in different folders

First, add image paths to imagepaths.txt like below.

# this is a comment details https://trac.ffmpeg.org/wiki/Concatenate

file 'E:\images\png\images__%3d.jpg'
file 'E:\images\jpg\images__%3d.jpg'

Sample usage as follows;

"h:\ffmpeg\ffmpeg.exe" -y -r 1/5 -f concat -safe 0 -i "E:\images\imagepaths.txt" -c:v libx264 -vf "fps=25,format=yuv420p" "e:\out.mp4"

-safe 0 parameter prevents Unsafe file name error

Related links

FFmpeg making a video from images placed in different folders

FFMPEG An Intermediate Guide/image sequence

Concatenate – FFmpeg



Answered By - khan
Answer Checked By - Pedro (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