How-To: Raspberry Pi media SERVER (easy)

by jelleke60 » Fri Sep 20, 2013 8:59 pm

In this tutorial I will attempt to explain how to turn your Raspberry Pi in a media SERVER to stream media to your home network or even remote network.

This setup will allow the following:
    -> Stream movies/photo's/music TO your home network and remote network.
    -> Stream to any device (PC/laptop/XBMC/WD Live/Popcorn/Android/...)
    -> SRT support for movies
    -> HD support
    -> Using samba share and FTP share methods

You will need:
    -> Raspberry Pi with the latest Raspbian image installed http://www.raspberrypi.org/downloads
    -> internet connection to your PI
    -> External USB HDD with media content (ordered in seperate folders)
    -> Another device to stream the content to such as a laptop,media box, ...[/url]

Let's get started

You can use SSH to acces your terminal on the RPI from another device or use the terminal on the device itself by using a monitor/keyboard with the RPI.
In your terminal type the following:

Update your Repo's
CODE: SELECT ALL
sudo apt-get update

If you are going to use a NTFS based external hard drive (most are) (TIP: ext4 file systems are the fastest)
CODE: SELECT ALL
sudo apt-get install ntfs-3g

Now insert your usb hard drive in the RPI and wait untill it gets mounted. If it's mounted type the following
CODE: SELECT ALL
sudo df

A list of installed hard drives will appear. Write down your external HD's location. Mine was /dev/sda1. Type the following commands. (You might want to CHMOD your HDD folder permissions if you get permission errors later)
CODE: SELECT ALL
cd /media
sudo mkdir HDD
sudo nano /etc/fstab

A file will open, on the bottom of the file type the following and then exit and save the file (ctrl+x, Y, enter, enter). Remember to replace /dev/sda1 with your HDD location. Also replace ntfs-3g with vfat if your have a fat based HDD or ext4 for a ext4 filesystem. Whitespaces areTABS
CODE: SELECT ALL
/dev/sda1         /media/HDD       ntfs-3g     defaults,noatime      0        0

Back in terminal, type these commands
CODE: SELECT ALL
sudo umount /dev/sda1
sudo mount /dev/sda1

Your external Hard drive should now always be mounted in the folder HDD. So far so good, now lets install samba and vsftpd.
CODE: SELECT ALL
sudo apt-get install samba samba-common-bin
sudo apt-get install vsftpd
sudo apt-get install hdparm
sudo hdparm -S 240 /dev/sda1 ##DO THIS ONLY if you want to spindown your external hard drive when it's inactive for 20min, handy if you always want to keep everything powered.

Configure Samba, for home network share (skip if you only want a remote share)
CODE: SELECT ALL
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak  //Make a backup of the config file
nano /etc/samba/smb.conf

when the file opens scroll to the bottom and paste the following, then save and exit
CODE: SELECT ALL
[media] 
comment = Media share
path = /media/HDD
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

Now make an extra account to log into samba on another device
CODE: SELECT ALL
sudo service samba restart
sudo useradd ChooseUsernameHere -m -G users
sudo passwd TheChosenUsername //after this choose a password for the new user
sudo smbpasswd -a TheChosenUsername //after this enter passwd again

All set! Scroll to the bottom to see how to stream movies on another device now in the home network if you want to skip remote streaming.

Configure remote streaming
First make an extra user (if you skipped samba setup)
CODE: SELECT ALL
sudo useradd ChooseUsernameHere -m -G users
sudo passwd TheChosenUsername //after this choose a password for the new user

Configure vsftpd
CODE: SELECT ALL
sudo nano /etc/vsftpd.conf

##Edit or uncomment the following lines ::::
Anonymous_enable=NO
Local_enable=YES
Write_enable=YES
Ascii_upload_enable=YES
Ascii_download_enable=YES

##ADD the following lines to the bottom of the file!
pasv_enable=YES
listen_port=64000
pasv_min_port=64001
pasv_max_port=64040
pasv_address=YOUR REMOTE IP ADDRESS (lookup my ip on google)
pasv_address_resolve=YES
local_root=/media/HDD

important! Now go into your Router settings and forward port 64000 to 64040, to the local IP of your raspberry. Make sure everything has a static address, if you don't know how to do it then lookup another tutorial, there are plenty.
CODE: SELECT ALL
sudo service vsftpd restart

All done on the Raspberry Pi side! Now take your laptop/XBMC/mediabox!

On a PC/XBMC mediabox where you want to stream to

Note: it really helps if your video files on the HDD are properly ordered and in seperate folders with movie title.
If you are on a laptop/pc then install XBMC for windows/linux http://xbmc.org/download/.

Open XBMC and do the following (for video streaming on the HOME network)
    -> videos -> files -> add videos...
    Click browse and choose Windows network (SMB) (You could even map the share into a drive first in windows)
    -> Choose the raspberry out of the list and then the folder where your files are
    -> next choose movie scraper and make sure settings are ok, then scan the content, when it's done you should be able to stream movies from your RPI!

For REMOTE streaming
    -> videos -> files -> add videos...
    Click browse and choose Add network location
    -> protocol = FTP
    -> Address = your remote IP (the one from google)
    -> port = 64000
    -> username = the extra user you made before 
    -> pass = the users passwd
    -> click OK and then select it, now choose movie scraper and check the settings

Done! I hope you enjoy your new streaming device! 

For me, this works like a charm, i was able to watch HD movies in a Hotel abroad on my laptop, streaming from my RPI at home.
XBMC installs on almost everything (RPI, PC,Linux,Android) so you would be able to stream to all those devices using the above method.

Let me know what you think and ask questions if you like! Greets
Last edited by jelleke60 on Tue Oct 21, 2014 4:19 pm, edited 3 times in total.


'Linux > RaspberryPi' 카테고리의 다른 글

ftp명령어  (0) 2015.06.29
ftp확인  (0) 2015.06.29
raspberry pi network status  (0) 2015.06.29
라즈베리파이에 FTP서버 구축  (0) 2015.06.29
Raspberry Pi – Enabling Telnet  (0) 2015.06.29

+ Recent posts