0

I've set up my Raspberry Pi 3 as an ad-hoc network so that I can log in, start a VNCServer session and run the Pi using my laptop.

The Pi is going to be installed in a rotating platform so it needs to be wireless. On the platform are sensors so when one of the sensors goes off, the platform rotates, turns the Raspberry Pi Camera on and displays the what set the sensor off.

This worked great when it was plugged into a monitor as I believe the Pi Camera video is sent directly to the HDMI, but once I am viewing the desktop from the VNC connection I don't see the video output.

I've seen how you can stream the Pi Camera video using a command like this:

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264

Then opening VLC player and watching it, but how do I run this command from within Python to begin the stream,

and is there a way to open VLC player from within Python, or add a video player component to the GUI on my application to view it from within the program?

Or just in general a way of streaming the Raspberry Pi Camera over VNC from within Python?

Cheers

1 Answer 1

2

The 'standard' library for working with the Pi camera module in Python is picamera, described here by the Pi Foundation as:

python-picamera is a pure Python interface to the Raspberry Pi camera module for Python 2.7 (or above) or Python 3.2 (or above). The library is written and maintained by Dave Jones.

The linked Pi Foundation page above has a brief walkthrough on getting started with it, and the library's author has provided some examples of more complex usage.

For future reference (or if you really, really want to use raspivid), if you need to launch a process from within Python you can use the subprocess module.

From the Python docs on the subprocess module:

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)

Run the command described by args. Wait for command to complete, then return the returncode attribute.

Examples:

>>> subprocess.call(["ls", "-l"]) 
0

>>> subprocess.call("exit 1", shell=True) 
1

Your Answer

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

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