テレビでストリーミング動画が見れる!CentOSでDLNAサーバの作り方

2016/06/16

1280px-Dlna.svg

 

今回はfirefox OSを搭載したテレビやPS3などDLNAクライアントで手持ちの動画見れるようにDLNAサーバの作り方を紹介します。

サーバソフトは軽量な『miniDLNA』を使います。前提条件としてffmpegがインストールされていることが条件です。

別記事でAirVideoサーバの作り方を紹介していますが、その中にffmpegのインストール方法もありますのでffmpegをインストールしていないのであればそちらを参考にしてインストールして下さい。

 

目次

各インストール

CentOSのyumでDLNAサーバのパッケージを検索しても見つからなかったので手動でインストールします。

まずはtmpディレクトリに移動
# cd /tmp

公式ページからDLNAサーバのファイルをダウンロードします。(公式ページを確認して最新版を使うようにして下さい)
# get http://sourceforge.net/projects/minidlna/files/minidlna/1.1.5/minidlna_1.1.5_static.tar.gz/download

.tar.gzで圧縮されているので解凍します。
# tar -zxvf minidlna_1.1.5_static.tar.gz

するとこんな感じで解凍されるのを確認します。
usr/sbin/minidlna
usr/share/locale/sv/LC_MESSAGES/minidlna.mo
usr/share/locale/fr/LC_MESSAGES/minidlna.mo
usr/share/locale/nl/LC_MESSAGES/minidlna.mo
usr/share/locale/es/LC_MESSAGES/minidlna.mo
usr/share/locale/da/LC_MESSAGES/minidlna.mo
usr/share/locale/it/LC_MESSAGES/minidlna.mo
usr/share/locale/de/LC_MESSAGES/minidlna.mo
usr/share/locale/nb/LC_MESSAGES/minidlna.mo
usr/share/locale/ja/LC_MESSAGES/minidlna.mo
etc/minidlna.conf

これでインストールは完了です。
サーバの構成がかなり簡素になっているのでインストールは非常に簡単ですね。

 

miniDLNAコンフィグ設定

以下のコマンドを実行してコンフィグファイルを編集します。
# vi /etc/minidlna.conf

青字の部分の変更してください。元々コメントアウトになっている部分はグレーにしてあります。
黒字の部分はそのままコピぺで設定してください。

# port for HTTP (descriptions, SOAP, media transfer) traffic
port=8200

# network interfaces to serve, comma delimited
#network_interface=eth0

# specify the user account name or uid to run as
#user=jmaggard

# set this to the directory you want scanned.
# * if you want multiple directories, you can have multiple media_dir= lines
# * if you want to restrict a media_dir to specific content types, you
# can prepend the types, followed by a comma, to the directory:
# + "A" for audio (eg. media_dir=A,/home/jmaggard/Music)
# + "V" for video (eg. media_dir=V,/home/jmaggard/Videos)
# + "P" for images (eg. media_dir=P,/home/jmaggard/Pictures)
# + "PV" for pictures and video (eg. media_dir=PV,/home/jmaggard/digital_camera)
#media_dir=/opt
media_dir=V,/home/user/movie
media_dir=A,/home/user/music

# set this to merge all media_dir base contents into the root container
# note: the default is no
#merge_media_dirs=no

# set this if you want to customize the name that shows up on your clients
friendly_name=mydlna_server

# set this if you would like to specify the directory where you want MiniDLNA to store its database and album art cache
#db_dir=/var/cache/minidlna

# set this if you would like to specify the directory where you want MiniDLNA to store its log file
log_dir=/var/log

# set this to change the verbosity of the information that is logged
# each section can use a different level: off, fatal, error, warn, info, or debug
#log_level=general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn

# this should be a list of file names to check for when searching for album art
# note: names should be delimited with a forward slash ("/")
album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg

# set this to no to disable inotify monitoring to automatically discover new files
# note: the default is yes
inotify=yes

# set this to yes to enable support for streaming .jpg and .mp3 files to a TiVo supporting HMO
enable_tivo=no

# set this to strictly adhere to DLNA standards.
# * This will allow server-side downscaling of very large JPEG images,
# which may hurt JPEG serving performance on (at least) Sony DLNA products.
strict_dlna=no

# default presentation url is http address on port 80
#presentation_url=http://www.mylan/index.php

# notify interval in seconds. default is 895 seconds.
notify_interval=2

# serial and model number the daemon will report to clients
# in its XML description
serial=12345678
model_number=1

# specify the path to the MiniSSDPd socket
#minissdpdsocket=/var/run/minissdpd.sock

# use different container as root of the tree
# possible values:
# + "." - use standard container (this is the default)
# + "B" - "Browse Directory"
# + "M" - "Music"
# + "V" - "Video"
# + "P" - "Pictures"
# + Or, you can specify the ObjectID of your desired root container (eg. 1$F for Music/Playlists)
# if you specify "B" and client device is audio-only then "Music/Folders" will be used as root
#root_container=.

# always force SortCriteria to this value, regardless of the SortCriteria passed by the client
#force_sort_criteria=+upnp:class,+upnp:originalTrackNumber,+dc:title

# maximum number of simultaneous connections
# note: many clients open several simultaneous connections while streaming
#max_connections=50

 

起動/停止用のinitスクリプトを作成

OS起動時にDLNAサーバも自動的に起動するようにinitスクリプトを作成し、chkconfig onします。

# vi /etc/rc.d/init.d/minidlnad

#!/bin/bash
#
#chkconfig: 345 99 10
MINIDLNA=/usr/sbin/minidlnad
PIDFILE=/var/run/minidlna/minidlna.pid
CONF=/etc/minidlna.conf
ARGS="-f $CONF -R"
LOCKFILE=/var/lock/subsys/minidlna

. /etc/rc.d/init.d/functions

start() {
echo -n "Starting minidlna: "
daemon --pidfile=$PIDFILE $MINIDLNA $ARGS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
echo -n "Stopping minidlna: "
killproc -p $PIDFILE $MINIDLNA
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $PIDFILE $LOCKFILE
}

case $1 in
start)
start
;;
stop)
stop
;;
status)
status -p $PIDFILE $MINIDLNA
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
RETVAL=2
esac
exit $RETVAL

 

ファイルを保存し実行権限を与えます。
# chmod 755 /etc/rc.d/init.d/minidlnad

OS起動時にminiDLNAが自動起動するように登録し、確認します。
# chkconfig --add minidlnad
# chkconfig --list | grep minidlnad
minidlnad       0:off 1:off 2:on 3:on 4:on 5:on 6:off ←これが3:onと5:onになっていることを確認

 

miniDLNAの起動と自動起動設定

以下のコマンドでminiDLNAを起動できます。
/etc/rc.d/init.d/minidlnad start

ちなみにminiDLNAを再起動する場合は以下のコマンドです。
/etc/rc.d/init.d/minidlnad restart

ここまでできればminiDLNA側の設定は完了です。DLNA対応のクライアントでminiDLNAをインストールするしたIPアドレスを入力すれば、DLNAサーバを認識できるはずです。

 



関連記事

シェア訴求文言

-CentOS
-, , , ,