Showing posts with label Media. Show all posts
Showing posts with label Media. Show all posts

2011/08/04

HOWTO: Install and use the latest FFmpeg and x264

http://ubuntuforums.org/showthread.php?t=786095

Install the Dependencies
1. Uninstall x264, libx264-dev, and ffmpeg if they are already installed. Open a terminal and run the following (you can usually paste into a terminal with shift+ctrl+v). Copy and paste the whole code box for each step.

Code:
sudo apt-get remove ffmpeg x264 libx264-dev
2. Get all of the packages you will need to install FFmpeg and x264 (you may need to enable the Universe and Multiverse repositories):
Code:
sudo apt-get update
sudo apt-get install build-essential checkinstall git libfaac-dev libjack-jackd2-dev \
  libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev \
  libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html \
  yasm zlib1g-dev

Install x264
3. Get the current source files, compile, and install x264.
Code:
cd
git clone git://git.videolan.org/x264
cd x264
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
    awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
    --fstrans=no --default

Install libvpx (optional)
4. This is used to encode VP8 video. If you follow this step, add --enable-libvpx to the FFmpeg ./configure line in step 5.
Code:
sudo apt-get remove libvpx-dev
cd
git clone git://review.webmproject.org/libvpx
cd libvpx
./configure
make
sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" --backup=no \
    --deldoc=yes --fstrans=no --default

Install FFmpeg
5. Get the most current source files, compile, and install FFmpeg.
Code:
cd
git clone git://git.videolan.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
    --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 \
    --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no \
  --deldoc=yes --fstrans=no --default
hash x264 ffmpeg ffplay ffprobe

Install qt-faststart (optional)
6. This is a useful tool if you're showing your H.264 MP4 videos on the web. It relocates some data in the video to allow playback to begin before the file is completely downloaded. Usage: qt-faststart input.mp4 output.mp4.
Code:
cd ~/ffmpeg
make tools/qt-faststart
sudo checkinstall --pkgname=qt-faststart --pkgversion="$(date +%Y%m%d%H%M)-git" --backup=no \
    --deldoc=yes --fstrans=no --default install -D -m755 tools/qt-faststart \
    /usr/local/bin/qt-faststart

Adding lavf support to x264 (optional)
7. This allows x264 to accept just about any input that FFmpeg can handle and is useful if you want to directly use x264.
Code:
cd ~/x264
make distclean
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
    awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
    --fstrans=no --default
That's it for installation. You can keep the x264, libvpx, and ffmpeg directories in your home directory if you plan on updating later. See Updating FFmpeg and x264 below for more details.



Using FFmpeg and x264
The easiest method for high quality video encoding is by using the libx264 presets. See x264 --fullhelp for more info on these options.

One-pass CRF (Constant Rate Factor) using the slow preset. One-pass CRF is good for general encoding and is what I use most often. Adjust -crf to change the quality. Lower numbers mean higher quality and a larger output file size. A sane range is 18 to 28.
Code:
ffmpeg -i input -acodec libfaac -aq 100 -vcodec libx264 -preset slow -crf 22 \
    -threads 0 output.mp4
One-pass CRF (Constant Rate Factor) using the medium preset, animation tuning, baseline profile, and level 3.0:
Code:
ffmpeg -i input -acodec libfaac -aq 100 -vcodec libx264 -preset medium \
    -tune animation -profile baseline -level 3.0 -crf 20 -threads 0 output.mp4
Two-Pass encode using the fast preset. Two-pass encoding is usually used when you want a specific output file size.
Code:
ffmpeg -i input -pass 1 -vcodec libx264 -preset fast -b 512k -threads 0 \
    -f mp4 -an -y /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k \
    -ac 2 -vcodec libx264 -preset fast -b 512k -threads 0 output.mp4


Updating FFmpeg and x264
Development of FFmpeg and x264 is active and an occasional update can give you new features and bug fixes. First, remove some packages and then update the dependencies:
Code:
sudo apt-get remove ffmpeg x264 libx264-dev libvpx-dev
sudo apt-get update
sudo apt-get install build-essential git checkinstall yasm texi2html \
  libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev \
  libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev \
  libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
Update x264:
Code:
cd ~/x264
make distclean
git pull
Now compile x264 as shown earlier in the guide starting with the x264 ./configure line. Update libvpx:
Code:
cd ~/libvpx
make clean
git pull
Now compile libvpx as shown earlier in the guide starting with the libvpx ./configure line. Update FFmpeg:
Code:
cd ~/ffmpeg
make distclean
git pull
Finish the installation starting with the FFmpeg ./configure line.



Reverting Changes Made by This Guide
To remove FFmpeg/x264 and other packages added for this guide:
Code:
sudo apt-get autoremove x264 ffmpeg qt-faststart build-essential git checkinstall \
  yasm texi2html libfaac-dev libjack-jackd2-dev libmp3lame-dev libsdl1.2-dev \
  libtheora-dev libva-dev libvdpau-dev libvorbis-dev libvpx libx11-dev libxfixes-dev \
  libxvidcore-dev zlib1g-dev
Lastly, delete the x264, libvpx, and ffmpeg directories in your home folder.


Additional Resources

2011/08/03

Play MPEG-2 TS with VLC

$ vlc --demux ffmpeg file.ts # run vlc with ffmpeng demux

MPEG-TS, MPEG-PS

=期待= 要瞭解TP,還得從TS說起。先來簡要介紹一下什麼是MPEG2-TS吧。MPEG2格式大家都通過對DVD的接觸而多多少少瞭解了一些,DVD節目中的 MPEG2格式,確切地說是MPEG2-PS,全稱是Program Stream,而TS的全稱則是Transport Stream。PS與TS都是基於mpeg2運動壓縮算法的流媒體。所以平常我們可以把ts文件後綴改成mpeg而不影響觀看。

MPEG是『Moving Picture Experts Group』的簡稱,在它之前的標準叫做JPEG,即『Joint Photographic Experts Group』。當人們用到常見的『.jpg』格式時,實際上正在使用JPEG的標準。JPEG規範了現代視頻壓縮的基礎,而MPEG把JPEG標準擴展到 了運動圖像。而MPEG-2是MPEG-1之後的標準,是與MPEG-1向後兼容的,但同時又增加了幾個新的內容,這包括5.1聲道環繞聲,即除了左右聲 道外還加有中央聲道、左後聲道和右後聲道,以及一個低頻增強聲道,前面的5.1中的.1就是指這個低頻聲道。MPEG-1包含了構成一幅圖像所需的全部元 素,這些元素構成了所謂的『系統流(system stream)』。在MPEG-2中,系統流被重新命名為『節目流(program stream)』,節目流還規定了傳輸流(transport stream)(也就是ts)用於容易出錯的媒體。節目流同時還增加了數字電視的服務內容。MPEG-2是一種同時適用於空間傳送與電纜傳送的MPEG標 準。所以HDTV實際上被併入到MPEG-2中~

那麼這兩種格式的主要區別是什麼呢?簡單地打個比方說,你將DVD上的VOB文件的前面一截cut掉(或者乾脆就是數據損壞),那麼就會導致整個文件無法 解碼了,而電視節目是你任何時候打開電視機都能解碼(收看)的,所以,MPEG2-TS格式的特點就是要求從視頻流的任一片段開始都是可以獨立解碼的,所 以我們可以從某個整場中截取一段視頻而不會影響播放,正是這個道理。也正是如此,我們的tp流出現了————TP流實際上是從MPEG2- transport stream(TS)中截取出來的一段packet(package),也就是
MPEG2-transport stream packet或者transport packet,簡稱TP或者TRP

所以tp實際上也可以說是一種封裝包,裡面含有視頻流和音頻流數據,這一點和avi、mkv是一樣的。所不同的是採用的MPEG2的壓縮標準,而且tp、 ts的碼率一般在16~20Mbps左右(VCD是1.5Mbp,DVD是4-6Mbps),也就是 2.x M字節/秒的速率,一個HDTV頻道的碼率甚至在20Mbps左右,數據量相當龐大,而且一般採用ac3音頻格式,所以體積就更龐大,.tp和.ts電影 能達到8G以上,有的甚至達到20多G(比如說魔戒2 1080i)。在這裡我順便提一下1080i(1080i:水平掃瞄行數為1080行,每行有1920或者1440個圖像點的高清晰度電視標準,用「半圖 像」的方法進行信號傳輸,「隔行掃瞄」,每次圖像刷新只在一半的掃瞄行中進行。使用的頻率為50或者60 Hz。特別適用於放映故事片或者是文稿演示) 站上的tp幾乎都是1920×1080i的,所以清晰度絕對保證~

Reference: http://www.hd.club.tw/archiver/tid-5793.html

2011/08/02

Install mediainfo on Ubuntu 10.10

sudo add-apt-repository ppa:razrfalcon/qmediainfo

sudo apt-add-repository ppa:shiki/mediainfo

sudo apt-get update

sudo apt-get install qmediainfo

Reference