Chapter 9. Streaming with Ampache
In this chapter, we will cover the following recipes:
- Installing the Ampache server
- Uploading contents and creating catalogs
- Setting on-the-fly transcoding
- Enabling API access for remote streaming
- Streaming music with Ampache
Introduction
This chapter covers the installation and configuration of the open source audio and video streaming service, Ampache. It is a web-based streaming application that allows you to upload your own audio/video contents and access them across multiple Internet-enabled devices. You can easily set up your home media server using Ampache and your old personal computer running Ubuntu. We will focus on installing Ampache on the Ubuntu server, but you can install Ampache on any Linux distribution of your choice.
Installing the Ampache server
This recipe covers the installation of the Ampache server. It is a simple PHP-based web application. Once installed and set up, you can use a web interface to play your audio/video files or use any of the various popular streaming clients to stream content over the intranet or even the Internet.
Getting ready
We will be using Ubuntu Server 16.04, but you can choose to have any version of Ubuntu.
Additionally, we will need the Samba server. It will be used as shared network storage.
As always, access to a root account or an account with sudo
privileges will be required.
How to do it…
Ampache is a web application developed in PHP. We will start the installation with the LAMP stack. This recipe covers installation with the Apache web server, but you can choose any other web server:
- Install the LAMP stack if it's not already installed:
$ sudo apt-get update $ sudo apt-get install apache2 mysql-server-5.5 php7 \ php7-mysql php7-curl libapache2-mod-php7
Note
For more details on Apache and PHP installation, check Chapter 3, Working with Web Server
- Next, download the latest Ampache server source code. Ampache is a PHP application:
$ wget https://github.com/ampache/ampache/archive/3.8.0.tar.gz Extract achieve contents under a web root directory $ tar -xf 3.8.0.tar.gz -C /var/www $ mv /var/www/ampache-3.8.0 /var/www/ampache
- We also need to create some configuration files. You can use the default configuration that ships with the Ampache setup and rename the existing files:
$ cd /var/www/ampache $ mv rest/.htaccess.dist rest/.htaccess $ mv play/.htaccess.dist play/.htaccess $ mv channel/.htaccess.dist channel/.htaccess
- The Ampache web setup will save the configuration under the
config
directory. It will need write access to that directory:$ chmod 777 -R config
- Next, we need to configure the Apache web server, enable
mod_rewrite
, and set a virtual host pointing to the Ampache directory. - Enable
mod_rewrite
with the following command:$ sudo a2enmod rewrite
- Create a new virtual host configuration:
$ cd /etc/apache2/sites-available/ $ sudo vi ampache.conf
- Add the following lines to
ampache.conf
:<VirtualHost *:80> DocumentRoot /var/www/ampache <Directory /var/www/ampache/> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
- Now, disable any default configuration that is using port
80
, or alternatively you can use a port other than80
for Ampache installation. - Reload the Apache server for the changes to take effect:
$ sudo service apache2 reload
Here, we have installed and configured the base setup. Now, we can move on to configuration through a web-based installer. You can access the web installer at the domain name or IP address of your server. The installer should greet you with a big Ampache logo and a language selection box; something similar to the following:
- Select the language of your choice and click the Start configuration button.
- On the next page, Ampache will check all the requirements and show you a list of settings that need to be fixed. These are mostly the configuration changes and file permissions.
- Most of these requirements should already be marked with a green OK button. You need to fix things that are marked in red. The requirements screen will look as follows:
- Click the Continue button when you are done reviewing all the requirements.
- On the next page, you need to configure the MySQL settings. Fill in the necessary details and select Create Database User to create a new Ampache user under the MySQL server:
- Click Insert Database to configure database settings.
- The next screen will confirm the database settings and write the configuration changes to a file under the
config
directory. You can choose to change the installation type and enable transcoding configuration from this screen. Once done, click the Continue button to write the configuration file. If you see any errors, scroll to the bottom of the page and click the write button to write config changes. - Finally, the web setup will ask for admin account credentials for the Ampache server. The Create Admin Account form will be shown with Username and Password fields, as follows. Set the admin account username and password and click the Create Account button:
- Once the account is created, the Ampache installation script will redirect you to the web player screen. If it shows a login screen, use the admin account credentials created in the last step to log in. The landing page of the web player will be rendered as follows:
You have completed the Ampache setup process. Now you need to upload content and enjoy your own streaming server. We will learn to create a catalog and upload content in the next recipe.
How it works…
Ampache is a web application written in PHP. We have downloaded the latest Ampache code and set it to work with our web server using Virtual Host configuration. Ampache provides sample htaccess
files that set required redirection rules. We have enabled respective rules by renaming the sample files. If you are using a web server other than Apache, make sure you check the Ampache documentation for your web server. It supports Nginx and lighttpd as web servers.
Ampache has made it easy to cross-check all requirements and configure your database connection using the web installer. The installer checks for the required PHP settings and extensions and returns a simple page with things that need to fixed. Next, we can configure database settings and push schema directly from the web installer.
Once everything is configured, the web installer returns the login page, from where you can access the Ampache server.
There's more…
The Ampache community have created a Docker image for the Ampache server. If you have a Docker system set up, you can quickly get started with Ampache with its Docker image.
You can get the Dockerfile at https://github.com/ampache/ampache-docker.
Ampache is also available in the Ubuntu package repository and can be installed with the following single command:
$ sudo apt-get install ampache mysql-server-5.5
The currently available version of Ampache is 3.6. If you don't care about the latest and greatest updates, you can use the Ubuntu repository for quick and easy installation.
See also
- Ampache installation guide: https://github.com/ampache/ampache/wiki/Installation
Getting ready
We will be using Ubuntu Server 16.04, but you can choose to have any version of Ubuntu.
Additionally, we will need the Samba server. It will be used as shared network storage.
As always, access to a root account or an account with sudo
privileges will be required.
How to do it…
Ampache is a web application developed in PHP. We will start the installation with the LAMP stack. This recipe covers installation with the Apache web server, but you can choose any other web server:
- Install the LAMP stack if it's not already installed:
$ sudo apt-get update $ sudo apt-get install apache2 mysql-server-5.5 php7 \ php7-mysql php7-curl libapache2-mod-php7
Note
For more details on Apache and PHP installation, check Chapter 3, Working with Web Server
- Next, download the latest Ampache server source code. Ampache is a PHP application:
$ wget https://github.com/ampache/ampache/archive/3.8.0.tar.gz Extract achieve contents under a web root directory $ tar -xf 3.8.0.tar.gz -C /var/www $ mv /var/www/ampache-3.8.0 /var/www/ampache
- We also need to create some configuration files. You can use the default configuration that ships with the Ampache setup and rename the existing files:
$ cd /var/www/ampache $ mv rest/.htaccess.dist rest/.htaccess $ mv play/.htaccess.dist play/.htaccess $ mv channel/.htaccess.dist channel/.htaccess
- The Ampache web setup will save the configuration under the
config
directory. It will need write access to that directory:$ chmod 777 -R config
- Next, we need to configure the Apache web server, enable
mod_rewrite
, and set a virtual host pointing to the Ampache directory. - Enable
mod_rewrite
with the following command:$ sudo a2enmod rewrite
- Create a new virtual host configuration:
$ cd /etc/apache2/sites-available/ $ sudo vi ampache.conf
- Add the following lines to
ampache.conf
:<VirtualHost *:80> DocumentRoot /var/www/ampache <Directory /var/www/ampache/> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
- Now, disable any default configuration that is using port
80
, or alternatively you can use a port other than80
for Ampache installation. - Reload the Apache server for the changes to take effect:
$ sudo service apache2 reload
Here, we have installed and configured the base setup. Now, we can move on to configuration through a web-based installer. You can access the web installer at the domain name or IP address of your server. The installer should greet you with a big Ampache logo and a language selection box; something similar to the following:
- Select the language of your choice and click the Start configuration button.
- On the next page, Ampache will check all the requirements and show you a list of settings that need to be fixed. These are mostly the configuration changes and file permissions.
- Most of these requirements should already be marked with a green OK button. You need to fix things that are marked in red. The requirements screen will look as follows:
- Click the Continue button when you are done reviewing all the requirements.
- On the next page, you need to configure the MySQL settings. Fill in the necessary details and select Create Database User to create a new Ampache user under the MySQL server:
- Click Insert Database to configure database settings.
- The next screen will confirm the database settings and write the configuration changes to a file under the
config
directory. You can choose to change the installation type and enable transcoding configuration from this screen. Once done, click the Continue button to write the configuration file. If you see any errors, scroll to the bottom of the page and click the write button to write config changes. - Finally, the web setup will ask for admin account credentials for the Ampache server. The Create Admin Account form will be shown with Username and Password fields, as follows. Set the admin account username and password and click the Create Account button:
- Once the account is created, the Ampache installation script will redirect you to the web player screen. If it shows a login screen, use the admin account credentials created in the last step to log in. The landing page of the web player will be rendered as follows:
You have completed the Ampache setup process. Now you need to upload content and enjoy your own streaming server. We will learn to create a catalog and upload content in the next recipe.
How it works…
Ampache is a web application written in PHP. We have downloaded the latest Ampache code and set it to work with our web server using Virtual Host configuration. Ampache provides sample htaccess
files that set required redirection rules. We have enabled respective rules by renaming the sample files. If you are using a web server other than Apache, make sure you check the Ampache documentation for your web server. It supports Nginx and lighttpd as web servers.
Ampache has made it easy to cross-check all requirements and configure your database connection using the web installer. The installer checks for the required PHP settings and extensions and returns a simple page with things that need to fixed. Next, we can configure database settings and push schema directly from the web installer.
Once everything is configured, the web installer returns the login page, from where you can access the Ampache server.
There's more…
The Ampache community have created a Docker image for the Ampache server. If you have a Docker system set up, you can quickly get started with Ampache with its Docker image.
You can get the Dockerfile at https://github.com/ampache/ampache-docker.
Ampache is also available in the Ubuntu package repository and can be installed with the following single command:
$ sudo apt-get install ampache mysql-server-5.5
The currently available version of Ampache is 3.6. If you don't care about the latest and greatest updates, you can use the Ubuntu repository for quick and easy installation.
See also
- Ampache installation guide: https://github.com/ampache/ampache/wiki/Installation
How to do it…
Ampache is a web application developed in PHP. We will start the installation with the LAMP stack. This recipe covers installation with the Apache web server, but you can choose any other web server:
- Install the LAMP stack if it's not already installed:
$ sudo apt-get update $ sudo apt-get install apache2 mysql-server-5.5 php7 \ php7-mysql php7-curl libapache2-mod-php7
Note
For more details on Apache and PHP installation, check Chapter 3, Working with Web Server
- Next, download the latest Ampache server source code. Ampache is a PHP application:
$ wget https://github.com/ampache/ampache/archive/3.8.0.tar.gz Extract achieve contents under a web root directory $ tar -xf 3.8.0.tar.gz -C /var/www $ mv /var/www/ampache-3.8.0 /var/www/ampache
- We also need to create some configuration files. You can use the default configuration that ships with the Ampache setup and rename the existing files:
$ cd /var/www/ampache $ mv rest/.htaccess.dist rest/.htaccess $ mv play/.htaccess.dist play/.htaccess $ mv channel/.htaccess.dist channel/.htaccess
- The Ampache web setup will save the configuration under the
config
directory. It will need write access to that directory:$ chmod 777 -R config
- Next, we need to configure the Apache web server, enable
mod_rewrite
, and set a virtual host pointing to the Ampache directory. - Enable
mod_rewrite
with the following command:$ sudo a2enmod rewrite
- Create a new virtual host configuration:
$ cd /etc/apache2/sites-available/ $ sudo vi ampache.conf
- Add the following lines to
ampache.conf
:<VirtualHost *:80> DocumentRoot /var/www/ampache <Directory /var/www/ampache/> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
- Now, disable any default configuration that is using port
80
, or alternatively you can use a port other than80
for Ampache installation. - Reload the Apache server for the changes to take effect:
$ sudo service apache2 reload
Here, we have installed and configured the base setup. Now, we can move on to configuration through a web-based installer. You can access the web installer at the domain name or IP address of your server. The installer should greet you with a big Ampache logo and a language selection box; something similar to the following:
- Select the language of your choice and click the Start configuration button.
- On the next page, Ampache will check all the requirements and show you a list of settings that need to be fixed. These are mostly the configuration changes and file permissions.
- Most of these requirements should already be marked with a green OK button. You need to fix things that are marked in red. The requirements screen will look as follows:
- Click the Continue button when you are done reviewing all the requirements.
- On the next page, you need to configure the MySQL settings. Fill in the necessary details and select Create Database User to create a new Ampache user under the MySQL server:
- Click Insert Database to configure database settings.
- The next screen will confirm the database settings and write the configuration changes to a file under the
config
directory. You can choose to change the installation type and enable transcoding configuration from this screen. Once done, click the Continue button to write the configuration file. If you see any errors, scroll to the bottom of the page and click the write button to write config changes. - Finally, the web setup will ask for admin account credentials for the Ampache server. The Create Admin Account form will be shown with Username and Password fields, as follows. Set the admin account username and password and click the Create Account button:
- Once the account is created, the Ampache installation script will redirect you to the web player screen. If it shows a login screen, use the admin account credentials created in the last step to log in. The landing page of the web player will be rendered as follows:
You have completed the Ampache setup process. Now you need to upload content and enjoy your own streaming server. We will learn to create a catalog and upload content in the next recipe.
How it works…
Ampache is a web application written in PHP. We have downloaded the latest Ampache code and set it to work with our web server using Virtual Host configuration. Ampache provides sample htaccess
files that set required redirection rules. We have enabled respective rules by renaming the sample files. If you are using a web server other than Apache, make sure you check the Ampache documentation for your web server. It supports Nginx and lighttpd as web servers.
Ampache has made it easy to cross-check all requirements and configure your database connection using the web installer. The installer checks for the required PHP settings and extensions and returns a simple page with things that need to fixed. Next, we can configure database settings and push schema directly from the web installer.
Once everything is configured, the web installer returns the login page, from where you can access the Ampache server.
There's more…
The Ampache community have created a Docker image for the Ampache server. If you have a Docker system set up, you can quickly get started with Ampache with its Docker image.
You can get the Dockerfile at https://github.com/ampache/ampache-docker.
Ampache is also available in the Ubuntu package repository and can be installed with the following single command:
$ sudo apt-get install ampache mysql-server-5.5
The currently available version of Ampache is 3.6. If you don't care about the latest and greatest updates, you can use the Ubuntu repository for quick and easy installation.
See also
- Ampache installation guide: https://github.com/ampache/ampache/wiki/Installation
How it works…
Ampache is a web application written in PHP. We have downloaded the latest Ampache code and set it to work with our web server using Virtual Host configuration. Ampache provides sample htaccess
files that set required redirection rules. We have enabled respective rules by renaming the sample files. If you are using a web server other than Apache, make sure you check the Ampache documentation for your web server. It supports Nginx and lighttpd as web servers.
Ampache has made it easy to cross-check all requirements and configure your database connection using the web installer. The installer checks for the required PHP settings and extensions and returns a simple page with things that need to fixed. Next, we can configure database settings and push schema directly from the web installer.
Once everything is configured, the web installer returns the login page, from where you can access the Ampache server.
There's more…
The Ampache community have created a Docker image for the Ampache server. If you have a Docker system set up, you can quickly get started with Ampache with its Docker image.
You can get the Dockerfile at https://github.com/ampache/ampache-docker.
Ampache is also available in the Ubuntu package repository and can be installed with the following single command:
$ sudo apt-get install ampache mysql-server-5.5
The currently available version of Ampache is 3.6. If you don't care about the latest and greatest updates, you can use the Ubuntu repository for quick and easy installation.
See also
- Ampache installation guide: https://github.com/ampache/ampache/wiki/Installation
There's more…
The Ampache community have created a Docker image for the Ampache server. If you have a Docker system set up, you can quickly get started with Ampache with its Docker image.
You can get the Dockerfile at https://github.com/ampache/ampache-docker.
Ampache is also available in the Ubuntu package repository and can be installed with the following single command:
$ sudo apt-get install ampache mysql-server-5.5
The currently available version of Ampache is 3.6. If you don't care about the latest and greatest updates, you can use the Ubuntu repository for quick and easy installation.
See also
- Ampache installation guide: https://github.com/ampache/ampache/wiki/Installation
See also
- Ampache installation guide: https://github.com/ampache/ampache/wiki/Installation
Uploading contents and creating catalogs
So, we have installed the Ampache streaming server. Now, we will learn how to upload our audio/video content and create our first catalog.
Getting ready
You will need audio and video files to be uploaded on your server and enough space to save all this content. I will be using podcasts from Ubuntu podcasts in the MP3 format.
Upload all content to your Ampache server and note the directory path. I will be using the podcasts
directory under home
for my user.
Open the Ampache server homepage and log in with admin credentials.
How to do it…
Ampache provides the admin page, where you can perform all administrative tasks, such as catalogue management, user management, and other configurations. We will create a new catalogue from the admin panel and then point it to already uploaded content:
- From your Ampache homepage, click on the admin icon in the upper-left corner of the screen. This should list all administrative tools:
- Now, click on the Add a Catalog link. This should load the Add a Catalog page:
- Enter the catalog name. Use a name that describes your content. I will use
Ubuntu podcasts
. - Set the Catalog Type to
local
, as we will be loading content from your local filesystem. - Enter the path for your MP3 (or video) files,
/home/ubuntu/podcasts
in my case. - Click on the Add Catalog button. This will create a new catalog and import all content to it. The process will check for meta tags and try to collect more information about the content. It will take some time to process all the files and add details to the Ampache database:
- Finally, click Continue to complete catalog creation and go to the catalog list:
- Once catalog creation is complete, you can go to the homepage by clicking the home icon (first) in the upper-left of the screen and then clicking on the song title link. This should list all the files available under your catalog directory:
- From this song list, you can play songs/podcasts, add or remove ratings, add them to playlists, and more:
How it works…
Catalog creation simply reads the content from the upload directory and adds the respective details to the MySQL database. The process tries to gather more details about content using information collected from meta tags and track titles or file names. This information is then used to group the content by artist and album. Note that Ampache is not tagging software where you upload random content and receive a well-organized media library. For Ampache to work well, you need to have properly tagged and well-organized content.
Getting ready
You will need audio and video files to be uploaded on your server and enough space to save all this content. I will be using podcasts from Ubuntu podcasts in the MP3 format.
Upload all content to your Ampache server and note the directory path. I will be using the podcasts
directory under home
for my user.
Open the Ampache server homepage and log in with admin credentials.
How to do it…
Ampache provides the admin page, where you can perform all administrative tasks, such as catalogue management, user management, and other configurations. We will create a new catalogue from the admin panel and then point it to already uploaded content:
- From your Ampache homepage, click on the admin icon in the upper-left corner of the screen. This should list all administrative tools:
- Now, click on the Add a Catalog link. This should load the Add a Catalog page:
- Enter the catalog name. Use a name that describes your content. I will use
Ubuntu podcasts
. - Set the Catalog Type to
local
, as we will be loading content from your local filesystem. - Enter the path for your MP3 (or video) files,
/home/ubuntu/podcasts
in my case. - Click on the Add Catalog button. This will create a new catalog and import all content to it. The process will check for meta tags and try to collect more information about the content. It will take some time to process all the files and add details to the Ampache database:
- Finally, click Continue to complete catalog creation and go to the catalog list:
- Once catalog creation is complete, you can go to the homepage by clicking the home icon (first) in the upper-left of the screen and then clicking on the song title link. This should list all the files available under your catalog directory:
- From this song list, you can play songs/podcasts, add or remove ratings, add them to playlists, and more:
How it works…
Catalog creation simply reads the content from the upload directory and adds the respective details to the MySQL database. The process tries to gather more details about content using information collected from meta tags and track titles or file names. This information is then used to group the content by artist and album. Note that Ampache is not tagging software where you upload random content and receive a well-organized media library. For Ampache to work well, you need to have properly tagged and well-organized content.
How to do it…
Ampache provides the admin page, where you can perform all administrative tasks, such as catalogue management, user management, and other configurations. We will create a new catalogue from the admin panel and then point it to already uploaded content:
- From your Ampache homepage, click on the admin icon in the upper-left corner of the screen. This should list all administrative tools:
- Now, click on the Add a Catalog link. This should load the Add a Catalog page:
- Enter the catalog name. Use a name that describes your content. I will use
Ubuntu podcasts
. - Set the Catalog Type to
local
, as we will be loading content from your local filesystem. - Enter the path for your MP3 (or video) files,
/home/ubuntu/podcasts
in my case. - Click on the Add Catalog button. This will create a new catalog and import all content to it. The process will check for meta tags and try to collect more information about the content. It will take some time to process all the files and add details to the Ampache database:
- Finally, click Continue to complete catalog creation and go to the catalog list:
- Once catalog creation is complete, you can go to the homepage by clicking the home icon (first) in the upper-left of the screen and then clicking on the song title link. This should list all the files available under your catalog directory:
- From this song list, you can play songs/podcasts, add or remove ratings, add them to playlists, and more:
How it works…
Catalog creation simply reads the content from the upload directory and adds the respective details to the MySQL database. The process tries to gather more details about content using information collected from meta tags and track titles or file names. This information is then used to group the content by artist and album. Note that Ampache is not tagging software where you upload random content and receive a well-organized media library. For Ampache to work well, you need to have properly tagged and well-organized content.
How it works…
Catalog creation simply reads the content from the upload directory and adds the respective details to the MySQL database. The process tries to gather more details about content using information collected from meta tags and track titles or file names. This information is then used to group the content by artist and album. Note that Ampache is not tagging software where you upload random content and receive a well-organized media library. For Ampache to work well, you need to have properly tagged and well-organized content.
Setting on-the-fly transcoding
Transcoding means converting media from one format to another. Suppose your music files are in a format different to MP3 and your media player only understands MP3 format. In that case, you need to convert your music files to MP3. This conversion task is done by transcoder programs. There are various transcoding programs available, such as ffmpeg
and avconv
. These programs need codec before they can convert media from source format to destination format. We need to separately install and configure these components.
Ampache supports on-the-fly transcoding of media files. That is, your music that is not in an MP3 format can be converted into the MP3 format just before it is delivered to your music player, and your high definition video content can be optimized for mobile consumption to reduce bandwidth use.
In this recipe, we will learn how to install and configure transcoding programs with Ampache.
Getting ready
Make sure you have working a setup of the Ampache server.
You will need access to a root account or an account with root privileges.
How to do it…
Ampache depends on external libraries for transcoding to work. We will first install the dependencies and then configure Ampache to work with them:
- First, add the
ffmpeg
PPA to the Ubuntu installation sources:$ sudo apt-add-repository ppa:mc3man/trusty-media $ sudo apt-get update
- Now, install
ffmpeg
and other required codecs:$ sudo apt-get install flac mp3splt lame faad ffmpeg vorbis-tools
- Next, we need to configure Ampache and enable transcoding. Open the configuration file located at
/var/www/ampache/config/ampache.cfg.php
, find the following lines in the file, and uncomment them:max_bit_rate = 576 min_bit_rate = 48 transcode_flac = required transcode_mp3 = allowed encode_target = mp3 transcode_cmd = "ffmpeg"
Here, we have set
ffmpeg
for the encoding/decoding of media files. You can choose any encoder of your choice. Change the value oftranscode_cmd
respectively. - Next, enable debug mode to get details of the transcoding. Find the debug section in the configuration file and set it as follows:
debug = true Enable log file path which is, by default, set to null log_path = "/var/log/ampache"
- Save the changes to the configuration file and reload the Apache web server:
$ sudo service apache2 reload
Now your transcoding setup should be working. You should be able to upload media in a different format and play it as MP3 or other respective formats.
It often happens that we have content in a format that is not supported by the device we are using for playback. Maybe the device does not have the required codec or the hardware is not capable of playing a high bit rate. We may even need to convert content to a lower bit rate and reduce the bandwidth used to stream. The transcoding feature of Ampache helps us to cover these scenarios.
With transcoding, you can convert the content to the desired device-supported format before actually starting the streaming. This is called on-the-fly transcoding. The contents are encoded in a new format as and when needed. Once the conversion is completed, the new format can be cached for repeat use. In the above example, we set Ampache to convert FLAC files to MP3 using the ffmpeg tool. Now whenever we request a file that is originally available in the FLAC format, Ampache will convert it to MP3 before streaming it to our device.
Ampache uses external, well-established media conversion tools for transcoding. Any tool that works with the Ubuntu command line can be configured to work with Ampache. Refer to the Ampache configuration file to get more details and configuration examples.
Getting ready
Make sure you have working a setup of the Ampache server.
You will need access to a root account or an account with root privileges.
How to do it…
Ampache depends on external libraries for transcoding to work. We will first install the dependencies and then configure Ampache to work with them:
- First, add the
ffmpeg
PPA to the Ubuntu installation sources:$ sudo apt-add-repository ppa:mc3man/trusty-media $ sudo apt-get update
- Now, install
ffmpeg
and other required codecs:$ sudo apt-get install flac mp3splt lame faad ffmpeg vorbis-tools
- Next, we need to configure Ampache and enable transcoding. Open the configuration file located at
/var/www/ampache/config/ampache.cfg.php
, find the following lines in the file, and uncomment them:max_bit_rate = 576 min_bit_rate = 48 transcode_flac = required transcode_mp3 = allowed encode_target = mp3 transcode_cmd = "ffmpeg"
Here, we have set
ffmpeg
for the encoding/decoding of media files. You can choose any encoder of your choice. Change the value oftranscode_cmd
respectively. - Next, enable debug mode to get details of the transcoding. Find the debug section in the configuration file and set it as follows:
debug = true Enable log file path which is, by default, set to null log_path = "/var/log/ampache"
- Save the changes to the configuration file and reload the Apache web server:
$ sudo service apache2 reload
Now your transcoding setup should be working. You should be able to upload media in a different format and play it as MP3 or other respective formats.
It often happens that we have content in a format that is not supported by the device we are using for playback. Maybe the device does not have the required codec or the hardware is not capable of playing a high bit rate. We may even need to convert content to a lower bit rate and reduce the bandwidth used to stream. The transcoding feature of Ampache helps us to cover these scenarios.
With transcoding, you can convert the content to the desired device-supported format before actually starting the streaming. This is called on-the-fly transcoding. The contents are encoded in a new format as and when needed. Once the conversion is completed, the new format can be cached for repeat use. In the above example, we set Ampache to convert FLAC files to MP3 using the ffmpeg tool. Now whenever we request a file that is originally available in the FLAC format, Ampache will convert it to MP3 before streaming it to our device.
Ampache uses external, well-established media conversion tools for transcoding. Any tool that works with the Ubuntu command line can be configured to work with Ampache. Refer to the Ampache configuration file to get more details and configuration examples.
How to do it…
Ampache depends on external libraries for transcoding to work. We will first install the dependencies and then configure Ampache to work with them:
- First, add the
ffmpeg
PPA to the Ubuntu installation sources:$ sudo apt-add-repository ppa:mc3man/trusty-media $ sudo apt-get update
- Now, install
ffmpeg
and other required codecs:$ sudo apt-get install flac mp3splt lame faad ffmpeg vorbis-tools
- Next, we need to configure Ampache and enable transcoding. Open the configuration file located at
/var/www/ampache/config/ampache.cfg.php
, find the following lines in the file, and uncomment them:max_bit_rate = 576 min_bit_rate = 48 transcode_flac = required transcode_mp3 = allowed encode_target = mp3 transcode_cmd = "ffmpeg"
Here, we have set
ffmpeg
for the encoding/decoding of media files. You can choose any encoder of your choice. Change the value oftranscode_cmd
respectively. - Next, enable debug mode to get details of the transcoding. Find the debug section in the configuration file and set it as follows:
debug = true Enable log file path which is, by default, set to null log_path = "/var/log/ampache"
- Save the changes to the configuration file and reload the Apache web server:
$ sudo service apache2 reload
Now your transcoding setup should be working. You should be able to upload media in a different format and play it as MP3 or other respective formats.
It often happens that we have content in a format that is not supported by the device we are using for playback. Maybe the device does not have the required codec or the hardware is not capable of playing a high bit rate. We may even need to convert content to a lower bit rate and reduce the bandwidth used to stream. The transcoding feature of Ampache helps us to cover these scenarios.
With transcoding, you can convert the content to the desired device-supported format before actually starting the streaming. This is called on-the-fly transcoding. The contents are encoded in a new format as and when needed. Once the conversion is completed, the new format can be cached for repeat use. In the above example, we set Ampache to convert FLAC files to MP3 using the ffmpeg tool. Now whenever we request a file that is originally available in the FLAC format, Ampache will convert it to MP3 before streaming it to our device.
Ampache uses external, well-established media conversion tools for transcoding. Any tool that works with the Ubuntu command line can be configured to work with Ampache. Refer to the Ampache configuration file to get more details and configuration examples.
Enabling API access for remote streaming
A streaming client needs to get the details of the media available on the streaming server. The client needs to authenticate with server access the catalog and list of songs and even request offline access to store media locally. With Ampache, we can use its REST and XML APIs. Through these APIs, clients can communicate with Ampache. You can even write your own client tool using any of the supported APIs.
This recipe covers the setup process for streaming content to remote devices. As of writing this, Ampache allows all users to use all available APIs. We will learn how to modify this setting and configure it to limit access based on user accounts.
Getting ready
Open Ampache in your browser and log in with admin credentials.
How to do it…
We will create a separate user account for remote streaming. From the Ampache homepage, click on the admin icon in the top-left corner and then click on the Add User link from the User Tools section. An add user menu will be shown that looks like this:
- Fill in the Username, E-mail, and Password fields for the new user account and set User Access to
User
. - Click the Add User button to create this user and then click Continue.
- We will use this new user account to log in from the remote client.
- Next, we need to configure access rights and allow this user to use APIs to stream music.
- Click on the admin icon and then click on the Add ACL link under the Access Control section.
- Set the name for this access control list.
- Set level to Read/Write.
- Set the user to the user account created in the previous step.
- Set ACL type to
Stream Access
. - Set the start and end IP addresses to
0.0.0.0
and255.255.255.255
respectively. - Click Create ACL to save the settings.
- Click on the Add ACL link again and repeat the preceding settings, except, for ACL Type that choose
API/RPC
. - Now you can use Ampache streaming from your mobile client. When asked for your username and password, use our new user account, and for the streaming server URL, use your Ampache FQDN followed by
/ampache
, for example:http://myampachehost.com/ampache
- If your client needs an API key, you can generate one from the User Tools section.
- Click on the Browse Users link and then select the user account in question. Click the edit icon to update user details and then click on the generate API key icon.
- Finally, click the Update User button to save your changes.
How it works…
By default, the Ampache server creates an Access Control List that allows all access to all users. It is a good idea to create a separate user and grant only the required permissions. Here, we have created a new user account with access to the REST API and to stream content. This will allow better control over users and content, as well as allow us to set various user-specific default settings, such as default bitrate and encoding formats.
Getting ready
Open Ampache in your browser and log in with admin credentials.
How to do it…
We will create a separate user account for remote streaming. From the Ampache homepage, click on the admin icon in the top-left corner and then click on the Add User link from the User Tools section. An add user menu will be shown that looks like this:
- Fill in the Username, E-mail, and Password fields for the new user account and set User Access to
User
. - Click the Add User button to create this user and then click Continue.
- We will use this new user account to log in from the remote client.
- Next, we need to configure access rights and allow this user to use APIs to stream music.
- Click on the admin icon and then click on the Add ACL link under the Access Control section.
- Set the name for this access control list.
- Set level to Read/Write.
- Set the user to the user account created in the previous step.
- Set ACL type to
Stream Access
. - Set the start and end IP addresses to
0.0.0.0
and255.255.255.255
respectively. - Click Create ACL to save the settings.
- Click on the Add ACL link again and repeat the preceding settings, except, for ACL Type that choose
API/RPC
. - Now you can use Ampache streaming from your mobile client. When asked for your username and password, use our new user account, and for the streaming server URL, use your Ampache FQDN followed by
/ampache
, for example:http://myampachehost.com/ampache
- If your client needs an API key, you can generate one from the User Tools section.
- Click on the Browse Users link and then select the user account in question. Click the edit icon to update user details and then click on the generate API key icon.
- Finally, click the Update User button to save your changes.
How it works…
By default, the Ampache server creates an Access Control List that allows all access to all users. It is a good idea to create a separate user and grant only the required permissions. Here, we have created a new user account with access to the REST API and to stream content. This will allow better control over users and content, as well as allow us to set various user-specific default settings, such as default bitrate and encoding formats.
How to do it…
We will create a separate user account for remote streaming. From the Ampache homepage, click on the admin icon in the top-left corner and then click on the Add User link from the User Tools section. An add user menu will be shown that looks like this:
- Fill in the Username, E-mail, and Password fields for the new user account and set User Access to
User
. - Click the Add User button to create this user and then click Continue.
- We will use this new user account to log in from the remote client.
- Next, we need to configure access rights and allow this user to use APIs to stream music.
- Click on the admin icon and then click on the Add ACL link under the Access Control section.
- Set the name for this access control list.
- Set level to Read/Write.
- Set the user to the user account created in the previous step.
- Set ACL type to
Stream Access
. - Set the start and end IP addresses to
0.0.0.0
and255.255.255.255
respectively. - Click Create ACL to save the settings.
- Click on the Add ACL link again and repeat the preceding settings, except, for ACL Type that choose
API/RPC
. - Now you can use Ampache streaming from your mobile client. When asked for your username and password, use our new user account, and for the streaming server URL, use your Ampache FQDN followed by
/ampache
, for example:http://myampachehost.com/ampache
- If your client needs an API key, you can generate one from the User Tools section.
- Click on the Browse Users link and then select the user account in question. Click the edit icon to update user details and then click on the generate API key icon.
- Finally, click the Update User button to save your changes.
How it works…
By default, the Ampache server creates an Access Control List that allows all access to all users. It is a good idea to create a separate user and grant only the required permissions. Here, we have created a new user account with access to the REST API and to stream content. This will allow better control over users and content, as well as allow us to set various user-specific default settings, such as default bitrate and encoding formats.
How it works…
By default, the Ampache server creates an Access Control List that allows all access to all users. It is a good idea to create a separate user and grant only the required permissions. Here, we have created a new user account with access to the REST API and to stream content. This will allow better control over users and content, as well as allow us to set various user-specific default settings, such as default bitrate and encoding formats.
Streaming music with Ampache
We have set up the Ampache server and configured it for streaming. In this recipe, we will learn how to set up an Android client to play content from our Ampache server.
Getting ready
You will need an Android or iOS phone or tablet. We will focus on the configuration of an Android client, but the same configuration should work with an iOS device, and even desktop clients such as VLC.
How to do it…
Follow these steps to stream music with Ampache:
- First, install Just Player on your Android device. It is an Ampache client and uses XML APIs to stream content from Ampache. It is available from the Play Store.
- Once installed, open the settings of Just Player and search for Ampache under cloud player.
- We need to add our Ampache server details here. Enter the server URL as the domain name or IP address of your Ampache server and append
/ampache
at the end, for example:http://myampacheserver.com/ampache
- Next, enter the username and password in their respective fields. You can use the user account created in the last recipe.
- Click Check to confirm the settings and then save.
Now you should be able to access your Ampache songs on your Android device or phone.
Getting ready
You will need an Android or iOS phone or tablet. We will focus on the configuration of an Android client, but the same configuration should work with an iOS device, and even desktop clients such as VLC.
How to do it…
Follow these steps to stream music with Ampache:
- First, install Just Player on your Android device. It is an Ampache client and uses XML APIs to stream content from Ampache. It is available from the Play Store.
- Once installed, open the settings of Just Player and search for Ampache under cloud player.
- We need to add our Ampache server details here. Enter the server URL as the domain name or IP address of your Ampache server and append
/ampache
at the end, for example:http://myampacheserver.com/ampache
- Next, enter the username and password in their respective fields. You can use the user account created in the last recipe.
- Click Check to confirm the settings and then save.
Now you should be able to access your Ampache songs on your Android device or phone.
How to do it…
Follow these steps to stream music with Ampache:
- First, install Just Player on your Android device. It is an Ampache client and uses XML APIs to stream content from Ampache. It is available from the Play Store.
- Once installed, open the settings of Just Player and search for Ampache under cloud player.
- We need to add our Ampache server details here. Enter the server URL as the domain name or IP address of your Ampache server and append
/ampache
at the end, for example:http://myampacheserver.com/ampache
- Next, enter the username and password in their respective fields. You can use the user account created in the last recipe.
- Click Check to confirm the settings and then save.
Now you should be able to access your Ampache songs on your Android device or phone.