How cut part of movie in php - php

User can upload any movie (.mov .mpg .avi .flv and many more) And now i would like cut this file from 15 to 25 seconds (part will be 10 seconds only) and convert this small part to FLV as preview of movie.
Now i have some questions:
Should i convert all uploaded movie to flv ? or cut part only and all movie file make as zip ?
How can i cut this file in php 7 ? is it possible ? i found
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
but this is only for mp4 ?

For HTML5 you can output various formats for compatibility. For example, H.264 + AAC in MP4, H.265/HEVC + AAC in MP4, and VP9 + Opus in Webm:
ffmpeg -ss 30 -t 10 -i input \
-c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p -c:a aac -movflags +faststart h264.mp4 \
-c:v libx265 -preset medium -crf 28 -pix_fmt yuv420p -c:a aac -movflags +faststart h265.mp4 \
-c:v libvpx-vp9 -crf 30 -b:v 2000k -c:a libopus vp9.webm
Adjust -preset, -crf, anf -b:v to your needs. Implementing this into shell_exec should be trivial for those familiar with PHP.
See the following FFmpeg Wiki articles for more info: PHP, H.264, H.265, VP9.

Related

FFMPEG command in PHP shell_exec is too slow for a 300Mo mp4

I have a web site where user upload videos.
When a video is uploaded I shell_exec 3 ffmpeg commands:
Generate preview:
$cmd = "ffmpeg -ss 1 -i ".$filePath." -vf \"scale='if(gt(dar,360/202),202*dar,360)':'if(gt(dar,360/202),202,360/dar)',setsar=1,crop=360:202\" -frames:v 1 ".$thumbnail;
Compress the video:
$cmd = "ffmpeg -i ".$filePath." -c:v libx264 -crf 23 -preset veryfast -c:a aac -ab 128k -movflags faststart ".$wmoutput;
Add watermark:
$cmd = 'ffmpeg -i '.$wmoutput.' -i new/watermark.png -filter_complex "overlay=10:10" '.$finaloutput;
The problem is that these 3 commands take a lot of time to finish and sometimes it goes over Maximum execution time specialy for video files that are bigger than 300Mo. I can just expand the Maximum execution time but I don't know how many seconds I have to set.
Is there a way to make the scripts above execute faster without having to change the Maximum execution time?
Combine Compress the video and add watermark into one command:
ffmpeg -i input.mp4 -i new/watermark.png -filter_complex "overlay=10:10" -c:v libx264 -crf 23 -preset veryfast -c:a aac -ab 128k -movflags faststart output.mp4
Should be significantly faster and you avoid yet another instance of generation loss.

Can't get video output on avi to mp4 conversion using ffmpeg

I am so frustrated with this problem. Any time I convert avi files to mp4 files, I can get the audio, but NO video. Here are the various switches I've tried. I don't know how to resolve the situation. I've never had this problem with mpg, mov or any other format, but AVI is frustrating.
Doing this in php but I've also done it from the command line.
(NOTE: I've also tried it with NO extra parameters letting ffmpeg do the full conversion).
(NOTE: It does play the original avi file in any desired Windows or Linux player as is so I know there are is no damage to the original file, but I want to convert to mp4 for the web).
(Final Note*: when using aac it warns of too many bits ...clamping to max if that helps)
Here's the code:
$InputFile - some avi file. I have a ton of them and they all do the same thing.
$OutputFile - same name but with an mp4 extension
$Parameters are various switches I've used.
shell_exec ("ffmpeg -i " . $InputFile . ' ' . $Parameters . ' ' . $OutputFile);
$Parameters = " -profile:v baseline -pix_fmt yuv420p ";
$Parameters = " -acodec copy -vcodec copy ";
$Parameters = " -c:v libx264 -c:a libfaac -movflags +faststart ";
$Parameters = " -c:v libx264 -c:a aac -strict experimental -movflags +faststart ";
$Parameters = " -c:v libx264 -c:a -acodec aac libfdk_aac -movflags +faststart ";
$Parameters = " -c:v libx264 -preset slow -crf 18 -c:a libmp3lame -b:a 128k -f mp4 ";
$Parameters = " -c:v libx264 -crf 19 -preset slow -c:a aac -strict experimental -b:a 192k -ac 2 ";
I really don't get why I only get an audio output. I can see it in VLC player, but, of course that's not my goal. I want it to mp4 to see it on a webpage.
I welcome any help!

Ideal bitrates for different video resolutions

I am building a Video-on-demand service for a closed community. I using FFMPEG for video processing and dash.js for adaptive bitrate player with custom resolution selector. Can somebody please suggest what ideal bitrates should I use while video/audio transcoding?
I am talking about -b:v and -ab option
ffmpeg -i vid.mp4 -c:v libvpx-vp9 -keyint_min 150 \
-g 150 -tile-columns 4 -frame-parallel 1 -f webm -dash 1 \
-an -vf scale=144:-1 -b:v 120k -dash 1 video_1.webm \
-an -vf scale=240:-1 -b:v 250k -dash 1 video_2.webm \
-an -vf scale=360:-1 -b:v 500k -dash 1 video_3.webm \
-an -vf scale=480:-1 -b:v 750k -dash 1 video_4.webm \
-an -vf scale=720:-1 -b:v 1500k -dash 1 video_5.webm
And
ffmpeg -i vid.mp4 -vn -acodec libvorbis -ab 96k -dash 1 audio_96k.webm
Any suggestions/hacks or examples to tackle real-world network situations are appreciated.
There is no ideal. Every video is different, and every viewer is different. What is ideal for one viewer is not ideal for another. Read the Netflix blog on pert title encoding and vmaf. Also look at Akamai state of the internet reports to determine what average global internet connection speeds are.

Ffmpeg - converting webm movie to flv movie not working

I need to convert .webm files to .flv.
I have used
'exec("ffmpeg -i 1.webm -acodec libfaac -ab 96k -ac 2 -vcodec libx264 -vpre hq -crf 22 -threads 0 1.flv");'.
When i use the above code, the file is converting to 1.flv with 0 bytes. No data is in 1.flv file.

Convert video to FLV using FFMPEG

I come across this code in one php script that i bought last time to convert video. The script is running on Ubuntu 12.04
-i $file_source -b 9600k -aspect 16:9 -acodec aac -strict experimental -ab 128k -ar 22050 $file_dest"
That is the full meaning of elements/attributes and what could be the alternative?
Thanks for your help
You can use below command to convert videos using ffmpeg
Required Codec:
libmp3lame - acodec
libfaac - acodec
libvorbis - acodec
libx264 - vcodec
libtheora - vcodec
libvpx - vcodec
FFMPEG build Version - ffmpeg version N-54207-ge59fb3f
Commands As Below -
Convert to flv -
$file_source = "/tmp/test.mp4";
$file_dest = "/tmp/test.flv";
ffmpeg -i $file_source -pass 1 -vcodec libx264 -preset slower -b 512k -bt 512k -threads 0 -s 640x360 -aspect 16:9 -acodec libmp3lame -ar 44100 -ab 32 -f flv -y $file_dest
Convert to mp4 to support HTML5 -
$file_source = "/tmp/test.flv";
$file_dest = "/tmp/test.mp4";
ffmpeg -y -i $file_source -vcodec libx264 -q:v 1 -preset slower -profile:v baseline -level 30 -crf 30 -vf scale="480:360" -aspect 16:9 -s 640x360 -acodec libfaac -ab 128k -ac 2 -coder ac -me_range 16 -subq 5 -sc_threshold 40 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 -f mp4 $file_dest
Convert to webm to support HTML5 -
$file_source = "/tmp/test.mp4";
$file_dest = "/tmp/test.webm";
ffmpeg -y -i $file_source -vcodec libvpx -b:v 480k -bt 480k -preset slower -level 30 -crf 30 -vf scale="480:360" -aspect 16:9 -s 640x360 -acodec libvorbis -ab 128k -ac 2 -coder ac -me_range 16 -subq 5 -sc_threshold 40 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 -f webm $file_dest
Convert to ogv to support HTML5-
$file_source = "/tmp/test.mp4";
$file_dest = "/tmp/test.ogv";
ffmpeg -y -i $file_source -vcodec libtheora -b:v 480k -bt 480k -preset slower -level 30 -crf 30 -vf scale="480:360" -aspect 16:9 -s 640x360 -acodec libvorbis -ab 128k -ac 2 -coder ac -me_range 16 -subq 5 -sc_threshold 40 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 -f ogg $file_dest;
For more information about ogg,mp4,web check link html5-videos-things-you-need-to-know and easyhtml5video
This is a command line instruction for FFMPEG
You can read the documentation for alternative options at: FFMPEG Docs
Anyways just to explain..
-i $file_source -b 9600k -aspect 16:9 -acodec aac -strict experimental -ab 128k -ar 22050 $file_dest
Where..
-i $file_source is your input file (any media type)
-b 9600k is video bitrate
-aspect 16:9 is widescreen
-acodec aac -strict experimental is using AAC codec (is experimental codec so use strict to force usage anyway)
-ab 128k is audio bitrate 128kb/s
-ar 22050 is audio samplerate of 22.05 khz
$file_dest the output filename (with extension so FFMPEG knows your preferred output format

Categories