<p>I don't know how raspberry encodes video, but if you got encoded stream, you can:</p>

<ol>
<li>Setup local RTMP server</li>
<li>Transcode it to HLS on the fly (this is cheap task, build-in in nginx rtmp server)</li>
<li>When you need, you can get screenshots with ffmpeg</li>
<li>When you need, you can record as many videos as you want with ffmpeg/rtmpdump</li>
<li>Feed video/images everywhere else you want</li>
</ol>

<p>Since here only one stream, here must be no problems with stream errors.</p>

CC BY-SA 3.0
2017-10-20T13:47:58.070Z
2017-10-20T13:47:58.070Z
bukkojot
<p>I'm trying to accomplish a few things at the same time with the raspberry pi camera;</p>

<ul>
<li>create an HLS live stream</li>
<li>take regular interval jpg snapshots and save them to disk</li>
<li>irregularly record short pieces of video to disk triggered by another process</li>
</ul>

<p>Running the HLS stream on its self works well with raspivid, psips and ffmpeg like this:</p>

<pre><code>raspivid -n -w 1280 -h 720 -fps 30 -t 86400000 -b 10000000 -o - | /root/psips | ffmpeg -loglevel 2 -y -analyzeduration 10M -i - -c:v copy -hls_time 5 -hls_list_size 10 -hls_wrap 20 /var/www/stream.m3u8
</code></pre>

<p>Since it's not possible to get access to the video device when it's already in use by raspivid, I create multiple virtual video devices for the desired scenario with v4l2loopback.</p>

<p>The first virtual device (/dev/video1) is created by running ffmpeg in the background like this:</p>

<pre><code>ffmpeg -f video4linux2 -video_size 1280x720 -r 24 -input_format h264 -i /dev/video0 -vcodec rawvideo -f v4l2 /dev/video1
</code></pre>

<p>Then I try to start the HLS stream like this:</p>

<pre><code>ffmpeg -i /dev/video1 -r 24 -f h264 - | /root/psips | ffmpeg -loglevel 2 -y -analyzeduration 10M -i - -c:v copy -hls_time 5 -hls_list_size 10 -hls_wrap 20 var/www/stream.m3u8
</code></pre>

<p>For some reason this results in ffmpeg producing quite a few 'Past duration 0.xxxxx too large" errors and psips exiting with a 'SPS/PPS overrun!' warning.</p>

<p>I'm not sure what's happening here or if there's something wrong with the approach I've chosen maybe?</p>

<ffmpeg><linux><hls>
Streaming HLS from a video4linux2 virtual video device
Erik van der Leer
# Streaming HLS from a video4linux2 virtual video device

(Asked by: username_0 on 2017-10-20)

I'm trying to accomplish a few things at the same time with the raspberry pi camera;

create an HLS live stream
take regular interval jpg snapshots and save them to disk
irregularly record short pieces of video to disk triggered by another process

Running the HLS stream on its self works well with raspivid, psips and ffmpeg like this:
raspivid -n -w 1280 -h 720 -fps 30 -t 86400000 -b 10000000 -o - | /root/psips | ffmpeg -loglevel 2 -y -analyzeduration 10M -i - -c:v copy -hls_time 5 -hls_list_size 10 -hls_wrap 20 /var/www/stream.m3u8

Since it's not possible to get access to the video device when it's already in use by raspivid, I create multiple virtual video devices for the desired scenario with v4l2loopback.
The first virtual device (/dev/video1) is created by running ffmpeg in the background like this:
ffmpeg -f video4linux2 -video_size 1280x720 -r 24 -input_format h264 -i /dev/video0 -vcodec rawvideo -f v4l2 /dev/video1

Then I try to start the HLS stream like this:
ffmpeg -i /dev/video1 -r 24 -f h264 - | /root/psips | ffmpeg -loglevel 2 -y -analyzeduration 10M -i - -c:v copy -hls_time 5 -hls_list_size 10 -hls_wrap 20 var/www/stream.m3u8

For some reason this results in ffmpeg producing quite a few 'Past duration 0.xxxxx too large" errors and psips exiting with a 'SPS/PPS overrun!' warning.
I'm not sure what's happening here or if there's something wrong with the approach I've chosen maybe?

**Tags:** ffmpeg, linux, hls


---

## 1 answers

### Answer by username_1 on 2017-10-20. Score: 0

I don't know how raspberry encodes video, but if you got encoded stream, you can:

1. Setup local RTMP server
2. Transcode it to HLS on the fly (this is cheap task, build-in in nginx rtmp server)
3. When you need, you can get screenshots with ffmpeg
4. When you need, you can record as many videos as you want with ffmpeg/rtmpdump
5. Feed video/images everywhere else you want

Since here only one stream, here must be no problems with stream errors.


---

