I have a Raspberry Pi 2 Model B and am running Raspbian.

I have a capture device (USB easycap) connected to the pi, and it is recognized and am able to open the video capture stream in VLC. I also have a python script I wrote that connects me to my server and fetches information for me.

I want to be able to run both of these tasks simultaneously. I need the VLC network stream to run, while also having the python script pull data down from my server (just simple json info). I need both of these thing to happen continuously and simultaneously . What is the best way to go about doing this?

Edit: Giving an overview of the project so that it may give a better understanding of what is being done so that you can better help out

I have the Raspberry Pi 2 with (NOOBS/Raspbian?) installed. The goal of the project is to receive the video output from a computer and have it inputted into the Pi. To do this, I have an HDMI2AV converter device (something like this) that takes in the PC's video output (via an HDMI cable) as an input to the HDMI input port on the device. The other end of the device outputs the video through composite cables that are then connected to a EasyCap DC60 USB capture device (something like this). The EasyCap is an stk1160 chipset so it worked right out of the box.

I have a powered USB hub with the USB host cable connected to one of the 4 Pi USB ports. I have the EasyCap DC60 plugged into the powered USB hub because I had read the the Pi could not provide enough power from its native USB ports for the DC60 with other peripherials connected as well (mouse and keyboard).

From there, the goal is to take the video that is coming in from the EasyCap DC60 capture and stream it from the Pi (using VLC/Mplayer/Omxplayer via RTSP) to a Android tablet or smart phone using an Android app I have written.

To handle the streaming and where it is streamed to, I have a server set up that the Pi connects to (as a form of authentication). The Android app that I have written also connects to the same server, so that the app and the Pi have all the information needed to connect to each other such as IP address and port (sending the transmission through the server would induce additional lag and latency).

I have a Python script running on the Pi that handles all the communication between the various system components (Pi, server, app, PC) and authentication between the Pi and the app (through the server). With the app, the user is able to issue mouse and keyboard commands/events (using a Bluetooth mouse and keyboard connected the the tablet/phone) that are transmitted to the Pi over TCP in JSON format. The Python script parses the JSON and passes the mouse/keyboard events (mouse coordinates. left/right clicks, key presses) to the computer that is providing the video source. This is done with a Teensy module connected to the Pi (UART pins on the Pi connect to the UART pins on the Teensy, micro usb port on Teensy connects to a USB port on PC) where the parsed JSON mouse/keyboard events are sent over UART from the Pi to the Teensy. The C code running on the Teensy takes the mouse/keyboard events from the Pi and using a library for mouse/keyboard HID, transmits the events received over UART to the PC that is providing the video source in USB-HID format in order to emulate a mouse/keyboard.

I have each part working independently:

  1. I can use the Python script to connect the Pi to the server, I can connect the Android app the to server, I can send mouse/keyboard commands directly from the Android app to the Pi, and I can send the app-received mouse/keyboard commands from the Pi to the Teensy and finally to the connect PC to properly emulate the PC's mouse and keyboard.
  2. I can open the DC60 video capture device and view the stream on the Pi, and am on the verge of being able to stream it to the app (fine tuning the best media player to use to do this and what parameters to use to optimize the video quality).
  3. How do I run both tasks 1. and 2. continuously and simultaneously?

TL;DR:I need the streaming of the video from the Pi to the app, and the listening for mouse/keyboard commands issued from the app (and subsequently the transmission of those commands to the PC via UART from Pi to UART on Teensy and then from Teensy to PC via microusb) to take place simultaneously. How do I accomplish this? The streaming of the video is handled by a string in the raspbian terminal (or a bash file), and the listening for and subsequent transfer of the mouse/keyboard commands is all being handled by a Python script. Do I create a bash file that runs the command to open the capture device' raw video and stream it, and then have that same bash file also call the python script? Would that work or is some sort of forking/threading needed to have both of these tasks run continuously or simultaneously?

  • Can you define simultaneously? What is the bandwidth needed by your video stream and python script? It may also help if you include a description of your project and what you are trying to achieve. Sep 1, 2015 at 0:28
  • Does the python script return any visual output for the user, or could it just run in the background? Sep 1, 2015 at 6:54
  • I updated the original post to include an explaination of exatly what it is I'm trying to do. @SteveRobillard: The bandwidth needed by the video stream is limited by the specifications of USB. I am trying to transmit 480p video (FPS and other specs are negotiable as long as it looks fluid and doesn't have insanse latency). The python script isn't very intensive at all. The python script pulls down JSON data that the app is sending, formats it, and sends it over UART to a Teensy board. Simple socket connectivity stuff, data fetching and serial transmission
    – Chriscas91
    Sep 2, 2015 at 2:46
  • @elParaguayo I updated the original post to expand on what exactly is being done in the project.The Python script does display the data being received from the app in the terminal (just for testing and debugging purposes) but the end goal is to not use any sort of GUI or view any console output while the device is in actual operation, so it is not necessary to view it. So yes it can just run in the background.
    – Chriscas91
    Sep 2, 2015 at 2:49
  • @Human, the RPi is not actually inputting HDMI signals in a traditional sense. I know the HDMI port on the RPi is output only. I have an HDMI cable connected from a PC to an HDMI2AV converter. So the HDMI signal is converted into simple composite signals. The composite signals are connected to the RPi through a EasyCap DC60 which takes composite input on one end, and connects to the RPi via USB on the other end.
    – Chriscas91
    Sep 2, 2015 at 2:52

1 Answer 1


So you have 2 programs that you want to run at the same time and have them both launched at boot.

Personally, I'd be inclined to do this with init.d scripts. I have had success using the example shown on this page: http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/

Although the page refers to a python script, it can be used to launch any program.

I would create 2 scripts, one for launching vlc and one for your python script. That way you can start/stop/restart them independently of each other (if necessary).

You'll need to update the template with the relevant paths and options for your programs - there are good instructions on that page.

The one part that I would change is where it says to run the command sudo update-rc.d myservice.sh defaults. I would change this to sudo update-rc.d myservice.sh defaults 99 as this will make your script start later in the boot sequence meaning that things like networking should be up and running first.

  • 1
    Thank you so much for your help! This sounds exactly like what I need to do. I will try it out and report back with my results here! @elParaguayo
    – Chriscas91
    Sep 6, 2015 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.