0

I am trying to stream Raspberry Pi camera video using VLC. The code is as follows:

import subprocess
import picamera
camera = picamera.PiCamera()
camera.resolution = (640,480)
cmdline = ['cvlc','-vvv','stream:///dev/stdin','--sout','#rtp{sdp=rtsp://:8554/}',':demux=h264' ]
myvlc = subprocess.Popen(cmdline, stdin=subprocess.PIPE)
camera.start_recording(myvlc.stdin, format = 'h264')
camera.wait_recroding(60)
camera.stop_recording()
myvlc.stdin.close()
myvlc.wait()

However, the code does not produce the desired output. Please guide me what's wrong with this code snippet.

0

Do you have a debugger?

Are you using an IDE?

Check out Spyder from Anaconda

If you're a a beginner maybe Thonny

But, try breaking your code up into functions, so you more easily diagnose where the problem is. Try adding:

stdout=subprocess.PIPE, stderr=subprocess.PIPE

to you Popen() arguments, and read their outputs with

print('pass through:', repr(stdout_value.decode('utf-8'))) print('stderr :', repr(stderr_value.decode('utf-8')))

you might also want to try passing shell=True to Popen.

0

I think this is my first solution to stack overflow instead of a question :).

What worked for me was to type your command as a string instead of a list, then use shlex.split() on that string for the Popen command. If anyone can explain why shlex works where techraf's code doesn't, please do as I got here through mostly blind trial and error.

import subprocess
import picamera
import json
import shlex

vlcCommand="cvlc -vvv  stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst:8080}' :demux=h264"
conf = json.load(open('conf.json'))

with picamera.PiCamera() as camera:
   camera.resolution = tuple(conf["resolution"])
   camera.framerate = conf["fps"]
   camera.vflip = True
   camera.hflip = True
   cvlc = subprocess.Popen(shlex.split(vlcCommand), stdin=subprocess.PIPE)
   camera.start_recording(cvlc.stdin, format=conf["codec"])
   camera.wait_recording(30)
   camera.stop_recording()

#Connect to network stream on VLC with http://ip:8080 on client

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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