11. ffmpeg + AirVideo Server 설치 [NAS 구축기][ubuntu 10.4]

얼렁뚱땅설명서 2012. 3. 6. 10:58


ffmpeg는 인코딩 프로그램을 유명하다. Airvideo Server을 설치하기 전에 먼저 설치하는 이유는  Airvideo Server가 더 훌륭해 지거나 Live Conversion이 매우 빠르게 수행될 것 같은 느낌 때문이다. 근거는 없다. 

ffmpeg는 컴파일을 해야하므로 일단, 시스템을 업데이트 하고 기본적인 컴파일 도구를 설치한다.
덤으로 인코딩에 사용할 여러개의 라이브러리도 설치한다. 명령어가 조금 길다.

username@Team4Svr:~$ sudo -s
root@Team4Svr:~#  apt-get update
.......
.......
....... 
 
패키지 목록을 읽는 중입니다... 완료
root@Team4Svr:~# apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
build-essential 패키지는 이미 최신 버전입니다.
.....
.....
..... 
0개 업그레이드, 61개 새로 설치, 0개 지우기 및 0개 업그레이드 안 함.
28.1M바이트 아카이브를 받아야 합니다.
이 작업 후 86.7M바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까 [Y/n]?
.....
.....
너무 길어서 이하생략
.....
.....
libxvidcore-dev (2:1.2.2+debian-0ubuntu2) 설정하는 중입니다 ...
subversion (1.6.6dfsg-2ubuntu1.3) 설정하는 중입니다 ...
texi2html (1.82-1) 설정하는 중입니다 ...
yasm (0.8.0-1) 설정하는 중입니다 ...
libc-bin에 대한 트리거를 처리하는 중입니다 ...
ldconfig deferred processing now taking place



x264 라이브러리를 설치한다. x264는 H.264의 구현으로 '매우 높은 데이터 압축률을 가지는 디지털 비디오 코덱 표준으로 MPEG-4 파트 10 또는 MPEG-4/AVC(고급 비디오 부호화, Advanced Video Coding)라 부르기도 한다.-한국위키-'....... 하여간 좋은 거다.;
 

root@Team4Svr:~# cd
root@Team4Svr:~# git clone git://git.videolan.org/x264.git
Initialized empty Git repository in /home/fishingday/x264/.git/
remote: Counting objects: 15359, done.
remote: Compressing objects: 100% (2923/2923), done.
remote: Total 15359 (delta 12578), reused 15174 (delta 12395)
Receiving objects: 100% (15359/15359), 3.80 MiB | 749 KiB/s, done.
Resolving deltas: 100% (12578/12578), done.
root@Team4Svr:~# cd x264
root@Team4Svr:~/x264#
root@Team4Svr:~/x264# ./configure   <--- yasm 버전이 낮다고 한다. 아래와 같이 한다.
Found yasm 0.8.0.2194
Minimum version is yasm-1.0.0
If you really want to compile without asm, configure with --disable-asm.
root@Team4Svr:~/x264# ./configure --enable-shared --disable-asm
platform:      X86_64
system:        LINUX
cli:           yes
libx264:       internal
shared:        yes
static:        no
asm:           no
interlaced:    yes
avs:           no
lavf:          no
ffms:          no
gpac:          no
gpl:           yes
thread:        posix
filters:       crop select_every
debug:         no
gprof:         no
strip:         no
PIC:           yes
visualize:     no
bit depth:     8
chroma format: all

You can run 'make' or 'make fprofiled' now.
root@Team4Svr:~/x264#
isualize:     no
bit depth:     8
chroma format: all

You can run 'make' or 'make fprofiled' now.
root@Team4Svr:~/x264# checkinstall --pkgname=x264 --pkgversion "2:0.`grep X264_BUILD x264.h -m1 | cut -d' ' -f3`.`git rev-list HEAD | wc -l`+git`git rev-list HEAD -n 1 | head -c 7`" --backup=no --deldoc=yes --fstrans=no --default

checkinstall 1.6.1, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.


The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs?  [y]: y

Preparing package documentation...OK

*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values:

0 -  Maintainer: [ root@Team4Svr ]
1 -  Summary: [ Package created with checkinstall 1.6.1 ]
2 -  Name:    [ x264 ]
3 -  Version: [ 2:0.120.2164+gitda19765 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ x264 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ x264 ]

Enter a number to change any of them or press ENTER to continue:

Installing with make...Installing with install...

========================= Installation results ===========================
....
.... 생략...
....
======================== Installation successful ==========================

Copying documentation directory...
./
./AUTHORS
./doc/
./doc/vui.txt
./doc/standards.txt
./doc/threads.txt
./doc/regression_test.txt
./doc/ratecontrol.txt
./COPYING
grep: /var/tmp/tmp.llEegCHGR8/newfile: 그런 파일이나 디렉터리가 없습니다

Some of the files created by the installation are inside the build
directory: /home/fishingday/x264

You probably don't want them to be included in the package,
especially if they are inside your home directory.
Do you want me to list them?  [n]: n
Should I exclude them from the package? (Saying yes is a good idea)  [y]: y

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

Installing Debian package...OK

Erasing temporary files...OK

Deleting doc-pak directory...OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been installed and saved to

 /home/fishingday/x264/x264_2:0.120.2164+gitda19765-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r x264

**********************************************************************

root@Team4Svr:~/x264#


 이제 ffmpeg를 설치해 준다.

root@Team4Svr:~# cd
root@Team4Svr:~# svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
....
....
A    ffmpeg/MAINTAINERS
A    ffmpeg/COPYING.LGPLv3
 U   ffmpeg
체크아웃된 리비전 26402.
root@Team4Svr:~# cd ffmpeg
root@Team4Svr:~/ffmpeg# ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab
.......
.......
.......
Enabled bsfs:
aac_adtstoasc           mjpeg2jpeg              mp3_header_decompress
chomp                   mjpega_dump_header      noise
dump_extradata          mov2textsub             remove_extradata
h264_mp4toannexb        mp3_header_compress     text2movsub
imx_dump_header

Enabled indevs:
alsa                    oss                     v4l2
dv1394                  v4l                     x11_grab_device

Enabled outdevs:
alsa                    oss

License: nonfree and unredistributable
Creating config.mak and config.h...
root@Team4Svr:~/ffmpeg# make
CC      libavdevice/alldevices.o
CC      libavdevice/alsa-audio-common.o
CC      libavdevice/alsa-audio-dec.o
CC      libavdevice/alsa-audio-enc.o
CC      libavdevice/avdevice.o
.....
.....
.....
POD     doc/ffmpeg.pod
MAN     doc/ffmpeg.1
POD     doc/ffplay.pod
MAN     doc/ffplay.1
POD     doc/ffprobe.pod
MAN     doc/ffprobe.1
POD     doc/ffserver.pod
MAN     doc/ffserver.1
root@Team4Svr:~/ffmpeg# checkinstall --pkgname=ffmpeg --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default
....
....
....
Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

Installing Debian package...OK

Erasing temporary files...OK

Deleting doc-pak directory...OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been installed and saved to

 /home/fishingday/ffmpeg/ffmpeg_4:SVN-r26402-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r ffmpeg

**********************************************************************

root@Team4Svr:~/ffmpeg# hash x264 ffmpeg ffplay
root@Team4Svr:~/ffmpeg# make tools/qt-faststart
CC      tools/qt-faststart.o
LD      tools/qt-faststart
rm tools/qt-faststart.o
root@Team4Svr:~/ffmpeg# checkinstall --pkgname=qt-faststart --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default install -D -m755 tools/qt-faststart /usr/local/bin/qt-faststart

checkinstall 1.6.1, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.


The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs?  [y]: y

Preparing package documentation...OK

*****************************************
**** Debian package creation selected ***
*****************************************

This package will be built according to these values:

0 -  Maintainer: [ root@Team4Svr ]
1 -  Summary: [ Package created with checkinstall 1.6.1 ]
2 -  Name:    [ qt-faststart ]
3 -  Version: [ 4:SVN-r26402 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ ffmpeg ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ qt-faststart ]

Enter a number to change any of them or press ENTER to continue:

Installing with install...Installing with -D...Installing with -m755...Installing with tools/qt-faststart...Installing with /usr/local/bin/qt-faststart...

========================= Installation results ===========================

======================== Installation successful ==========================

.......
.......
.......

Copying files to the temporary directory...OK

Stripping ELF binaries and libraries...OK

Compressing man pages...OK

Building file list...OK

Building Debian package...OK

Installing Debian package...OK

Erasing temporary files...OK

Deleting doc-pak directory...OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been installed and saved to

 /home/fishingday/ffmpeg/qt-faststart_4:SVN-r26402-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r qt-faststart

**********************************************************************

root@Team4Svr:~/ffmpeg#

짜잔 FFmpeg의 설치가 끝났다. CentOS에서 설치할땐 하루 종일 걸렸던 것 같은데.... 우분투에선 금방 이다. 
그럼 이제 ffmpeg를 실행 해 보자. 기대와 달리 실행할 수 없다는 오류를 냉큼 떨어뜨린다. ㅡㅡ;

root@Team4Svr:~/ffmpeg# ffmpeg
ffmpeg: error while loading shared libraries: libx264.so.120: cannot open shared object file: No such file or directory
root@Team4Svr:~/ffmpeg#

 공유 라이브러리를 찾을 수 없다는 오류 이므로, 아래와 같은 조치를 취한 후 다시 실행해 준다.

root@Team4Svr:~/ffmpeg# vi /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf

/usr/local/lib   <--- 추가하고 저장 한다.
~
root@Team4Svr:~/ffmpeg# ldconfig
root@Team4Svr:~/ffmpeg# ffmpeg
FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers
  built on Mar  6 2012 10:44:30 with gcc 4.4.3
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab
  libavutil     50.36. 0 / 50.36. 0
  libavcore      0.16. 1 /  0.16. 1
  libavcodec    52.108. 0 / 52.108. 0
  libavformat   52.93. 0 / 52.93. 0
  libavdevice   52. 2. 3 / 52. 2. 3
  libavfilter    1.74. 0 /  1.74. 0
  libswscale     0.12. 0 /  0.12. 0
  libpostproc   51. 2. 0 / 51. 2. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'
root@Team4Svr:~/ffmpeg#



FFmpeg의 간단하 사용방법이다.

### One-pass CRF
ffmpeg -i input.avi -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads 0 output.mp4

### Two-Pass 인코딩
ffmpeg -i input.avi -pass 1 -vcodec libx264 -vpre fast_firstpass -b 512k -bt 512k    -threads 0 -f rawvideo -an -y /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre fast -b 512k -bt 512k -threads 0 output.mp4

### iPod 640x480 으로 인코딩
ffmpeg -i input.avi -acodec libfaac -aq 100 -ac 2 -vcodec libx264 -vpre slow -vpre ipod640 -crf 26 -map_meta_data 0:0 -vf scale=640:-1 -threads 0 output.mp4


아래는 오래전(?)에 테스트 하면서 사용한 명령어이다. 여러가지 포맷으로 변환이 된다.

[root@localhost test] ffmpeg -i 640x480.wmv -y -s 640x360 -acodec libfaac -ar 32000 -ab 48000 -ac 2 -f flv -vcodec flv -b 700k tranc640x360.flv 
....
[root@localhost test] ffmpeg -i 640x480.wmv -y -threads 4-s 640x360 -acodec libfaac -ar 32000 -ab 48000 -ac 2 -f mp4 -vcodec libx264 -vpre fast -b 1000k -g 30 -bf 2 -b_strategy 1 tranc640x360.mp4

[root@localhost test] ffmpeg -i 640x480.wmv -y -threads 4-s 640x360 -acodec libfaac -ar 32000 -ab 48000 -ac 2 -f mp4 -vcodec mpeg4 -b 1000k  tranc640x360.mp4

인코딩 참고 사이트 : http://ospace.tistory.com/125, http://xmlangel2.blogspot.com/2010/04/ffmpeg-%EA%B8%B0%EB%B3%B8-%EC%82%AC%EC%9A%A9%EB%B2%95.html, http://ffmpeg.org/ffmpeg-doc.html 

※ ffmepg 설치방법은 여기서(http://ubuntuforums.org/showthread.php?t=786095) 참고 했다. 배꼈다. ㅡㅡ;



이제 드디어 Airvideo Server를 설치할 차례이다. 설치는 매우 간단하고 빠르다.

root@Team4Svr:~# add-apt-repository ppa:rubiojr/airvideo
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv A58221FEBF9C6AC1914B24ACC2B39E5DF6BD82A0
gpg: requesting key F6BD82A0 from hkp server keyserver.ubuntu.com
gpg: key F6BD82A0: public key "Launchpad PPA for rubiojr" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
root@Team4Svr:~# apt-get update
....
....
root@Team4Svr:~# sudo apt-get install airvideo-server
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
........
........
  airvideo-server ca-certificates-java faac icedtea-6-jre-cacao java-common
  libaccess-bridge-java libaccess-bridge-java-jni libclucene0ldbl libfaad2 libiodbc2
  libmodplug0c2 libmp4v2-0 libmpeg4ip-0 libmysqlclient16 libphonon4 libqscintilla2-5
  libqt4-dbus libqt4-designer libqt4-multimedia libqt4-network libqt4-opengl libqt4-ruby1.8
  libqt4-script libqt4-sql libqt4-sql-mysql libqt4-svg libqt4-test libqt4-webkit libqt4-xml
  libqt4-xmlpatterns libqtruby4shared2 libruby1.8 libsmokeqt4-3 libsmokesoprano3 libsoprano4
  libx264-85 libxcb-shape0 libxcb-shm0 libxcb-xv0 libxine1 libxine1-bin libxine1-console
  libxine1-misc-plugins libxine1-x mpeg4ip-server mysql-common openjdk-6-jre
  openjdk-6-jre-headless openjdk-6-jre-lib phonon phonon-backend-xine ruby ruby1.8
  soprano-daemon ttf-dejavu-extra tzdata-java virtuoso-nepomuk
0개 업그레이드, 57개 새로 설치, 0개 지우기 및 0개 업그레이드 안 함.
78.9M바이트 아카이브를 받아야 합니다.
이 작업 후 228M바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까 [Y/n]?
......
......
......
openjdk-6-jre (6b20-1.9.13-0ubuntu1~10.04.1) 설정하는 중입니다 ...
update-alternatives: /usr/lib/jvm/java-6-openjdk/jre/bin/javaws 사용해서 자동 모드에서 /usr/bin/javaws (javaws) 제공.
update-alternatives: /usr/lib/jvm/java-6-openjdk/jre/bin/pluginappletviewer 사용해서 자동 모드에서 /usr/bin/pluginappletviewer (pluginappletviewer) 제공.
update-alternatives: /usr/lib/jvm/java-6-openjdk/jre/bin/policytool 사용해서 자동 모드에서 /usr/bin/policytool (policytool) 제공.

airvideo-server (0alpha6ubuntu1~lucid1) 설정하는 중입니다 ...
libc-bin에 대한 트리거를 처리하는 중입니다 ...
ldconfig deferred processing now taking place
root@Team4Svr:~# vi /opt/airvideo-server/AirVideoServerLinux.properties
path.ffmpeg = /opt/airvideo-server/bin/ffmpeg
path.mp4creator = /usr/bin/mp4creator
path.faac = /usr/bin/faac
password =
subtitles.encoding = euc-kr   <-- 변경
subtitles.font = undotum  <-- 변경
folders = Movies:/DataCenter/Movies,/DataCenter/Study  <-- 변경

이제 설치가 끝났다. AirVideo Server를 실행하기 위해선 아래의 화면과 같이 프로그램>음악과비디오>Airvideo Server 를 찾아서 실행한다.
서버를 띄우면 아래 화면처럼 아이콘이 생기는 것을 볼 수 있다. 여기서 Start Server를 눌러주면 된다.



아래는 아이폰을 통해 Airvideo Server에 접속한 모습니다. 아이폰의 Airvideo 프로그램은 유료 버전과 무료 버전이 있다. 유료와 무료의 차이점은 목록이 전부다 나오느냐, 일부만 나오느냐의 차이다. 그 외에는 차이는 없는 듯 하다. [+] 버튼을 눌러 Specify Address Manually를 선택한 다음 서버주소와 포트 번호를 누르면 서버를 간단히 추가할 수 있다. 그리고, 서버를 누르면 목록을 볼 수 있고, 목록에서 동영상을 선택하면 된다. mp4로 인코딩 된 동영상은 바로 실행이 되지만, 그 외에는 Play with Live Conversion을 통해 동영상을 즐길 수 있다.