Multimedia https://tech.feedyourhead.at/ en HackADay: Listening to Spotify on my Pi using A2DP https://tech.feedyourhead.at/content/HackADay-Listening-to-Spotify-on-my-Pi-using-A2DP <span class="field field--name-title field--type-string field--label-hidden">HackADay: Listening to Spotify on my Pi using A2DP</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><img alt="Raspberry Pi Logo" data-entity-type="file" data-entity-uuid="2aa4f80c-e0f3-4a34-8bce-f27689f8d5f5" height="504" src="/sites/default/files/inline-images/raspberry-pi-logo.png" width="401" /></p> <p>I installed  <a href="http://raspbian.org/">Raspbian(Debian Jessie)</a> with <a href="https://kodi.tv/">Kodi</a> on my <a href="https://www.raspberrypi.org/">Raspberry Pi</a> and I use my Pi as a Meda Center. This Media Center plays music, mostly radio stations, all day long. I can easily control this media-center using the <a href="http://yatse.tv/redmine/projects/yatse">Yatse-App</a> on my phone. The Setup is almost perfect, but just almost. Sometimes I prefer to listen to my <a href="https://www.spotify.com">Spotify</a>-Playlists. At the moment there are no really good music addons for that. So I came to the idea to pair my phone via bluetooth with my Pi and use the audio output of my phone to play the Spotify-playlists.</p> <h3>Requirements</h3> <ul><li>Raspberry Pi Model 3(All the others don't have a builtin bluetooth)</li> <li>Headset/Speaker</li> <li>Pulseaudio (Sound-Daemon)</li> <li>Bluez(Bluetooth-Stack)</li> </ul><h3>Installing the needed packages</h3> <pre> <code>apt-get update apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluez-tools </code></pre> <h3>Configuring Bluetooth</h3> <p>To enable all the bluetooth audio commands we have to add the following lines in the [General]-section of /etc/bluetooth/main.conf:</p> <pre> <code>Enable=Source,Sink,Media </code></pre> <p>Next we have to change the bluetooth-class:</p> <pre> <code>Class = 0x00041C </code></pre> <p>Now we have all the audio-functions we need for our bluetooth-stack. So let's pair the phone with our raspberry. Just call bluetoothctl and use the following commands:</p> <pre> <code> scan on trust xx:xx:xx:xx:xx:xx(phone bluetooth mac) connect xx:xx:xx:xx:xx:xx(phone bluetooth mac) </code></pre> <p>To exit bluetoothctl we can hit CTRL+D. Now our phone is paired and ready to rock.</p> <h3>Setup the Audio-Connection</h3> <p>When the phone connects via bluetooth, a few commands are necessary to rock the house. One of those commands are connecting the right bluetooth-audio-source to the right audio-output-device. Fist we start as user pi the pulseaudio-daemon:</p> <pre> <code>pi@raspberrypi:~ $ pulseaudio --start </code></pre> <p>Next we can check the audio-devices:</p> <pre> <code>pi@raspberrypi:~ $ pactl list sources short 0 alsa_output.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 48000Hz IDLE 1 bluez_source.84_CF_BF_89_47_01 module-bluez5-device.c s16le 2ch 48000Hz RUNNING </code></pre> <p>The output might differ, since in this example my phone is already playing music via the raspberry pi ;) To list only all the sinks we can use this command:</p> <pre> <code>pi@raspberrypi:~ $ pactl list sinks short 0 alsa_output.0.analog-stereo module-alsa-card.c s16le 2ch 48000Hz RUNNING </code></pre> <p>So now we know the input-device, and the output device and can connect it properly. When we do that, we also have to make sure that the audio volume is set correctly. We can do all this automatically as soon as we connect our phone to the pi. We will use a udev-rule to achieve this. So let's create the file /etc/udev/rules.d/99-input.rules with the following content:</p> <pre> <code>KERNEL=="input[0-9]*", RUN+="/home/pi/a2dp-autoconnect" </code></pre> <p>The file /home/pi/a2dp-autoconnect looks like that:</p> <pre> <code> #!/bin/bash # The original script: http://blog.mrverrall.co.uk/2013/01/raspberry-pi-a2dp-bluetooth-audio.html. # Find the right sink with `pactl list sources short`. PA_SINK="alsa_output.0.analog-stereo" BT_MAC=$(echo "$NAME" | sed 's/:/_/g' | sed 's/\"//g') BT_USER=pi sudo su - "$BT_USER" -c "pulseaudio -D" function log { echo "[$(date)]: $*" &gt;&gt; /var/log/a2dp-autoconnect } function checkSource { # Get the current sources local _sources=$(sudo su - "$BT_USER" -c "pactl list sources short") # Check if any sources are currently running and that our new device is valid. if [[ "$_sources" =~ RUNIING ]]; then log "Source is already RUNNING. Available sources:" log "$_sources" return fi if [[ ! "$_sources" =~ "$1" ]] ; then log "Unrecognized source. Available sources:" log "\n$_sources" return fi log "Validated new source: $1." echo "$1" } function setVolume { log "Setting volume levels." # Set our volume to max sudo su - "$BT_USER" -c "pacmd set-sink-volume 0 65537" sudo su - "$BT_USER" -c "amixer set Master 100%" } function connect { log "Connecting $1." # Connect source to sink sudo su - "$BT_USER" -c 'pactl load-module module-loopback source="$1" sink="$PA_SINK" rate=44100 adjust_time=0' } log "Change for device $BT_MAC detected, running $ACTION." if [ "$ACTION" = "add" ] then incoming=bluez_source."$BT_MAC" if [ ! -z $(checkSource "$incoming") ] ; then connect "$incoming" setVolume fi fi </code></pre> <p>I borrowed this file from <a href="https://gist.github.com/oleq/24e09112b07464acbda1">here</a> but I modified it so that it automatically starts pulseaudio. Next we have to change the permissions:</p> <pre> <code> pi@raspberrypi:~ $ chmod +x a2dp-autoconnect </code></pre> <h3>Let's Rock The House</h3> <p>So finally we can rock the house. As soon as I start Spotify on the phone I can listen to it but I can also easily stop the music and play all my favourite radio stations using Kodi.</p> <p> </p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Oct 28 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/raspberry" hreflang="en">Raspberry</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/multimedia" hreflang="en">Multimedia</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <div class="node__links"> <ul class="links inline"><li class="comment-add"><a href="/content/HackADay-Listening-to-Spotify-on-my-Pi-using-A2DP#comment-form" title="Share your thoughts and opinions." hreflang="en">Add new comment</a></li></ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title">Comments</h2> <article data-comment-user-id="0" id="comment-87" about="/comment/87" typeof="schema:Comment" class="comment js-comment by-anonymous"> <mark class="hidden" data-comment-timestamp="1525519458"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/user/0" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" typeof="schema:Person" property="schema:name" datatype="">ofus (not verified)</span> on May 02 2018</span> <span property="schema:dateCreated" content="2018-05-01T22:23:10+00:00" class="rdf-meta hidden"></span> </p> <a href="/comment/87#comment-87" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/87#comment-87" class="permalink" rel="bookmark" hreflang="en">non-SBC codecs</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Is it possible to use a higher quality audio codec than SBC, or enable maximum quality SBC (375 kbit/s)?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=87&amp;1=default&amp;2=en&amp;3=" token="Hic7uc9cyGcu8Emgc0pmLRpfxlu285eDB1WO9UqzIwY"></drupal-render-placeholder> </div> </article> <article data-comment-user-id="1" id="comment-88" about="/comment/88" typeof="schema:Comment" class="comment js-comment by-node-author"> <mark class="hidden" data-comment-timestamp="1525521093"></mark> <footer class="comment__meta"> <article typeof="schema:Person" about="/users/hoti" class="profile"> </article> <p class="comment__submitted"><span rel="schema:author">Submitted by <span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span> on May 05 2018</span> <span property="schema:dateCreated" content="2018-05-05T11:51:33+00:00" class="rdf-meta hidden"></span> </p> <a href="/comment/88#comment-88" hreflang="en">Permalink</a> </footer> <div class="content"> <h3 property="schema:name" datatype=""><a href="/comment/88#comment-88" class="permalink" rel="bookmark" hreflang="en">I found the following codecs…</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item">I found the following codecs in the sources of bluez: #define A2DP_CODEC_SBC 0x00 #define A2DP_CODEC_MPEG12 0x01 #define A2DP_CODEC_MPEG24 0x02 #define A2DP_CODEC_ATRAC 0x03 but I am not sure if pulseaudio supports any other codec than sbc. If you really wanna know, ask at the pulseaudio-mailinglist</div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=88&amp;1=default&amp;2=en&amp;3=" token="yNROpDxHetycA7X96bZ0aaei_TH6OlLk12xsiZxQxwI"></drupal-render-placeholder> </div> </article> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=212&amp;2=comment&amp;3=comment" token="21QyDjuz5iPBmhAfIRELqPXyoUz65_ZOQhGaaKlrOes"></drupal-render-placeholder> </section> Fri, 28 Oct 2016 12:52:36 +0000 Hoti 212 at https://tech.feedyourhead.at Preparing video's for the web(using ffmpeg) https://tech.feedyourhead.at/node/146 <span class="field field--name-title field--type-string field--label-hidden">Preparing video&#039;s for the web(using ffmpeg)</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>Convert video to different formats:</h3> <p>Mp4 (H.264 / ACC):</p> <pre> <code>ffmpeg -i INPUTFILE -b 1500k -vcodec libx264 -vpre slow -vpre baseline -g 30 "OUTPUTFILE.mp4</code></pre> <p>Webm (VP8 / Vorbis):</p> <pre> <code>ffmpeg -i "INPUTFILE" -b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30 "OUTPUTFILE.webm"</code></pre> <p>Ogv (Theora / Vorbis):</p> <pre> <code>ffmpeg -i "INPUTFILE" -b 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30 "OUTPUTFILE.ogv"</code></pre> <h3>Rotate video 90 clockwise:</h3> <pre> <code>ffmpeg -i INPUTFILE.ogv -vf "transpose=1" -b 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30 "OUTPUTFILE.ogv"</code></pre> <h3>Remove sound from video:</h3> <pre> <code>ffmpeg -i INPUTFILE.ogv -c copy -an OUTPUTFILE.ogv</code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jan 15 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/multimedia" hreflang="en">Multimedia</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=146&amp;2=comment&amp;3=comment" token="AdiB7qpCr-cJqVv_Pyj5A_P7VztIMRZb41Piolka_uQ"></drupal-render-placeholder> </section> Fri, 15 Jan 2016 21:53:25 +0000 Hoti 146 at https://tech.feedyourhead.at Useful Command-Line-Tools: CMUS https://tech.feedyourhead.at/content/useful-command-line-tools-cmus <span class="field field--name-title field--type-string field--label-hidden">Useful Command-Line-Tools: CMUS</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><a href="https://cmus.github.io/"><img alt="" src="https://cmus.github.io/cmus-2.4.3-osx.png" /></a></p> <p>&nbsp;</p> <p>I always used the audio-player XMMS. When the developers stopped working on it, I was a bit lost. Most of the other players just have too many features I don't want(like a database). I need a small, customizable audio-player. So I am very glad that I found <a href="https://cmus.github.io/">CMUS</a>, which is exactly what I needed. I really recommend to have a look at it..</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mar 23 2015</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/cli" hreflang="en">CLI</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/multimedia" hreflang="en">Multimedia</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=66&amp;2=comment&amp;3=comment" token="rupWV-WO5c8lSRBR5fm_KWTKp3dZs97hzpseyMXKC4g"></drupal-render-placeholder> </section> Mon, 23 Mar 2015 14:11:00 +0000 Hoti 66 at https://tech.feedyourhead.at