Today I spent some time to compile ffmpeg libs on Windows. Most documentation out there is not updated to 2015, yet compiling ffmpeg on Windows is pretty easy. If you’re looking for a copy and paste solution, keep reading.
Pre-requisites
Visual Studio 2013 or 2015
MSYS2
YASM
Visual Studio
Latest ffmpeg versions compile both with Visual Studio 2013 and 2015. Previous versions don’t compile with VS2015 because they expect that VS compiler has no snprintf support while it was introduced in VS2015.
MSYS2
Download and run the installer at http://msys2.github.io. Follow the instructions and install it in C:\workspace\windows\msys64
Install required tools: pacman -S make gcc diffutils
Rename C:\workspace\windows\msys64\usr\bin\link.exe to C:\workspace\windows\msys64\usr\bin\link_orig.exe, in order to use MSVC link.exe (naming conflict)
YASM
Download Win64.exe and move it to C:\workspace\windows
Rename yasm-<version>-win64.exe to yasm.exe
Add C:\workspace\windows to PATH environment variable (setx PATH "%PATH%;C:\workspace\windows)
Ready to compile
Launch msys2 shell from Visual Studio Code shell
Run VS2013/VS2015 prompt
Run C:\workspace\windows\msys64\msys2_shell.cmd -msys -use-full-path: will open msys2 shell inheriting %PATH% from VS2013/VS2015 prompt
Ensure which cl exists and which link points to MSVC
Fmpeg is an extremely powerful and versatile command line tool for converting audio and video files. It is free and available for Windows, Mac and Linux machines. Whether you want to join two video files, extract the audio component from a video file, convert your video into an animated GIF, FFmpeg can do it all and even more.
Extract the audio from a video file with this simple FFmpeg command.
USEFUL FFMPEG COMMANDS
FFmpeg supports all popular audio and video formats. Or you can running the command ./ffmpeg -formats to get a list of every format that is supported by your FFmpeg installation. If you are just getting started, here are some commands that will give you good idea of the capabilities of this tool.
1. CUT VIDEO FILE INTO A SMALLER CLIP
You can use the time offset parameter (-ss) to specify the start time stamp in HH:MM:SS.ms format while the -t parameter is for specifying the actual duration of the clip in seconds.
If you want to split a large video into multiple smaller clips without re-encoding, ffmpeg can help. This command will split the source video into 2 parts – one ending at 50s from the start and the other beginning at 50s and ending at the end of the input video.
You can use the -vcodec parameter to specify the encoding format to be used for the output video. Encoding a video takes time but you can speed up the process by forcing a preset though it would degrade the quality of the output video.
If you have multiple audio or video files encoded with the same codecs, you can join them into a single file using FFmpeg. Create a input file with a list of all source files that you wish to concatenate and then run this command.
Use the -an parameter to disable the audio portion of a video stream.
ffmpeg -i video.mp4 -an mute-video.mp4
6. EXTRACT THE AUDIO FROM VIDEO
The -vn switch extracts the audio portion from a video and we are using the -ab switch to save the audio as a 256kbps MP3 audio file.
ffmpeg -i video.mp4 -vn -ab 256 audio.mp3
7. CONVERT A VIDEO INTO ANIMATED GIF
FFmpeg is an excellent tool for converting videos into animated GIFs and the quality isn’t bad either. Use the scale filter to specify the width of the GIF, the -t parameter specific the duration while -r specifies the frame rate (fps).
This command will extract the video frame at the 15s mark and saves it as a 800px wide JPEG image. You can also use the -s switch (like -s 400×300) to specify the exact dimensions of the image file though it will probably create a stretched image if the image size doesn’t follow the aspect ratio of the original video file.
You can use FFmpeg to automatically extract image frames from a video every ‘n’ seconds and the images are saved in a sequence. This command saves image frame after every 4 seconds.
ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png
10. MERGE AN AUDIO AND VIDEO FILE
You can also specify the -shortest switch to finish the encoding when the shortest clip ends.
This command creates a video slideshow using a series of images that are named as img001.png, img002.png, etc. Each image will have a duration of 5 seconds (-r 1/5).
You can add a cover image to an audio file and the length of the output video will be the same as that of the input audio stream. This may come handy for uploading MP3s to YouTube.
You can change the speed of your video using the setpts (set presentation time stamp) filter of FFmpeg. This command will make the video 8x (1/8) faster or use setpts=4*PTS to make the video 4x slower.
For changing the speed of audio, use the atempo audio filter. This command will double the speed of audio. You can use any value between 0.5 and 2.0 for audio.
Stack Exchange has a good overview to get you started with FFmpeg. You should also check out the official documentation at ffmpeg.org or the wiki at trac.ffmpeg.org to know about all the possible things you can do with FFmpeg.
FFmpeg is an amazing collection of open-source tools that can record and stream video and audio. However, it can also transcode video and audio (convert the files to different formats), and that is what has me so excited. There’s also a great PHP package called ffmpeg-phpthat allows for easy use of FFmpeg from inside PHP scripts. Today, I’m going to see if I can’t help you get both of these set up on your system.
Admittedly, it’s been a while since I’ve tried to install FFmpeg, about two years. I recently thought up some ideas on how I’d like to use FFmpeg, so I thought it was time to give it a try yet again. Today, I’m proud to say that installing FFmpeg is so much easier to install compared to the past, that I dare say it’s simple.
Here is my experience with installing FFmpeg on my server and how to fix the pitfalls that I encountered.
Preface
Note that I did all the following steps on a CentOS server. The specific version is CentOS x64 6.7.
If you successfully get FFmpeg running on another distro, please comment your changes here and I’ll update the post (and make sure you get credit of course).
Also note that I experienced some bumps in the road while installing everything. While many of you may not experience these issues, I found it important to document these problems and how I fixed them in case you encounter them.
Preparing
The first thing that you need to do is set up the DAG repository. This repository is an actively-maintained repository that provides a staggering number of packages with current or near current builds. Adding this repository is a great way to run the latest offerings of many packages.
Adding the DAG repository is simple. I’m using yum, so I did the following to add the repository:
Create and open a new file called /etc/yum.repos.d/dag.repo. I ran “vi /etc/yum.repos.d/dag.repo“.
In order to successfully use the DAG repository with tools such as yum, you need to add DAG’s GPG key. Failure to do so will result in an error like the following:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Public key for faac.x86_64.1.26-1.el5.rf.rpm is not installed
In order to add the GPG key for DAG, run the following:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
The DAG: Frequently Asked Questions page has additional instructions on how to get the repository loaded and working on your distro.
Now that DAG is setup, it’s a good idea to update all your packages.
yum update
Depending on the packages you currently have installed, this could potentially upgrade, install, or replace numerous packages that may or may not be very important to you. Make sure you carefully look through that list and do any necessary preparations before telling yum that it can go ahead.
For example, yum told me that it was going to replace my current MySQL interface library for Perl with a new one. I added to my check list a note to verify that my Perl code functioned correctly after the install.
I ran into another hitch when I told yum to go ahead with the update. It informed me that my current version of Subversion conflicted with the new version it wanted to install. When this happens, you need to remove the old package before proceeding. This time, I made backups of all of my repositories and my /etc/sysconfig/svnserve file before proceeding just in case. I then removed Subversion “yum remove subversion“, ran the update process “yum update“, and installed Subversion again “yum install subversion“.
Installing – FFmpeg
Now you are ready to install FFmpeg with yum. I wanted to install all the available FFmpeg packages, so I first asked yum what was available.
yum search ffmpeg
Searching through the results, I found that three packages need to be installed: ffmpeg, ffmpeg-devel, and ffmpeg-libpostproc.
Note: If you install ffmpeg-libpostproc, the entire FFmpeg software library changes from the LGPL license to the GPL license.
After a couple of minutes, the packages and the packages that they depend on were installed.
I simply ran “ffmpeg” from the command line, and I took the lack of threatening error or warning messages as a good sign that things were working.
Preparing for ffmpeg-php
I often work with programs through command line calls in code, but I wanted something more robust this time, so I looked around and foundffmpeg-php. Based on the API, it looks to be a great tool to interface PHP and FFmpeg.
There are four things that are required to successfully install and run ffmpeg-php; they are:
ffmpeg-0.4.9_pre1 or higher
php-4.3.0 or higher
gd-2.0 or higher
php-devel
PHP and FFmpeg should be good to go since at the time of this writing, DAG has PHP version 5.1.6 and FFmpeg version 0.4.9. GD and php-devel can be easily installed by running the following yum command:
yum install php-gd php-devel
In case you are wondering what php-devel is for, it installs the phpize program which is used to install ffmpeg-php.
Installing ffmpeg-php
Now we are ready to install ffmpeg-php. This can be done in six easy steps:
Extract the archive: tar -xjf ffmpeg-php-X.x.x.tbz2
cd ffmpeg-php-X.x.x/
phpize
./configure && make
sudo make install
Finishing Thoughts
This may seem like a lot of work when I earlier described this process as “simple,” but trust me that this is a thousand times easier than when I first tried installing FFmpeg. I think I spent three hours working on installing FFmpeg just to find out that it didn’t work the first time I tried.
Time and time again, package management has proven to be an extremely powerful tool. While I know the value of manually configuring and compiling code, the ease of simply using a package manager can reduce the time needed to install and manage software from hours or days to minutes.
I’m glad to see that FFmpeg has benefited from the use of these package managers and great repositories like the DAG RPM Repository.
MP4Box is a MP4 multiplexer. So let see How TO Install MP4Box on CentOS. MP4Box can import MPEG-4 video, DivX, XviD, 3ivx, h264 etc, audio streams and subtitles into the .mp4 container. The end result is a compliant MP4 stream. It can also extract streams from a .mp4. MP4Box is a command line tool, but can be used with graphical user interfaces such as YAMB or my MP4box GUI.
1) Install some dependencies packages with yum command
cd /usr/local/src/
wget http://mirror.ffmpeginstaller.com/source/gpac/gpac-0.5.0.tar.gz
wget http://mirror.ffmpeginstaller.com/source/gpac/gpac_extra_libs-0.5.0.zip
3) Extract gpac tar files
tar -zxvf gpac-0.5.0.tar.gz
unzip gpac_extra_libs-0.5.0.zip
4) Install gpac
cd extra_libs
cp -r * /usr/local/src/gpac/extra_lib
cd ..
cd gpac
chmod 755 configure
./configure
make lib
make apps
make install lib
make install
cp bin/gcc/libgpac.so /usr/lib
install -m644 bin/gcc/libgpac.so /usr/local/lib/libgpac.so
chmod +x /usr/local/lib/libgpac.so
ldconfig
And it’s done.
[root@server ~]# which MP4Box
/usr/local/bin/MP4Box
[root@server ~]# /usr/local/bin/MP4Box -version
MP4Box - GPAC version 0.5.0-rev4065
GPAC Copyright: (c) Jean Le Feuvre 2000-2005
(c) ENST 2005-200X
GPAC Configuration:
Features: GPAC_HAS_SSL GPAC_HAS_JPEG GPAC_HAS_PNG
That command will install the EPEL repo inside your /etc/yum.repos.d directory.
then
Manually, install FFmpeg-Php
cd /usr/local/src
wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
tar jxvf ffmpeg-php-0.6.0.tbz2
cd ffmpeg-php-0.6.0
phpize
./configure
make
If you get (error make: *** [ffmpeg_frame.lo] Error 1) do this commands.
sed -i 's/PIX_FMT_RGBA32/PIX_FMT_RGB32/g' ffmpeg_frame.c
OR
vi ffmpeg_frame.c
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32
:wq
Then rerun "./configure && make" and if all went fine make install make install If no error skil to step 5. Step 5. Now adding to php.ini echo 'extension=ffmpeg.so' >> /usr/local/lib/php.ini Step 6. Now test php with ffmpeg php -r 'phpinfo();' | grep ffmpeg
-i | grep ffmpeg -i
/etc/php.d/ffmpeg.ini,
ffmpeg
ffmpeg-php version => 0.7.0
ffmpeg-php built on => Jan 1 2013 09:50:55
ffmpeg-php gd support => enabled
ffmpeg libavcodec version => Lavc53.61.100
ffmpeg libavcodec license => GPL version 3 or later
ffmpeg libavformat version => Lavf53.32.100
ffmpeg libavformat license => GPL version 3 or later
ffmpeg swscaler version => SwS2.1.100
ffmpeg swscaler license => GPL version 3 or later
When you run command ./configure if you get error: configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the –enable-shared option. Check some library with command:
rpm -ql ffmpeg-devel
In On CentOS 6/7 with nux-dextop installed ffmpeg-devel
The following assumed you have root access to your cpanel server. ImageMagick is one of the most requested add-ons that allows for image manupulation. Always try to use GD first, if it is available, as it can be compiled from easyapache instead directly.
CHECK IF ITS INSTALLED FIRST:
from root ssh /scripts/checkimagemagick
INSTALLATION /scripts/installimagemagick
Installation will take a couple minutes as it will install other packages needed by ImageMagick. After the installation, check that it is installed again and it should state the version. /usr/bin/convert --version
It will give you something like: Version: ImageMagick 6.4.8, etc
Imagick
Go to WHM -> Software -> Module Installers -> PHP Pecl (manage). On the box below “Install a PHP Pecl” enter “imagick” and click “Install Now” button – that’s all. Restart Apache.
Uninstall:
If you decide to uninstall it’s as easy as the installation process:
ImageMagick: /scripts/cleanimagemagick
Imagick: WHM -> Software -> Module Installers -> PHP Pecl (manage). Click on Uninstall button for Imagick
CHECKING WHERE ImageMagick is located:
from ssh use
whereis convert
should give you the directory
ffmpeginstaller is a free software completely written in bash shell script. The purpose of this script is to build a video streaming platform in your Gnu/Linux server. So you can start video streaming websites and avoid the cost of installations. This script not only install ffmpeg but also all its friends packages. You can chose this script for building platform for most of the youtube clone software like clip-shre, sharemixer,shareigniter,etc,.
What packages ffmpeginstaller install in your server?
Please see the complete list of packages below.
FFmpeg : FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video
MPlayer And Mencoder : MPlayer is a movie player.It plays most MPEG/VOB, AVI, Ogg/OGM, VIVO, ASF/WMA/WMV, QT/MOV/MP4, RealMedia, Matroska, NUT, NuppelVideo, FLI, YUV4MPEG, FILM, RoQ, PVA files, supported by many native, XAnim, and Win32 DLL codecs.
A52decoder : Are you a hosting company and you like to sell PCI DSS compliance servers to your clients with support ? If so this is your plan
Amrnb and Amrwb : The Adaptive Multi-Rate (AMR) audio codec is a patented audio data compression scheme optimized for speech coding
Latest Codecs : Install latest codecs libs
Faad2 : FAAD2 is an open source MPEG-4 and MPEG-2 AAC decoder
FAAC : FAAC is an MPEG-4 and MPEG-2 AAC encoder.
Flvtool2 : FLVTool2 is a manipulation tool for Macromedia Flash Video files (FLV )
Lame MP3 Encoder : LAME is a high quality MPEG Audio Layer III (MP3) encoder
Liba52 : liba52 is a free library for decoding ATSC A/52 streams
Libogg : Ogg Lib collections
OpencoreAMR : Library of OpenCORE Framework implementation of Adaptive Multi Rate Narrowband and Wideband speech codec
Theora : Theora is a free and open video compression format
Vorbis tools : Vorbis is a completely open, patent-free, professional audio encoding and streaming technology with all the benefits of Open Source
Libwmf : libwmf is a library for reading vector images in Microsøft’s native Windøws Metafile Format (WMF)
MP4Box : MP4Box is a MP4 multiplexer
X264 : x264 is a free software library and application for encoding video streams into the H.264/MPEG-4 AVC format
Xvid : Open-source compression codec based on MPEG-4 ISO format
How to Install FFMPEG Auto Installer on CentOS
Seeing as FFMPEG Auto Installer do not give clear instructions on how to install their packages I have produced a easy guide which hopefully should be of some use to server admins and novices alike.
Firstly SSH into your server.
Now run the following commands:
mkdir ~/ffmpeg-packages
cd ~/ffmpeg-packages
wget http://mirror.ffmpeginstaller.com/old/scripts/ffmpeg7/ffmpeginstaller.8.0.tar.gz
tar -xvzf ffmpeginstaller.8.0.tar.gz
cd ffmpeginstaller.8.0
Im using version ffmpeginstaller.8.0 for this installation, make sure you edit your command to coincide with the current package.