cyphercolt
Posts: 14
Joined: Thu Mar 21, 2019 4:34 pm

RTMP Stream using GStreamer and a B101

Fri Mar 29, 2019 12:36 am

Following a lot of helpful advice from the HDMI to CSI-2 via TC358743 on kernel 4.1 thread, I've managed to get Video and Audio from any HDMI out device to my Pi.
Big thanks to 6by9 for helping me get this project this far!

I'm trying to set up my Pi to Stream to Twitch.tv without having to buy a second PC with a capture card just to stream. Especially when the Pi setup with the B101 and an SD Card is around the same price as a good capture card.

This is my current pipeline, that is still giving me some buffering issues when I stream to RTMP, but is pretty good when I stream to a file.

  1. gst-launch-1.0 flvmux streamable=true name=mux
  2. ! rtmpsink location="rtmp://live.justin.tv/app/STREAMKEY" v4l2src io-mode=4
  3. ! "video/x-raw,framerate=60/1,format=UYVY"
  4. ! v4l2h264enc output-io-mode=5 extra-controls="controls,video_bitrate=2000;"
  5. ! video/x-h264,profile=high
  6. ! h264parse
  7. ! queue
  8. ! mux. alsasrc device=hw:1
  9. ! audio/x-raw,rate=48000,channels=2
  10. ! audioconvert
  11. ! avenc_aac bitrate=128000
  12. ! aacparse
  13. ! queue ! mux.

At the moment, whenever I start the stream and don't do anything, it's fine. As soon as pixels start to change I get this message which appears as choppyness and buffering on Twitch:
WARNING: from element /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Can't record audio fast enough
Additional debug info:
gstaudiobasesrc.c(849): gst_audio_base_src_create (): /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0:
Dropped 106560 samples. This is most likely because downstream can't keep up and is consuming samples too slowly.


From testing for a few hours, I noticed that Twitch is sending me the video at over 20000 kbps even though I set the bitrate down to 2000. I am positive this is where my issue is coming from. - I noticed no matter what I do in the extra-controls section for v4l2h264enc, nothing changes at all. It's as if it's ignoring everything in there.

Extra Info:
Hardware:
Pi 3B - Kernel 4.19
Auvidea B101 rev4

GStreamer:
gst-launch-1.0 --version
gst-launch-1.0 version 1.14.4
GStreamer 1.14.4
Unknown package origin

cyphercolt
Posts: 14
Joined: Thu Mar 21, 2019 4:34 pm

Re: RTMP Stream using GStreamer and a B101

Fri Mar 29, 2019 3:35 pm

I had a thought this morning - Is it possible to cap the Bitrate on the input itself? Potentially through the EDID?

I'll look my EDID editor when I get home anyway to see if there's that option (Using the AW EDID Editor, nice UI tool)
Then I wouldn't need to convert.

mextril
Posts: 3
Joined: Tue May 07, 2019 9:45 am

Re: RTMP Stream using GStreamer and a B101

Tue May 07, 2019 10:01 am

Did you found solution to control the video bit rate?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6995
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RTMP Stream using GStreamer and a B101

Fri May 24, 2019 8:46 am

Following mextril's other thread, there is a bug fix for setting the encode bitrate on v4l2h264enc as https://github.com/raspberrypi/linux/pull/2961
It should hopefully be merged in the next couple of days.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

cyphercolt
Posts: 14
Joined: Thu Mar 21, 2019 4:34 pm

Re: RTMP Stream using GStreamer and a B101

Tue Jun 04, 2019 7:01 pm

6by9 wrote:
Fri May 24, 2019 8:46 am
Following mextril's other thread, there is a bug fix for setting the encode bitrate on v4l2h264enc as https://github.com/raspberrypi/linux/pull/2961
It should hopefully be merged in the next couple of days.
Oh wow I had put this project on hold for a while, just came back to check in and saw this. I'll look into it and follow up if it helped!

Thanks!

alower
Posts: 20
Joined: Tue Feb 26, 2019 8:40 am

Re: RTMP Stream using GStreamer and a B101

Thu Jul 18, 2019 4:16 am

cyphercolt wrote:
Fri Mar 29, 2019 12:36 am
Following a lot of helpful advice from the HDMI to CSI-2 via TC358743 on kernel 4.1 thread, I've managed to get Video and Audio from any HDMI out device to my Pi.
Big thanks to 6by9 for helping me get this project this far!

I'm trying to set up my Pi to Stream to Twitch.tv without having to buy a second PC with a capture card just to stream. Especially when the Pi setup with the B101 and an SD Card is around the same price as a good capture card.

This is my current pipeline, that is still giving me some buffering issues when I stream to RTMP, but is pretty good when I stream to a file.

  1. gst-launch-1.0 flvmux streamable=true name=mux
  2. ! rtmpsink location="rtmp://live.justin.tv/app/STREAMKEY" v4l2src io-mode=4
  3. ! "video/x-raw,framerate=60/1,format=UYVY"
  4. ! v4l2h264enc output-io-mode=5 extra-controls="controls,video_bitrate=2000;"
  5. ! video/x-h264,profile=high
  6. ! h264parse
  7. ! queue
  8. ! mux. alsasrc device=hw:1
  9. ! audio/x-raw,rate=48000,channels=2
  10. ! audioconvert
  11. ! avenc_aac bitrate=128000
  12. ! aacparse
  13. ! queue ! mux.

At the moment, whenever I start the stream and don't do anything, it's fine. As soon as pixels start to change I get this message which appears as choppyness and buffering on Twitch:
WARNING: from element /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Can't record audio fast enough
Additional debug info:
gstaudiobasesrc.c(849): gst_audio_base_src_create (): /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0:
Dropped 106560 samples. This is most likely because downstream can't keep up and is consuming samples too slowly.


From testing for a few hours, I noticed that Twitch is sending me the video at over 20000 kbps even though I set the bitrate down to 2000. I am positive this is where my issue is coming from. - I noticed no matter what I do in the extra-controls section for v4l2h264enc, nothing changes at all. It's as if it's ignoring everything in there.

Extra Info:
Hardware:
Pi 3B - Kernel 4.19
Auvidea B101 rev4

GStreamer:
gst-launch-1.0 --version
gst-launch-1.0 version 1.14.4
GStreamer 1.14.4
Unknown package origin

Hey cyphercolt, how did you get audio to work? I'm trying to put together the same thing as you. Got a basic node app sending video to Twitch but no audio.

I'm not familiar at all with Gstreamer and I'm not able to follow the post above. How does this pipeline that you mention work? Any help would be greatly appreciated.

Cheers

Return to “Graphics, sound and multimedia”