Social

Social

Social

Showing posts with label live streaming. Show all posts
Showing posts with label live streaming. Show all posts

Thursday, August 4, 2016

Live Streaming to Youtube with Raspberry Pi 3

After a bit of research on the best way to stream from the Raspberry Pi 3 with camera sensor version 2, I came across this tutorial:
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=134141&p=893318#p893318

So I followed this until I hit issues.

When compiling ffmpeg for Raspberry Pi 3 I want to use all four cores of processor.

Where these instructions ( http://www.valmueller.net/stream-video-with-raspberry-pi-to-youtube/ ) say:

sudo make
sudo make install

I replaced it with:
sudo make -j4 install
Testing the install of ffmpeg:
ffmpeg

gives this error:
/usr/local/bin/ffmpeg: cannot execute binary file: Exec format error

I noticed that my full version of jessie must have had ffmpeg in it already so I removed it but it did not help:

I did not note the exact way I removed it but it was something like:
sudo apt-get remove ffmpeg

I removed the ffmpeg directory I had previously cloned ( /usr/src/ffmpeg) and cloned from another source:
https://git.videolan.org/git/ffmpeg.git

Then rebuilt with no options to see what happened:
sudo ./configure
sudo make -j4 install

then ran stream on command line and it worked!
sudo raspivid -o - -t 0 -w 1280 -h 720 -fps 25 -b 4000000 -g 50 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/my-utube-code-here

But while steaming I did get some warnings and errors to investigate further:

Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.

[flv @ 0x16dba70] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[h264 @ 0x168e1f0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
^Cmmal: Aborting program.0 size= 56962kB time=00:04:02.11 bitrate=1927.3kbits/s speed= 1x

[flv @ 0x16dba70] Failed to update header with correct duration.
[flv @ 0x16dba70] Failed to update header with correct filesize.

Youtube showed my live stream with a starting delay and a status of 'healthy' in green.
Raspberry Pi v2  with alternative pi-compatible camera module .  Camera sensor is v1 based 5 megapixel with adjustable focus and near fish eye - around 160 degrees angle of view

Next I can now investigate the errors and consider recompiling my ffmpeg with some of the options if needed.

UPDATE:
After some time playing with video, I resolved jerky capturing and added text display with this new run string

 sudo raspivid -o - -t 0 -w 1280 -h 720 -fps 30 -ex sports -b 4000000 -g 50 -a 12 -ae 10,0x00,0x8080ff -a "My Camera %m-%d-%y @ %I:%M %P" | /usr/src/ffmpeg/ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -framerate 30 -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 60 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/my-youtube-id