ubuntu/debianでAirVideoをサーバとして利用する方法

AirVideoはコンピュータ上で再生できる映像をiPhone,iPadで再生するというとても素晴らしいサービス、ソフトです。

http://www.inmethod.com/air-video/

しかも方法次第では外出先からもiPhone,iPadで自宅のコンピュータの映像が見れます。そのAirVideoをubuntu/debianで構築したのでその方法をメモっときます。動作環境は2.6.32-24-generic #42-Ubuntuです。

インストールの方法は
AirVideo Server under Linux | wiki.mbirth.de

を参考にしていますが多少異なっている部分などもあります。わからない部分は下記を参考にしていただけると書いた意味あります^^

1 下準備:ffmpegコンパイルのためのapt-get

aptでもインストールできますがconfigureなどのオプションを明確にするために自分でコンパイルします。その他、AirVideoでmp4creatorを利用するためにmpeg4ip-serverも入れます。

# apt-get install faad
# apt-get install libfaad-dev
# apt-get install libxvidcore-dev
# apt-get install libmp3lame
# apt-get install libx264-85
# apt-get install libx264-dev
# apt-get install mpeg4ip-server
# apt-get install libfaac-dev
# apt-get install libmp3lame-dev

2 ffmpegのdownloadとconfigure, make, make install

Licenses
からffmpegをdownloadします。私は2.2.5をdownloadしました。

# wget http://www.inmethod.com/air-video/download/ffmpeg-for-2.2.5.tar.bz2
# bzip2 -dc ffmpeg-for-2.2.5.tar.bz2 | tar xvf -
# cd ffmpeg
# ./configure --enable-gpl --enable-nonfree --enable-postproc \
--enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame \
--enable-libx264 --enable-libxvid --enable-x11grab --disable-shared \
--enable-static --disable-decoder=aac
# make
# make install

ffmpegで"ERROR: libx264 not found"エラーが出る場合

ffmpeg-2.2.5ではx264が見つからない "ERROR: libx264 not found" というエラーが出ることがあります。このバージョンのffmpegのバグのようです。最新版のffmpegコンパイルするとうまくいくことがあります。その際に、x264のバージョンが低いとffmpegコンパイルの際に怒られることがあります。x264を1からコンパイルしたほうが無難なようです。

http://www.videolan.org/developers/x264.html よりx264をdownload。

# wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
# bzip2 -dc last_x264.tar.bz2 | tar xvf -
# cd x264-*
# ./configure --disable-asm # アセンブラが入ってないので無効にしたほうが無難
# make
# make install

この後にffmpegの最新版をdownload
http://ffmpeg.org/download.html

# wget http://ffmpeg.org/releases/ffmpeg-0.6.90-rc0.tar.bz2
# bzip2 -dc ffmpeg-0.6.90-rc0.tar.bz2 | tar xvf -
# ./configure --enable-gpl --enable-nonfree --enable-postproc --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-x11grab --disable-shared --enable-static --disable-decoder=aac --disable-yasm

これでffmpegコンパイルできることがあります。

3 AirVideoServerLinuxの起動

AirVideoLinuxServerをDownloadします。

# wget http://inmethod.com/air-video/download/linux/alpha5/AirVideoServerLinux.jar

AirVideoServerLinuxはjavaベースです。Java一式が入っていない場合はとりあえず

# apt-get install openjdk-6-jre

で問題はないと思います。

AirVideoServerLinuxの起動用設定ファイルを作ります。

#vim test.properties

test.propertiesの内容

path.ffmpeg = /usr/local/bin/ffmpeg
path.mp4creator = /usr/bin/mp4creator
path.faac = /usr/bin/faac
password = xxxxx ←パスワード
subtitles.encoding = windows-1250
subtitles.font = Verdana
folders = Movies:/var/xxxxx ←共有するパス(Moviesという名前で共有)

では早速AirVideoServerLinuxを動かします。
【AirVideoServerLinux.jarとtest.propertiesは同じパスに保存してください。】

# java -jar AirVideoServerLinux.jar test.properties

これで起動します。iPhone,iPadからサーバのipを入力してアクセスしてみてください。"Your AirVideo server is outdated"などというメッセージがiPhone,iPadで出る場合は単純にAirVideoServerLinux.jarのバージョンが低いことがあります。

現時点(2012-09-07)では

http://inmethod.com/air-video/download/linux/alpha1/AirVideoServerLinux.jar
http://inmethod.com/air-video/download/linux/alpha2/AirVideoServerLinux.jar
http://inmethod.com/air-video/download/linux/alpha3/AirVideoServerLinux.jar
http://inmethod.com/air-video/download/linux/alpha4/AirVideoServerLinux.jar
http://inmethod.com/air-video/download/linux/alpha5/AirVideoServerLinux.jar
http://inmethod.com/air-video/download/linux/alpha6/AirVideoServerLinux.jar

がリリースされています。もしかしたら新しいものが出ているかもしれませんので探してみてください。

4 avahi, bonjourで検索

IP指定ではなくbonjourで簡単にAirVideoServerにアクセス出来るようにする方法です。

# apt-get install avahi-daemon

でavahi-daemonをインストール。入っている場合は不要です。

その後

# vim /etc/avahi/services/airvideo.service

/etc/avahi/services/airvideo.serviceの内容

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service> 
    <type>_airvideoserver._tcp</type>  
    <port>45631</port>  
</service>
</service-group>
# /etc/init.d/avahi-daemon start 

5 AirVideoServerLinuxを自動起動させる

update-rc.d使ってもいいのですが。upstartを使っています。upstart入ってない場合は

# apt-get install upstart

upstart用にAirVideo起動設定

# mkdir /opt/AirVideoServer
# cp test.property /opt/AirVideoServer
# cp VirVideoServerLinux.jar /opt/AirVideoServer
# vim /etc/init/airvideo.conf

/etc/init/airvideo.confに

start on runlevel [2345]
stop on shutdown
respawn

exec sudo -H -n -u mbirth env LANG=ja_JP.UTF-8 \
`which java` -jar /opt/AirVideoServer/AirVideoServerLinux.jar \
/opt/AirVideoServer/test.properties

mbirthは自分のユーザ名です

あとはupstart

# sudo start airvideo

で起動します。

実際に上記通りで動作したので問題はないと思います。