Welcome on DoYourself.org

Have an tutorial and wanna public it ?

On this website you can add any type of tutorials , but first you must have an account . To create one just complete right inputs with your dates.

Members Login

Lost your password?

Not member yet? Sign-up!

Security Code

YouTube, FFMPEG, and MP3 Conversion

Posted by CarcaBot on Sunday, 08.23.09 @ 16:50pm  •  Filled under Ffmpeg  • No comments  •   •  Views (197)  

Yesterday I published a quick post about a basic MPEG -> FLV video conversion method using FFMPEG. Today I want to share another great usage of FFMPEG: stripping a video’s audio and creating an MP3. As an added bonus, I’ll be ripping the audio from a great YouTube video using youtube-dl, a python script with loads of options for downloading YouTube videos.

The youtube-dl Shell Script

01.#command
02.davidwalsh83$ youtube-dl.py http://www.youtube.com/watch?v=tlWpnLdPwvk
03. 
04.#output
05.[youtube] Setting language
06.[youtube] tlWpnLdPwvk: Downloading video webpage
07.[youtube] tlWpnLdPwvk: Extracting video information
08.[youtube] tlWpnLdPwvk: URL: http://www.youtube.com/get_video?video_id=tlWpnLdPwvk&;t=vjVQa1PpcFMZ4TkTSYXamGxmLZq-ot2l8Jx-HiNAf0I=&el=detailpage&ps=
09.[download] Destination: tlWpnLdPwvk.flv
10.[download] 100.0% of 18.78M at   53.98k/s ETA 00:00

The initial install of youtube-dl was tough but only because I’m not well-versed with the permissions side of Unix. I eventually figured it out but if you have trouble installing youtube-dl or simply want to use its advanced options, check out youtube-dl’s documentation. youtube-dl also provides an option to read a text file with a list of videos and will do a batch download. Note: youtube-dl allows you to set an output file name but it didn’t appear to be working. If you’d like a more simple method, Mark Sanborn wrote a great post on ripping YouTube videos using wget.

The FFMPEG Shell Script

1.davidwalsh83$ ffmpeg -i tlWpnLdPwvk.flv RodStewartMaggieMay.mp3

As I did with youtube-dl, I chose the most basic usage of FFMPEG. FFMPEG’s documentation provides you a list of all of the possible conversion options if you need them.

Use the video player above to listen to the result. The video I chose is a live version of Maggie May by Rod Stewart recorded at Royal Albert Hall in the Knightsbridge area of the City of Westminster, London, England. The video is from Rod’s One Night Only DVD which I HIGHLY recommend. This is the best version of Maggie May that exists (my opinion but, as you know, when is my opinion not correct?) Enjoy!

Converting video (AVI, MOV, MPG, MP4) to FLV using FFmpeg

Posted by CarcaBot on Sunday, 08.23.09 @ 16:44pm  •  Filled under Ffmpeg  • No comments  •   •  Views (147)  

Firstly you need to download FFmpeg from the FFmpeg website

To convert your file use the following command.

ffmpeg -i “C:\videos\videoname.mov” -ar 44100 -ab 96 -f flv “C:\videos\videoname.flv”

  • ffmpeg – runs the program
  • -i “filename.ext” – input file
  • -ar 44100 – audio frequency
  • -ab 96 – audio bitrate
  • -f flv – force format followed by format
  • “newfilename.ext” – output file

I used these settings to convert some 500MB+ Apple Quicktime (MOV) files down to ~20MB FLV which were perfect for uploading to YouTube.

Using FFMpeg to Convert mpg or mov to flv

Posted by CarcaBot on Sunday, 08.23.09 @ 16:00pm  •  Filled under Ffmpeg  • No comments  •   •  Views (92)  

Hi all.

If you need to use a command-line program to convert between different movie or media formats, it’s likely you’ll end up using ffmpeg. ffmpeg is the de facto standard for converting file formats in *nix and FreeBSD environments.

Using the program from the command-line is like using any other program. There are a large amount of switches and options you can use to change the functionality of ffmpeg, including video resolution, video quality, audio compression and quality, framerate, and more!

There are many ways to download ffmpeg. Many vary on your distribution of Linux or other Operating System. In many cases, ffmpeg may already be installed and ready for you to use. For Mandriva users, ffmpeg is available using urpmi or the “Add/Remove Software” program in the control panel.

In case you simply need to convert a video from mov or mpeg format to Flash Video (flv) here is the command that I use:

# ffmpeg -i <filename.mpg> -deinterlace -ar 44100 -r 25 -qmin 3 -qmax 6 <filename.flv>

This will convert your movie to Flash video (.flv extension) at the same resolution it went in as (for example 480×392 pixels in width and height), deinterlace the video, set the audio frequency to 44100 (high quality), the video framerate to be 25 frames per second, and set the video quality between 3 and 6, which will give you very good yet quickly servable results. If you’re shipping this video on CD or DVD you can set the qmin and qmax values lower (lower = higher quality) but for streaming video this is very, very good and very close to the original without being massive in size.

In fact, the one thing that requires some explanation are the qmin and qmax values. It’s a slightly complicated subject but can be easily explained by thinking of qmin and qmax as how much quality you want to take away from your video, between those two numbers. The minimum qmin and qmax is 1 and the maximum is 31.

If the video size is too large after using this command example and you would like a smaller file, try increasing qmax first until you reach it’s maximum. It’s likely that you will find a happy number in there without having to adjust the qmin value.

If you need to convert several videos, say from a directory, you can use this script available here.

Below is the code in the script file, for reference.

<?php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && strpos($file, "mpg") !== false) {
$new_filename = str_replace(" ", "_", strtolower(str_replace("mpg", "flv", $file)));
$file = str_replace(" ", "\ ", $file);
exec("ffmpeg -i $file -deinterlace -ar 44100 -r 25 -qmin 3 -qmax 6 $new_filename");
}
}
closedir($handle);
}
?>

It’s fairly self-explanatory, but the above script simply fetches a list of all of the files in the current directory and executes the ffmpeg program for each file in that list that has the extension “.mpg”.

It should be noted that converting between different video file formats may require a license to do so by the patent holders of that file format. Be sure that you have dotted your “i’s” and crossed your “t’s”.

Good luck!

Installing FFMPEG on Linux

Posted by Hitesh Agrawal on Friday, 08.21.09 @ 20:08pm  •  Filled under Ffmpeg  • No comments  •   •  Views (30)  

FFMPEG is an open source application that allows you to convert video and audio files easily between a variety of different formats. It supports most industry-standard codec and can convert from one file format to another quickly and easily. This article will guide you to installing FFMPEG and other codec on Linux.

FFMPEG Installation Requirements:

  • FFMPEG
  • LAME Mp3 Audio Codec (Requred for mpg, flv, avi, wmv etc files)
  • AMR Audio Codec (Required for 3gp video files)
  • XVID Audio Codec
  • FFMPEG-PHP

Note on installing FFMPEG:

  • All the Audio Codec getting used in FFMPEG are not part of FFMPEG Source base

FFMPEG Download URL:
On the download page of FFMPEG they have geven the download link from SVN and checkout-snapshot but i would suggest to use SVN source code base.
FFMPEG Download Page FFMPEG
The url for the SVN source code for FFMPEG is: svn://svn.mplayerhq.hu/ffmpeg/trunk

To download from SVN you will have to install subversion located at subversion.tigris.org, or you can use “TortoiseSVN” located at tortoisesvn.tigris.org.

LAME Mp3 Codec download URL: Lame Mp3 Codec

AMR Audio Download URL: AMR Audio Codec
To install the AMR codec you will require both AMR-WB and AMR-NB files.

XVID Audio Download URL: XVID Audio Codec

FFMPEG-PHP Download URL: FFMPEG-PHP

Installation Steps:
It is a good practice to install all the external audio codec libraries first and then install the FFMPEG.

Installing LAME MP3 Encoder

  • Untar the lame file by using tar zxvf lametarfile
  • Assign 777 permission rights to the lame folder by typing chmod 777 lamefolder -R
  • Traverse to the root of lame folder and type
    ./configure
    make
    make install

Installing AMR Codec
For installing the AMR codec there are two separate files that needs to be installed are AMR-WB and AMR-NB.

  • Untar the AMR file by using tar zxvf tarfile
  • Assign 777 permission rights to the amr folder by typing chmod 777 amrfolder -R
  • Traverse to the root of amr folder and type
    ./configure
    make
    make install

Note on Installing AMR:
You might get errors installing AMR codec on Autoconf utility of linux. To resolve this problem will have to install the latest version of Autoconf utility from Download AutoConf

Installing Xvid Codec

  • Untar the xvid file bu using tar zxvf tarfilename
  • Assign 777 permission rights to the lame folder by typing chmod 777 xvidfolder -R
  • Traverse to the root of xvid folder
  • Goto Build/generic folder and type
    ./configure
    make
    make install

Installing GCC

  • This is required only if the SVN for FFMPEG is not compatible with the existing version of GCC(3x) requires a new version for the same
  • After the installation of GCC need to convert all the files of SVN to Unix compatible by using “dos2unix ffmpegfolder/* -R”.

Installing FFMPEG

  • Download the ffmpeg from SVN
  • Assign 777 permission rights to the ffmpeg folder by typing chmod 777 ffmepgfolder -R
  • Traverse to the root of ffmpeg folder and type
    ./configure –enable-libmp3lame –enable-libogg –enable-libvorbis –enable-libamr-nb –enable-libamr-wb –enable-libxvid –enable-gpl –enable-shared
    make
    make install
Installing FFMPEG-PHP
  • Download the ffmpeg-php from Sourceforge
  • Unpack the archive by using following command “tar -xjf ffmpeg-php.X.XX.tar.gz”
  • Iterate inside the ffmpeg-php directory
  • Run phpize (included with your php install) to build configuration files
    ./configure
    make
    make install

NOTE FOR FFMPEG-PHP:
If you are planning to install FFMPEG-PHP then will have to add –enable-shared parameter while configuring FFMPEG

You might get installation error while making the file related to html or texti files in ffmpeg\doc folder. The solution for this that worked for me is to just create a empty file by using touch command in the respective folders.

Note:
The following configure parameter will work with FFMPEG 0.49. But now the latest version does not have –enable-libogg parameter so if you are planning to installing the latest version then the configure parameter would be /configure –enable-libmp3lame –enable-libvorbis –enable-libamr-nb –enable-libamr-wb –enable-libxvid –enable-gpl –enable-shared.

Note on Reinstalling FFMPEG:
If you are planning to reinstall the FFMPEG software the will have to perform following steps:

  • ./configure –enable-libmp3lame –enable-libogg –enable-libvorbis –enable-libamr-nb –enable-libamr-wb –enable-libxvid –enable-gpl –enable-shared

  • make clean
  • make
  • make install

Lot of people are facing error on loading shared libraries libavdevice.so.52, solution to the same is:
export LD_LIBRARY_PATH=/usr/local/lib/

Converting Audio/Videos using FFMPEG

Posted by Hitesh Agrawal on Friday, 08.21.09 @ 20:08pm  •  Filled under Ffmpeg  • No comments  •   •  Views (48)  

I was simply ignoring writing this articles but after writing articles on Installing FFMPEG on Linux i couldn’t resist on writing this article. Anyways this article will guide you on how you can convert audio video formats using FFMPEG.

This articles in divided in various sections

  • Parameter Used
  • Command Line Syntax
  • Conversion Examples

Parameter Used:
Common Parameters

-i ‘filename’ Filename will be the Path of Source Filename
-y Overwrite the existing output file without prompting
-an disable audio

Video Related Parameters

-aspect ‘aspect ratio’ Set Aspect Ratio for the video (4:3, 16:9 or 1.3333, 1.7777)
-r ‘rate’ set frame rate in Hz for the video
-s ’size’ set video resolution size (Width x Height)
-sameq use same video quality as source

Audio Related Parameters

-ar ‘rate’ set audio sampling rate (in Hz)
-acodec ‘codec’ force audio codec E.g. mp3
-vol ‘volume’ change audio volume (256=normal)
-ab ‘rate’ set audio bit rate (in bits/s)

Advanced Parameters

-map_meta_data output file:input file Copy the Metadata from Input File to Converted output file

Command Line Syntax
ffmpeg –i ‘input filename’ ‘output filename’

  • Syntax Example:
    [root@linux /]# ffmpeg -i demo.mpg demo.flv
    Here FFMPEG will convert demo.mpg file to demo.flv

Conversion Examples:

Video Examples:

  • Converting MOV to FLV using FFMPEG
    ffmpeg -i movie1.mov movie1.flv
    This will convert movie1.mov file to movie1.flv
  • Converting Mpeg to FLV using FFMPEG
    ffmpeg -i movie1.mpeg movie1.flv
    This will convert movie1.mpeg file to movie1.flv
  • Converting AVI to FLV using FFMPEG
    ffmpeg -i movie1.avi -s 500×500 movie1.flv
    This will convert movie1.avi file to movie1.flv and will resize the video resolution to 500×500
  • Converting 3GP to FLV using FFMPEG
    ffmpeg -i movie1.3gp -sameq -an movie1.flv
    This will convert movie1.3gp file to movie1.flv and will keep the original file settings and will disable the audio content
  • Converting MPEG to 3GP using FFMPEG
    ffmpeg -i movie1.mpeg -ab 8.85k -acodec libamr_wb -ac 1 -ar 16000 -vcodec h263 -s qcif movie2.3gp

Audio Examples:

  • Converting aac to mp3 using FFMPEG with MetaData
    ffmpeg -i audio1.aac -ar 22050 -ab 32 -map_meta_data audio1.mp3:audio1.aac audio1.mp3
    This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz and will copy the meta data from .aac file to .mp3 file
  • Converting WMV to MP3 using FFMPEG
    ffmpeg -i audio1.wmv audio1.mp3
    This will convert audio1.wmv file to audio1.mp3
  • Converting WMV to FLV using FFMPEG
    ffmpeg -i audio1.wmv audio1.flv
    This will convert audio1.wmv file to audio1.flv, this will generate only audio content
  • Converting AMR to MP3 using FFMPEG
    ffmpeg -i audio1.amr -ar 22050 audio1.mp3
    This will convert audio1.amr file to audio1.mp3 having audio rate 22.05 Khz
  • Converting aac to mp3 using FFMPEG
    ffmpeg -i audio1.aac -ar 22050 -ab 32 audio1.mp3
    This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz

Extract Image From Video Using FFMPEG

Posted by Hitesh Agrawal on Friday, 08.21.09 @ 20:07pm  •  Filled under Ffmpeg  • No comments  •   •  Views (50)  

FFMPEG is an awesome tool and today only i found that FFMPEG can extract JPEG image from video. To achieve this following are the software requirements.

  • FFMPEG
  • GD Library

FFMPEG Syntax:

ffmpeg -i 'video file' 'image file'

Example:

ffmpeg -i test.mpg image%d.jpg
This will create images on span of 1 second.
Example:
ffmpeg -i test.avi -ss 1.4 -vframes 33 -f image2 output%2d.jpg

In this example the image extraction will start from 1.4 second and will extract the image till 33rd frame.

Execute FFMPEG Command in PHP

Posted by Hitesh Agrawal on Friday, 08.21.09 @ 20:05pm  •  Filled under Ffmpeg  • Comments (9)  •   •  Views (804)  

It has been a nightmare for me searching for executing FFMPEG command from PHP. But finally i got the solution for executing ffmpeg from php script. This article will guide you on how to convert videos and audios using FFMPEG from within the PHP scripts.

NOTE:
I have tested this on Red Hat Enterprise(RHEL). Not sure about other Linux OS like Ubuntu etc. But i would say if it works then its rocking to execute FFMPEG inside the php scripts.

<?
define('FFMPEG_LIBRARY', '/usr/local/bin/ffmpeg ');
$exec_string = FFMPEG_LIBRARY.' -i inputfile.mpg outputfile.flv';
exxc($exec_string); //where exxc is the command used to execute shell command in php
?>
PHP Code Explanation
  • Defined an variable called FFMPEG_LIBRARY that holds the path to FFMPEG Libraries
  • Finally i am calling exec() function that executes the FFMPEG command

 

    Page [1] of 1   1