NOTE: This will only work with Facebook Pages, it will not work for your own personal Facebook feed as Facebook does not allow API access to users currently. You’ll get an error if you try.

In my endeavors to make my #PiCam more useful, I wanted to see if I could make it connect and stream to Facebook Live automagically. Why you ask? Well simple, because I’d like to use the #PiCam to stream to something more than just Chew.TV or YouTube. What if I wanted to load up the #PiCam as a live event stream, etc. Honestly the #PiCam can be amazingly useful. So why automate it to connect to Facebook Live? Because I wanted to see if it could be done for cheaper than the MeVo by Livestream. You see, the MeVo is a camera by livestream that will stream to LiveStream, Facebook Live, and Twitter/Periscope. The catch? They want you to spend $400 on it. While I admit, their app looks pretty sweet in setting up multiple shots from the one wide-angle camera feed, it is iOS only. And I’m, at the very least, not an Apple fan

So, can you setup a Raspberry Pi to be able to automatically stream to Facebook? Yes… with a bit of magic. So let’s begin.

First, I making the assumption you’ve viewed and followed the guides to setup your basic #PiCam ( 1, 2, 3 ). Similar to the Chew.TV automation guide we can accomplish what we want with a little bit of PHP and some bash scripting.

At first, I was going to try to use the Facebook PHP-SDK and build it around that.. but that just seemed… excessive. I mean, we can already make calls to a restful api, we did that with the ChewCam. So with a little adaptation, and some finesse. I was able to generate a working prototype to share with you.

Get Your Facebook Page Access Token

The first step is to get your Facebook Page access token. So far, unfortunately you’ll need to have a Facebook app created to do this, even if you don’t do anything with it. I tried using the Graph API Explorer using the user token, but it errors out consistently. Once I switched from the user token to an app token, as is shown in the official Facebook Live API Quick Start Guide, things went smoothly. I’m not going to walk you through setting up a Facebook app, you can Google that yourself. So what am I going to show you here? How to get your access token so you can do the #PiCam magic. So go create your Facebook app, then come back here.

Step 1

Navigate your favorite web browser to the Graph API Explorer. In the area I circled in the screenshot below, change from Graph API Explorer to the FBapp you just created.

Step 2

Once you’ve changed to your new application, click the get token, then select “Get Page Access Token”. This will generate a token into the access token field.

Step 3

After you’ve generated your Page Access Token, click the “Get Token” drop down again and select the page you want to publish your live video to. In this case I’ve chosen Mikey Malone. Copy and paste the token somewhere safe, or simply leave this open in a tab if you want and we’ll go on to the next part of the automation steps. You’ll also want to write down the ID that is returned. It is your Page ID, which you’ll need for your POST API call.

Step 4

Scripting for Automation

PHP Page

Now we get to the scripting parts. First, we’re going to build a simple PHP page that will make a POST request to the Facebook Graph. Open your favorite editor and create your page. For simplicity, I’ve named my php page “facebook.php”.

nano facebook.php

Now in your editor, paste the following. Note where it says “{YOUR_ACCESS_TOKEN_GOES_HERE}” replace that with your actual access token that you just generated. This makes a POST request, which if you’ve properly generated your access_token, will retrieve a JSON response from the Facbeook Graph, it then turns it into an array object so we can pull the stream_url from the JSON, and then it outputs it with the echo command. This is necessary to pass the stream_url on to the bash script we will make. Also you’ll need to substitute the Page ID you made not of for {PAGE_ID}.

Bash Script

Now we’ll create a bash script that will process the PHP script, store the returned URL in a variable, then launch GStreamer to begin streaming automatically to Facebook Live on the Facebook page you set this up for. In your favorite editor, create a shell script. I named mine fbstart.sh, but you can name it whatever.

Line 1: declares the shell script processor.
Line 2: Sets the bash script variable, in this case called “url” to equal the results of the command executed, php /home/pi/facebook.php
Line 3: This line should look familiar to you! Yes! It’s our old friend Gstreamer launching. However, you’ll notice there’s a few changes. First, the output format is changed to fit the maximum specs supported by FB Live. According to the document I just linked, the current max video specs are 720p video at 30FPS. This may change, however I just set this to the specs provided in the document.

The other change to the gstreamer launch line is with the rtmpsing location="$url" portion. In the other steps, you’d normally have your RTMP url there, however since you don’t know the URL, you can’t set it. Hence why we went thru these automation steps. The facebook.php page connects to the Graph, gets the rtmp url, then echoes it out. The bash script captures it in the $url variable, then passes the $url variable to the gstreamer command.

Save this shell script and exit to your command line.

Allow Execution

Now, you’ll need to give the shell script execute permissions so you can run it stand-alone:

chmod +x fbstart.sh

Now you should be ready to go!

Using your new #PiCam with Facebook Live

If you’ve followed all the steps from the previous guides and setup your #PiCam, and then done the above, you simply have to start the stream to go live!

./fbstart.sh

You should see the familiar Gstreamer output. To end your output Ctrl+C and it will end publishing the video.

BONUS

As an aside, the access_token you generate is a temporary access code that expires after 24hours. Facebook does offer longer duration access_tokens but you have to do a bit of work for them. Instead of trying to recreate the wheel, I’ll simply link you to this awesome StackOverflow on the subject: click here

I make no guarantees that it will always work, but it works for now. You can extend it to two months by generating a long_lived_access_token, or even set it to expire never. Doing the never_expire step will require to regenerate your access token if you want to revoke that later.

Also, with a bit of setup, you could manage this to run automatically once powered on. Once again, I won’t be doing this, but the option is there.

ENJOY!

Ok, so you’ve got it setup, you’re rocking a new PiCam incorporated into your home/studio streaming option. So what now? Enjoy it! If you enjoyed it and want to support other guides like this, feel free to donate to motivate for other solutions etc!

So if you’ve read any of my Chew/PiCam guides (part 1, part 2 and part 3), you’ll know I’m pretty happy with the Chew/PiCam setup. Overall, it’s my goto option when attempting to stream (or record) when at a gig or out in the field. Powered by a nice steady power bank (Anker 20000mah) I can run the PiCam nonstop for any endeavors I’ve tried.

Though when I’m not in the field or at a gig, I yearned for a way to incorporate the PiCam into my normal OBS setup. Unfortunately, you cannot simply plug in the Pi to your computer via USB and have it act as a webcam… At least not that I’ve found a way to do

So, how can you incorporate it? I looked at quite a few options. I currently run two webcams, and was looking to add the Pi to the suare of cameras. So whatever method I chose, it had to be low-latency so it looked in time with the other webcams that were connected directly to the computer. My first attempt involved nginx-rtmp and pulling the feed from that. While it worked, the latency was insane at times… well not insane, but not nearly as low as I’d liked it to be. What would happen on the webcams would sometimes show up on the PiCam feed 10 seconds later. For a live streaming gig, definitely not ideal.

My second attempt was to setup an IP Webcam on it. This worked well setting up thanks to the Pi community and people who’ve honed the setup down to a science. Unfortunately, it too suffered from latency as well as low frame-rate. However, if you’re looking for a home-security style setup then I highly suggest this setup. (Raspberry Pi IP Camera)

I had about given up when I stumbled across some posts on the Pi forums discussing using netcat and piping it thru mplayer. I did not hold my breath, however after testing… I can definitively say it was successful for my needs! So, I decided I’ll share it for those who have a PiCam and want to incorporate it into their home/studio streaming setup.

Step 1 – Information

Gather some information from both of your computers. From your windows (or mac) machine, get the IP address. Also grab the Pi IP address if you’re going to remote into it.

Step 2 – Pi Setup

So luckily the Pi actually has everything installed that you need on it now. So what we’re going to do is create a quick file for easy startup. We’ve just got a couple of things to do.

First – Create a fifo file on the pi. I do this in the home directory for simplicity. We’ll name the fifo video for ease remembering:

cd ~
mkfifo video

Second – Open your favorite editor, mine is nano, and input the following, and save it as a shell file. Mine is named picam.sh:

The IP address/port you input is going to be the ip addressof your Windows or Mac machine that will be running mplayer on it. The -w and -h refer to the height and width you are planning on streaming… I set it to 1280×720 because that’s my preferred resolution. You can set it to 1080p or higher/smaller depending on your preference. Just know that the larger the resolution the more data needs to be sent and could possibly introduce more latency. If you’ve saved this shell file in a directory that is not the same as the video fifo file you created, you’ll need to change the ‘video’ portion to match the location of the fifo file.

Third – After you’ve saved the file, you’ll need one more step for ease. The following tells the Pi it’s an executable shell file that you can run:

chmod +x picam.sh

Step 3 – Windows/Mac Setup

So I’ll provide the Windows setup, as that’s what I use. However mplayer and netcat are both available for Mac as well, so you can figure that out if you’re a Mac person.

First – Download and install netcat and mplayer for windows. netcat doesn’t appear to have a native build on the sourceforge, however a kind individual has been maintaining a build personally for others to use.

Go here and download/unzip netcat: https://eternallybored.org/misc/netcat/ Once you’ve downloaded it, make note of where you unzip it. For ease, I put it in the root of C, but you can put it anywhere you want, just make a note of it.

Second – Go download and unzip mplayer for windows here: https://sourceforge.net/projects/mplayerwin/ Again, make note of where you unzip. Again for my purposes I unpacked it in root of C.

Third – In your favorite text editor, create a simple text file with the following:

Once you’ve saved it, rename it to whatever you want but save it with a .bat extension. This tells window it’s a batch file and that it runs the commands inside of it. The cache you can set to lower if you’d like. I tried 1024 but occasionally emptied the buffer so I increased it a bit just for safety. You’ll also notice I specified 60fps. That’s because the v2 camera for Pi I’m using can do 60fps at 720p. If you’re running larger resolution or simply don’t want 60fps, you can of course change that to 30. In fact, you might want to as your Chew archive will be capped at 30fps anyways. That will lower latency even a bit more as you’re sending half as much data.

Step 4 – Low-Latency Magic

That’s all there is to setup, so let’s get this in action.

On the streaming computer, run the batch (or mac variant) file you created. You should see something similar to the following:

Now on the Pi, remote in or whatever you’re doing and switch to where you saved your shell file and run it.

./picam.sh

Here you can see I’ve VNC’d into my Pi and run the command in a terminal window in my home directory:

The output on the Pi should start running thru the pipe and pushing to the streaming computer. If you look at the output on the streaming computer, you should see something like the following:

Also you’ll see an mplayer window open after a few moments with the stream from the PiCam! Go ahead, test it out. Look how low-latency that is! Awesome right? Below you can see the stopwatch app in Windows on top, and the picam capture of it displayed in mplayer. Mind you, this is a 720p 60fps stream over a wifi connection:

Step 4 – OBS Capture

So, now that the mplayer window is running, you simply need to start up OBS (or whatever software you’re using) and do a game capture and select it.

Step 5 – ENJOY!

Ok, so you’ve got it setup, you’re rocking a new PiCam incorporated into your home/studio streaming option. So what now? Enjoy it! If you enjoyed it and want to support other guides like this, feel free to donate to motivate for other solutions etc!

]]>http://mikeymalone.com/2016/12/23/picam-obs-integration-low-latency-streaming/feed/01454Chew.TV has gone DARK!http://mikeymalone.com/2016/10/04/chew-tv-has-gone-dark/
http://mikeymalone.com/2016/10/04/chew-tv-has-gone-dark/#respondWed, 05 Oct 2016 02:25:40 +0000http://mikeymalone.com/?p=1390…Continue Reading]]>Have you ever been listening to a Chew.TV stream while lying in bed with your favorite device and thought, “Man… the screen is just so bright!” Well… apparently you’re not alone. Today, a few people were discussing whether this would be an awesome idea or not and the conclusion was… yes. Yes it would be.

So here we go. While Chew.TV could, and may, implement their own dark theme, I’ve created one that doesn’t detract from the overall Chew.TV theme. Simply some color CSS changes etc. You must be asking yourself, “How do I use this awesome new theme?” Well I’ll tell you.

Step 1: Install Stylish Add-on

Stylish is an addon for Firefox & Chrome that lets the user create/install/share themes for their favorite websites. So choose which browser you want and load it up. Note: You will have to restart your browser after install for it to take effect.

You should see a shiny new “S” icon in your browser extensions area. When stylish is inactive, it will have be a white icon, when Stylish is active on a page, it will be multicolor. Examples:

Stylish – ActiveStylish – Inactive

Step 2: Install my Chew.tv Night/Dark Theme

Installing userstyles is simple as can be. Head over to userstyles.org and install my script from there via the “Install Style” button.

Step 3: ???!!

Ok, so there are no other steps. Simply browse around on Chew and you should notice a sleek dark interface. I tried to hit all the pages, however I may have missed a page or an interface. When you want to go back to the default theme, click the stylish icon and you should be presented with a menu that looks similar to this. Simply click the theme to disable it.

Step 4: Donate if you want!

So, just like all my other tools, I provide this free to you. If you find it useful, or want to request specific changes, or even new projects, donate to motivate me

Note: This doesn’t work unless you’ve read and setup your Pi like described in the previous guides linked below.

So you’ve gone thru the first three posts (1, 2, 3) about the #PiCam/#ChewCam and got it going and think it’s awesome as hell, right?

Now think of the awesome setups you can stream with your new camera. You’re out and about and you want to stream your party/gig/event/whatever. You’ve got an awesome cellphone plan or a wifi connection at the event, and want to do as little as possible to the pi to get it running.

For me, I wanted to use the #PiCam to stream to Chew.tv and share my awesome parties/events/gigs that I’m at. I already have to setup gear usually, so I wanted it to be as simplistic as possible for me to turn the pi on, connect it to whatever internet connection I’m using, and let it do it’s magic. In a perfect world for me, all I would need to do is turn on the Pi and be done with it (which I suppose I could do), but I suppose a little bit of interaction is probably safest.

Step 1: Configuring your Network

So here’s my situation and setup. I plan on using my ChewCam at my regular weekly event. We have a (usually)steady wifi there, then I have my cellphone’s hotspot feature, then my home wifi for when I’m at home. So what we do is add these all in the proper priority in the right file. To do this, we’ll edit the wpa_supplicant file. This is for wifi connections only, cause honestly, if you’re connecting by ethernet this is all moot. You won’t have this file if you have no wifi built-in or via dongle (older Pi devices).sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
This pulls up the file in the editor. I’ll post my example and you should be able to figure out what to do to match your situations.

Ok, so what does the above do? It is ordered in a specific manner so that the Raspberry Pi connects to the wifi ssid’s automatically. So at home, when I turn my Pi on, it connects to the “supercoolhomewifi” using the password assigned. The neat part though is, let’s say I am at home and turn on my phone’s hotspot. Since it is higher in the priority list, the Pi will move wifi connection to it. Extremely handy. Same thing if the Pi was connected to my “workunsecuredwifisucks” ssid. I turn on my hotspot on my phone (or whatever device), and the pi switches over to it and uses it’s connection.

After you’ve made changes to your wpa_supplicant file, you’ll need to reboot to put it into effect.

Step 2: Semi-automagic connection

So here is where things get fun. Chew.TV has an API service, and thru the API, you can create/modify/delete shows and grab show/chat information. So with a little wizardry, we can get the #ChewCam to create our show and automatically start streaming to the show.

First, head on over to Chew.TV and get your API Key here. Once you have your API key, we’re gonna do a few things on the Pi to get it ready for what we need.

So what does it do? Well first, we create an array with required data needed to create a show. You can expand this array by adding more info from the options listed here. The next part encodes the array into a json string.

We then connect to the api interface and send all the proper header and REST-type information. Then we retrieve the results, decode the json string into an object, then pull our URL and Key information from the object that we created.

The final line, the exec() line should look familiar to you. Inside the exec is our gstreamer string from our previous steps. Now depending on your connection you may want to modify the width/height/FPS. Save the file and we’ll move on.

Now, if you’ve done all the steps we’ve talked about previously, and didn’t encounter any errors, we should be good to go for some magic! We’re going to call that new php file with the php command line interface. In my example below, my php file is named chewshow.php:

But wait? Why is it blank? Well that’s a GOOD thing. The way we have it setup, it’ll only display something if there is an error. What’s happened is the ChewCam file is now streaming in the background. Go ahead, go look at your chew shows!

So there we have it. When you’re done streaming, you can CTRL+C in your ChewCam via SSH/RDP/VNC and the stream wraps up and you’re done. Or if you turn off the camera without doing that, Chew.TV will auto-end your stream after 20 minutes.

Now you could of course take this to full-on automation, but then what about those times where you simple wanted to turn on your Pi and not stream. I figured a simple in-between step would be good, and it’s a lot less bothersome now to setup and use out in the field than it used to be.

]]>http://mikeymalone.com/2016/09/30/picamchewcam-automation/feed/01382Malone’s Auto-Hype for The Konduithttp://mikeymalone.com/2016/09/25/malones-auto-hype-for-the-konduit/
http://mikeymalone.com/2016/09/25/malones-auto-hype-for-the-konduit/#respondMon, 26 Sep 2016 05:54:45 +0000http://mikeymalone.com/?p=1378…Continue Reading]]>So in the old days of Mixify, there was a hype function. It was client-side scripting that sent to server for sheer cosmetic effect and a way for the listener to show appreciation to the dj. As we’re all aware, Mixify is no more (acquired by Chew.tv).

I was approached by someone to create an auto-hype for The Konduit, and here we are. Same steps as before so I’ll keep this post brief.

This willwork in multiple rooms at the same time. So yes, if you have multiple rooms open in different tabs, you will be hyping in each room separately.

This will not pull your focus away from the chat input so you won’t be interrupted while typing (like when you use iMacro, etc). So chat it up with the other listeners and have a party!

This willhype no matter which room you are in. If you want it to work only in a certain person’s room you’ll need to edit the @include. If it’s not entirely apparent, feel free to ask in the comments here and I’ll help you.

Installation

Once you have installed one of the above (or both if you use Chrome & Firefox), you’ll need to go install the script I created. To do so just head on over to Greasyfork.org and install the script. There’s a green button that says install, click it!

Step 3:

Sit back and enjoy the music on The Konduit and let the script do the hyping for you!

Donate

Did you find this useful? Donating helps to motivate me to maintain and release more tidbits for your enjoyment! Donate today and buy me a coffee, new music, or new equipment!

Troubles? Questions? Issues?

Leave a comment below!

]]>http://mikeymalone.com/2016/09/25/malones-auto-hype-for-the-konduit/feed/01378What to do when your laptop screen is not enough?http://mikeymalone.com/2016/08/29/what-to-do-when-your-laptop-screen-is-not-enough/
http://mikeymalone.com/2016/08/29/what-to-do-when-your-laptop-screen-is-not-enough/#respondTue, 30 Aug 2016 04:06:50 +0000http://mikeymalone.com/?p=1369…Continue Reading]]>In the past, and still in the present for many, DJs had to worry about how to access all the information on their laptops… At least for those who use them during live gigs. Often when you’re out with your mobile setup, you’re restricted to whatever information you can cram onto the screen.

Take my laptop for instance. I’ve got a Toshiba Satellite (S855). I’m not here to tote the specs of the laptop or argue Windows vs Apple. That argument has been had time and time again, and if you really want to get into that discussion, just leave a comment and we can “discuss” there

On my laptop, the screen resolution is a measly 1366×768. So I’ve always had to be… creative in how I use my layouts in dj software and production software. The obvious solution was to simply get another monitor, but I wanted to avoid having yet another power plug to plug into a power strip so I began looking around for alternatives.

After a bit of digging, voila! You’ll have to excuse the mess, I’m re-organizing my office/studio space sooooo yeah. Sorry about that.

Enter the AOC e1659Fwu 16-Inch Ultra Slim monitor. Now, you may be wondering “Hey, didn’t you just say you didn’t want to plug in another monitor??” You are absolutely correct! That’s the joy about this bad boy! I wanted something that could run off of USB/HDMI combined or something to that effect. This monitor runs completely off of the USB 3.0 port. One cord. Using the latest displaylink driver it not only provides an additional 1366×768 of screen real estate, that screen can sit on any of the edges and the screen will flip to fit. It’s got a built-in stand and comes with it’s own carrying case. So I can simply unplug it, put it in the case, and put it in my flight case. Easy-peasy lemon-squeezy.

There are days when I’m thankful to have lived the 40 years that I have. I’ve watched technology progress so far during that time. Thank God we’re not all still stuck with the old CRT monitors. shudder

Anywho, if you’re looking for more screen real-estate for your portable setup, I suggest giving this a go. There are multiple versions and a couple of companies putting these things out from what I saw. AOC after reading the reviews etc seemed like the choice for me, so I wanted to share with yall.

Holy moly! You’ve made it to part three (the final stage) of the remote recording solution, PiCam! So you’ve followed Part 1 and bought all the parts you need and gotten them assembled. You’ve followed Part 2 and got all the software bits running that you need… So now you just need to put it all together and make the hardware and software do what you want!

If you recall in the final steps of the part 2, you ran the gst-launch to test that the software ran properly. The final step is similar, only we’re going to add a bunch of add-on commands to the gst-launch to make it do what we want. This will cause it to run things depending on how we want to do them.

Here’s the general command I use to launch my streamer/recorder depending on which I’m doing

Now… You’ll notice there are some settings you can change here. The above is an example for a 1080p 30fps stream. But what if you wanted to do 720p? Or 60fps? Yes, the PiCam CAN do 60fps 720p streaming/recording, which I think is pretty freaking awesome for such a compact little device. So… how would you do that? Well you the width&height should be obvious, then to change the FPS you change framerate from 30/1 to 60/1. So it would look something like video/x-h264,width=1280,height=720,framerate=60/1,profile=high That tells it to do 1280×720 video at 60 frames per second.

You can change the bitrate if you want, but know that larger bitrates increase filesize, while smaller bitrates decrease quality. It’s really a balancing act based on what you’re trying to do. Larger filesizes/bandwidths are required for higher bitrate and resolutions/FPS streams. With the above settings, it saved a test file of about 16 seconds and used 4mb of space. Of course the grows with the length of stream when you’re saving a file, and if you’re streaming, you simply need to make sure you have enough bandwidth available for it.

The other difference you can see between the two options is the method for the sink (output). In the first example, we’re using filesink with a location specified to a directory and file name on the Pi. In the second example, you see we’re using an rtmpsink with location to the rtmpurl that you would use for Chew/Youtube/Twitch/Whatever.

For those trying rtmp streaming for the first time, most stream hosts will give you your rtmp url broken down in to two parts, commonly called the Stream URL and the Stream Key For instance, Chew.tv may give you Stream URL: rtmp://stream-na.chew.tv/live and Stream Key: chew-someusernamehash You then put that information into most of the stream software separately. But really you’re setting the rtmp stream to go to the designated URL rtmp://stream=na.chew.tv/live/chew-someusernamehash and that is what’s called when a viewer pulls up the stream. So what we’re doing in the second example is simply combining it into one RTMP url and the server knows what to do with it. It’s the same with youtube, twitch, etc. You’ll get a stream url, and a “stream key” which is usually just a unique hash to your channel, which you can then reset. Chew.tv and some others however I believe give a unique key each stream, so you’ll need to pay attention depending on which streaming service you’re using the camera with.

Advanced PiCam Steps

So you may be wondering, “Is there a way I can automate some of these startup steps?” Well… when there’s a will, there’s always a way. For instance, I wanted to create a simple bash script to automatically call up the proper gstreamer launch configuration dependent upon what I wanted to do. Now I warn you: this is just a test script that does what I want it to do. There are probably better ways to do this, but this is simply the method I chose to accomplish what I wanted to do.

As I’ve said in the earlier guide steps, I enjoy command line workings. I use SSH to connect to my pi, and go about what I need to do that way. I wanted a method that I could automate my steps and simply run a simple script thru an ssh client from my phone to start the pi-cam. Voila!

You’re probably looking at that and going, “HOLY SHIT WHAT IS THAT??” And to be honest, any time you look at a script on the web, you should think that and not use it unless you understand it and know what it’s doing. I’m merely providing this for an example. This is a simple bash script (the common command like scripting for many linux installs/distros) that offers 6 different streaming options and an exit option. The first the the script does is set a date/time variable since I couldn’t figure an easy way to include it in the filesink.

All of this is saved to a filename.sh which I provided execute privileges to, and I simply run it and choose what I want to do.

Then it provides the options for the choice between the three resolutions/fps combos I wanted to allow (1080p 30fps, 720p 60fps, 720p 30fps). The user then selects whichever option they want and the script goes through a case statement to match the option they chose.

If the user chose a streaming option, the script then prompts for the RTMP url, and sets whatever the user inputs as a variable, then launches gstreamer with the proper resolution/fps setting and the rtmpsink with the rtmp url variable.

If a file option is chosen, it launches gstreamer with the resolution/fps and sets the filesink to save to the /home/pi/Videos/ directory with a datetime-resolutionfps.flv filename. The other things are just some fluff echos that I’ve added to display information of choice, etc.

As you can see, with some intuition and basic research you can get this little inexpensive device to do a whole heck of a lot! Hopefully this tutorial/guide has inspired you to get involved in the Raspberry Pi project, and maybe I’ll see you streaming on Chew.tv soon!

So you read Part 1 of the Remote Recording & Streaming Solution and went out and got all your Raspberry Pi goodies purchased. You’ve got them all plugged in and everything powers on, now what? Well, let’s see if I can help you out with that some.

So let’s discuss what the Raspberry Pi is and why it may seem foreign to quite a few of you. The Raspberry Pi is a product of the Raspberry Pi Foundation with the purpose of providing inexpensive computing hardware for children to learn computer sciences on. You know what? I’m not going to write the book on this for you, simply head on over to Raspberry Pi and watch this “What is Raspberry Pi?” video!

So you’re back, and you’re thinking, “That’s all well and good, but what now?”

Raspberry Pi is a small computer, similar in power to many cell phones. Depending upon the software installed, it can have a variety of operating systems. The usual flavor of O/S used is Raspbian, which is a Debian-based Linux system. So yes, to use your Pi, you’ll be playing/learning Linux. Now I could go on for hours, no days, hell… forever about the ins and outs of Linux, and I still consider myself new to Linux. For a long time, and still widely used today, Linux was the backbone of the internet. It’s still the driving software behind many, many servers that power your favorite websites. But I’m not here to give you a Linux lesson, you just want to get your Pi setup and ready to record and/or stream.

When you boot your Pi for the first time, it will boot to the desktop manager (X session). This is like Windows, but different.

Yours won’t have those random files, it will likely just have the trashcan icon. Those files we’ll get to later There’s a few things to point out, the menu button is similar to the old start button in Windows. It’s your general menu and has links to many of the things you’ll install inside the desktop manager. The thing I want to bring your attention to is the computer screen icon to the right of the menu button. That’s the icon for your “terminal” window. A lot of things can be done through command-line interface, as well as thru gui. I’m going to simply give you CLI commands at this point because… well preference? I actually rarely use the RDP and connect via SSH to my Pi to do what I need.

First and foremost, update your PI.

sudo apt-get update
sudo apt-get upgrade

These will tell your Raspbian to update it’s sources lists. Linux, unlike windows, is maintained through packages focused on specific things. Each source list is called a repository and each repository can have many many packages on it. “apt-get” is a package manager program used in Debian-based systems.The first command tells your Pi to update it’s list, the second tells it to upgrade any packages that need it. It will likely prompt you asking if you want to continue, go ahead and type yes. After a few moments (or many minutes depending on the number of packages needing updates), you’ll be back at your prompt.

The next command will open a CLI based pseudo-GUI for configuration options:

sudo raspi-config

There are a few things you’ll want to address. First is to “Change User Password”, the pi default password is easily known to anyone who has a Pi. Devious individuals could try to gain entry to your Pi when you’re out and about if you have it connected to wifi’s etc.

Update your “Internationalization Options” as well. You’ll want to make sure the Pi knows what country you’re in, as well as setting the proper timezone.

Essential for this project, you’ll want to “Enable Camera”, else why are you reading this??

There are some other options you can adjust and partake in such as Rastrack (a fun/simple tracking website for Raspberry Pi’s), as well as some other basic stuff. Once you’ve got your settings done, go ahead and exit out of raspi-config, then restart your pi with the following:

sudo shutdown -r now

This tells the Pi to shutdown with the restart flag, now. So the pi will reboot, and all should be good and you’re back at your desktop manager. Once again, open the terminal window. Now it’s time to install the nuts and bolts of what you’re going to need for the streaming/recording.

These install a few things. xrdp is awesome, because it allows you to connect via Remote Desktop Protocol (from Windows and other machines) to your Pi and lets you control it just like you were sitting at the pi with keyboard & mouse. VLC is common for a bunch of the audio/video codecs you’ll need, samba for windows network interactions, and gstreamer1.0 for the streaming/recording stuff.

The second line installs some of the normal Linux development tools, as well as some dev packages for pi and gstreamer. This allows you to build the packages/programs you need since they’re currently not a package on a repository anywhere for you to just install with.

Next, you’re going to need to get the source files you need to build the wrapper.

This tells Pi to download a file from the web and save it as gst-rpicamsrc.zip. You’re grabbing the source which, once you build it, creates an element for gstreamer to interface with the raspberry pi camera and use it as a source.

Now to unzip/unpack the archive, and get into the building of it. First you’ll unpack it, change to the directory, then the first step in building things in linux is to configure it.

The last line is telling the configure script where to prepare the program to be installed and some libraries to include.

Then you build the files with:

sudo make

Then you do the final install of the files you built

sudo make install

If all goes well and you don’t have some sort of Error at the end of the output, you should be ready to test that you set everything up correctly!

gst-launch-1.0 rpicamsrc bitrate=1000000 ! filesink location=test.mp4

This launches gstreamer using the rpicamsrc element you created, tells it the bitrate, and tells it to save a file in the directory you were in called test.mp4. You should see something like this:

It will run the camera (which should appear on your HDMI output) and save the file test.mp4 until you end it. Let’s do that by sending the interrupt with Ctrl+C:

And now with a quick ls command to list the directory we see our test.mp4 file output:

So there you have it, you’ve now successfully connected all your Raspberry Pi hardware, connected all the bits together, added the gstreamer packages, and should hopefully have successfully ran the test to save/create a video file of the camera input.

In the next blog post, we’ll dive deeper into the gstreamer steps and start actually streaming things live to your favorite rtmp service! Enjoy!

]]>http://mikeymalone.com/2016/06/24/remote-recording-solution-picam-part-2/feed/11349Remote Recording Solution – PiCam!http://mikeymalone.com/2016/06/20/remote-recording-solution-picam/
http://mikeymalone.com/2016/06/20/remote-recording-solution-picam/#commentsMon, 20 Jun 2016 23:51:57 +0000http://mikeymalone.com/?p=1325…Continue Reading]]>So in my endeavors to make my rare gigs more memorable, I’ve been on the lookout for methods to record audio & video of my sets. In doing some perusals of various methods, I happened across a channel on the Chew.TV Slack called #chewcam. As I dug into information on it, it seemed like an awesome idea for multiple reasons, so let’s touch on what it is, and how to make it happen.

#ChewCam is a channel on the Chew.TV slack dedicated to using Raspberry Pi as a stream/recording solution. Using the rpicam code, plus some packages from the pi repository, someone can for all intents and purposes create a self-contained streaming and recording solution, with a few caveats. Let’s delve into how this happens. I’m simply documenting the hardware I’m using, as well as the steps I took to get everything up and running. I’ll link to the hardware on Amazon where I purchased it, etc if you want to recreate on your own.

Hardware

Raspberry Pi

The first bit of hardware is the Raspberry Pi itself. While this can be done with older versions of Pi, I bought the Raspberry Pi 3 since it just came out and has some advancements over the Pi 2. The wonderful thing about the Raspberry Pi concept is that you’re purchasing a self-contained mini form factor CPU that is capable of quite a bit. And then you can customize it further by addons, cases, hats (extra boards that sit on top of yours), touch screen LCDs, and more. It can be a bit overwhelming though at first. So what I did to start, was buy a starter kit!

This is an awesome starter kit, it worked out perfectly. The case holds the Pi 3 snugly and snaps together easily, and the starter kit includes heatsinks for the gpu and cpu if you want. I chose the clear case style because it matches another piece I got, the camera.

Raspberry Pi Camera

There are two parts that I got for the camera, though the second part is optional. The first part is the camera itself which there are two options for. You can get the normal camera which works great for daylight and evening settings. It does not work so great for low-light settings though. Which is where option 2 comes in, it has no IR filter on it, so works great in conjuntion with IR lighting when you need low-light operation and setups.

The second part I linked to is optional, though I would obviously suggest it. It’s a case for the camera itself. Keep in mind when you buy parts for your raspberry pi, you’re usually just getting the circuit board and wires etc needed. Withe the camera it comes as the circuitboard with the camera attached to it, and the ribbon cable attached which you connect to your pi board. So that’s why I got the case, and it’s a clear case which is why I chose the clear-case starter kit linked at the top. It just ties together as a theme.

Sound Input/Output

One of the sad things I found out about the Raspberry Pi, is that even though it has a 3.5mm sound jack, it’s simply a stereo out for headphones/speakers/whatever. It’s not a combo jack with microphone input. You could of course replace the jack by soldering on a 3.5mm combo jack and soldering it to the right pieces etc, but why? The Raspberry Pi 3 comes with 4 USB ports, so I simply bought an inexpensive USB Soundcard to plug in. It simply plugs in and Raspian detects it automatically and I plug in my mic/line-in, and it has a line-out as well for speakers/headphones/whatever.

This part could be considered optional if you’re not worried about recording audio. Some people will simply want to record video and then do audio syncs etc at home in their favorite video editing software. If that’s your cup of tea, you can skip this piece of equipment and continue on.

Storage/OS

The Pi doesn’t have an incorporated HDD or anything like your normal computer setup (though you could use the USB for some external storage). So how do you boot it? By having your OS loaded on to a MicroSD card. Older versions of the PI used full size SD cards, but as I said I’m on the Pi 3 which is Micro SD. I chose a SanDisk 32gb MicroSD card, and then loaded the NOOBS/Raspian OS onto it.

Now if you have a microSD card already, you can likely use that. The tutorial I followed from Raspberry Pi foundation suggests 8GB or larger, and since I wanted a little bit of storage I went with a 32gb card. I figured this would allow me to record some audio/video without having to add USB thumb drives etc, and it works like a champ.

Power(?!)

So by now you may be wondering, “Ok Mikey, I ordered all the Raspberry Pi stuff, how do I power it all at my gig?” Well the great thing about the Raspberry Pi is that it’s a lower-voltage device. So while the starter kit linked above has a power supply, what about when you’re off-grid? Or when you’re in a situation that doesn’t allow for you running an extension cord, or when your power strip is all full-up? Enter the powerbank options. Now, I’m going to link you two options. One is the one that I purchased, and one was recommended by someone in the #ChewCam channel on Chew.TV Slack.

So, why the two options? Well I owned the Xiaomi 10400 powerbank. It’s pretty inexpensive, well-built, and does what it needs to do. The problem with this is that it has one output port that uses “smart output” to adjust the output amps based on the device. Here in lies a possible problem. The amps/volts used by the Pi vary based on what it is doing. In my tests with the Pi3 running on the battery pack, it ran just fine. Recorded and streamed video just as expected. However, I need to state this clearly! The entire time I ran my tests, the Pi would trigger it’s “current undervolt” warnring. Now as I said, it never stopped functioning, it would simply trigger the warning then reset and trigger again. I believe this is because the Power Bank was dropping amps then upping amps as it thought the device didn’t need as much power.

The second power-bank listed was suggested by someone else using their Pi out in the field and he states he doesn’t have that problem. Looking at the specs of the 2nd Power bank, it has two output ports, both capable of supplying 2.4a power. This allows for full voltage no problem for the Pi, so I may buy this one if I run into issues. It’s double the cost of the first one though, so I’m going to try more testing in the field etc to see if I actually ever run into any issues.

Output/Video

So at this point, you may be wondering “Ok, so what are we looking at for video quality?” And to answer that, I’m simply going to link two videos for you to review. These are going to be rtmp streams to YouTube at 720p and 1080p video. The audio I’m going to feed is simply YouTube royalty free music, so you’ll have to pardon that, but here we go! The camera remains in the same position between the two video streams, so as you can tell the zoom changes when switching between 720p and 1080p for some reason. I haven’t done any digging on this to see if it’s a specification of the camera or if it is something in the software rendering the stream, but enjoy none the less.

720p Video (Audio turns on a little loud at 2:40, sorry, lol)

1080p Video (Audio kicks in around 2:09)

Bonus Video Test

720p 60fps Quick Test

What’s next?

In a later post, I’ll document the howtos on setting up the PiCam to do what you need for both streaming & recording. Now keep in mind, the hardware that I linked above is just what I chose. There are many many options out there, and I encourage you to take the time to find what suits you best. After all, that’s half the fun in Pi-based Projects!