Bug #829

Hi-res is not working

Added by Hammel about 1 month ago. Updated 14 days ago.

Status:In ProgressStart date:26 Mar 2021
Priority:ImmediateDue date:
Assignee:Hammel% Done:


Target version:PiBox - 2.0 - Harkonnen
Severity:01 - Critical


The following command works for low res:
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 256x144 -f 4" -o "output_http.so -p 9090"

The following command works for high res:
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480 -f 33" -o "output_http.so -p 9090"

This is the current config for high res:
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480 -f 10" -o "output_http.so -p 9090"

It should work. But it will fail if the old mjpeg_streamer is running. So the problem may be that the low-res is still running when we try to switch to the high-res.

Associated revisions

Revision bf1b9e0e
Added by Hammel 24 days ago

RM #829: Init script doesn't need to set -I and -S. The config file can be used for that to customize piboxd for different systems.

Revision 796de61c
Added by Hammel 24 days ago

RM #829: Fix piplayer build to add -I -S to piboxd command in init script.


#1 Updated by Hammel about 1 month ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

Need to add some programmatic upkeep here.
See https://gist.github.com/tugstugi/2627647

This will allow me to query the device and do some setup before creating the hi-res/low-res instance of mjpeg-streamer.

#2 Updated by Hammel about 1 month ago

This may be a more general problem. I can't get the webcam to work at all with pisentry.

I need to retest a full media system build and check that the webcam is really working (on the web interface).
I need to add more debug - is the php message getting to piboxd? Is it the right message? Is piboxd not adding inbound to the queue? Is the message getting lost on the queue?

#3 Updated by Hammel 24 days ago

  • % Done changed from 10 to 20

It seems that the init script now starts piboxd with -I and -S. The latter disables streams. Taking that out (manually) seemed to let the video stream just fine.

The question is: why did that get added? And why?

#4 Updated by Hammel 24 days ago

  • % Done changed from 20 to 80

It was a mistake, based on tests for piplayer. This has been fixed now.
Changes committed, tested and pushed.
Still needs to be tested with pisentry just to be sure.

#5 Updated by Hammel 23 days ago

  • % Done changed from 80 to 60

Hi-Res is still not working in the webui. It starts in low-res mode but switching to hi-res fails.

#6 Updated by Hammel 22 days ago

The problem is that sometimes mjpg_streamer doesn't start. I don't know why. Nor do I know how to get any additional information as to why it doesn't start.

#7 Updated by Hammel 21 days ago

Just thought of this, but maybe I should switch from mjpg_streamer to ffmpeg. That might provide better results.

I need to experiment with using ffmpeg to stream a webcam. Some references:
  1. https://trac.ffmpeg.org/wiki/StreamingGuide
  2. https://www.rickmakes.com/streaming-an-ip-camera-to-a-web-browser-using-ffmpeg/
    1. https://www.youtube.com/watch?v=ztjT2YqQ2Hc
  3. http://4youngpadawans.com/stream-camera-video-and-audio-with-ffmpeg/
  4. https://yushulx.medium.com/raspberry-pi-live-streaming-with-usb-webcam-bbc5f2380b3f
  5. https://quincyhuang.io/2019/11/21/ffmpeg-hls/
  6. http://trac.gateworks.com/wiki/linux/v4l2

Question: Can we control the stream on the fly using v4l2-ctrl? A quick experiment shows this:

Set resolution and format

v4l2-ctl -d /dev/video2 -vwidth=1920,height=1080,pixelformat=YUYV

Play the video

ffplay -i /dev/video2

The pixelformat may not be needed as I can set it with ffmpeg directly. In other words, instead of adjusting the ffmpeg command I can simply adjust resolution with v4l2-ctl and then use the same ffmpeg command every time. Not sure if that's cleaner than what I have now, though by using v4l2-ctl I can use popen to run the command and find out if it works before starting the stream.

#8 Updated by Hammel 21 days ago

This works with VLC, but only because it can play from a UDP stream.

ffmpeg -f v4l2 -i /dev/video2 -profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -tune zerolatency -vcodec libx264 -r 10 -b:v 512k -s 640x360 -f mpegts -flush_packets 0 udp://

The IP address has to be the local hosts address where ffmpeg is run.

#9 Updated by Hammel 21 days ago

I've experimented with both mjpeg_streamer and ffmpeg. The latter doesn't stream as easily as mjpeg-streamer but does handle input and output formats managed via v4l2-ctl better. mjpeg-streamer doesn't honor v4l2 changes to the device. So the only choice is to relaunch mjpeg-streamer with different resolution settings.

That means a better understanding of why relaunching the process doesn't always work.

#10 Updated by Hammel 16 days ago

I have an update to piboxd/stream.c that waits for the process to really start by stat'ing it's /proc/<pid> directory. If that doesn't work it returns an error.

This should be extended in queueProcessor.c to put the request back on the queue to be tried again, with a max-tries option added. Right now there are other assumptions on what to do if the process doesn't start, like just updating the timestamp.

#11 Updated by Hammel 16 days ago

  • Severity changed from 03 - Medium to 01 - Critical

#12 Updated by Hammel 14 days ago

Code has been updated and is ready for testing. Build a media system and test the webcam via piboxwww.</p>

#13 Updated by Hammel 14 days ago

Doesnt work. A mjpg-streamer process is launched but never killed.

There has to be a better way.

Also available in: Atom PDF