Comments (8)
@lumenier1 Hi! In my project I'm using hardware encoding on Raspberry Pi 3 with GStreamer - just try x264enc.
For gstreamer-send example you can change webrtc.DefaultPayloadTypeVP8
to webrtc.DefaultPayloadTypeH264
and webrtc.VP8
to webrtc.H264
in main.go. However there are ~3 sec latency in transmitted video, I've fixed it in pion/example-webrtc-applications#45
from mediadevices.
@alexey-kravtsov Does x264enc really support hardware acceleration on the Raspberry Pi? It works for me but leads to a CPU load of about 1.5 to 2 (in my test setup).
I switched to using omxh264enc in my test app. That seems to have decreased the load down to less than 0.5.
from mediadevices.
@djmaze actually I'm not 100% sure about x264enc
. I've tried omxh264enc
- it really loads CPU far less, but I have ~10s startup delay with it. Could you please share your pipeline with omxh264enc
or test app?
from mediadevices.
There is almost no startup delay for me.
The complete video pipeline in the application on the Pi looks like this:
v4l2src ! video/x-raw, width=640, height=480, framerate=15/1 ! queue ! video/x-raw,format=I420 ! omxh264enc control-rate=1 target-bitrate=600000 ! h264parse config-interval=3 ! video/x-h264,stream-format=byte-stream | appsink name=appsink
In order to see the difference, here is the pipeline when running on x64 machines:
v4l2src ! video/x-raw, width=640, height=480, framerate=15/1 ! queue ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast tune=zerolatency key-int-max=20 ! video/x-h264,stream-format=byte-stream ! appsink name=appsink
EDIT: Maybe the SPS insertion every 3 seconds (using the h264parse
element) is the crucial missing part in your pipeline? I read about that somewhere, so I added it, which made my pipeline work at all.
from mediadevices.
Thank you! I've missed h264parse
in my pipeline, so I don't know why it was working at all before :) I've slightly modified your example for my project (added videoconvert
before encoder), and now it works fine for me
v4l2src ! video/x-raw, width=640, height=480 ! videoconvert ! video/x-raw,format=I420 ! omxh264enc control-rate=1 target-bitrate=600000 ! h264parse config-interval=3 ! video/x-h264,stream-format=byte-stream ! appsink name=appsink
from mediadevices.
Great to hear it works for you. Was quite some trial & error and searching around the nets, because no one explains this kind of stuff to you..
Btw, I also used the videoconvert
when running on x64 but it at least seemed not necessary when running on a Pi 3 for me.
from mediadevices.
@lumenier1 now you can use mediadevices
to do hardware encoding on a raspberry pi 3, https://github.com/pion/mediadevices/tree/master/examples/webrtc.
Here's the snippet:
package main
import (
"fmt"
"github.com/pion/mediadevices"
"github.com/pion/mediadevices/examples/internal/signal"
"github.com/pion/mediadevices/pkg/frame"
"github.com/pion/mediadevices/pkg/prop"
"github.com/pion/webrtc/v3"
"github.com/pion/mediadevices/pkg/codec/mmal"
_ "github.com/pion/mediadevices/pkg/driver/camera" // This is required to register camera adapter
)
func main() {
config := webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
}
// Wait for the offer to be pasted
offer := webrtc.SessionDescription{}
signal.Decode(signal.MustReadStdin(), &offer)
// mmal package uses Raspberry Pi's hardware encoder.
// Reference: https://github.com/raspberrypi/userland/tree/master/interface/mmal
mmalParams, err := mmal.NewParams()
if err != nil {
panic(err)
}
mmalParams.BitRate = 500_000 // 500kbps
codecSelector := mediadevices.NewCodecSelector(
mediadevices.WithVideoEncoders(&mmalParams),
)
mediaEngine := webrtc.MediaEngine{}
codecSelector.Populate(&mediaEngine)
api := webrtc.NewAPI(webrtc.WithMediaEngine(&mediaEngine))
peerConnection, err := api.NewPeerConnection(config)
if err != nil {
panic(err)
}
// Set the handler for ICE connection state
// This will notify you when the peer has connected/disconnected
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
fmt.Printf("Connection State has changed %s \n", connectionState.String())
})
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
Video: func(c *mediadevices.MediaTrackConstraints) {
c.FrameFormat = prop.FrameFormat(frame.FormatI420)
c.Width = prop.Int(640)
c.Height = prop.Int(480)
},
Codec: codecSelector,
})
if err != nil {
panic(err)
}
for _, track := range s.GetTracks() {
track.OnEnded(func(err error) {
fmt.Printf("Track (ID: %s) ended with error: %v\n",
track.ID(), err)
})
_, err = peerConnection.AddTransceiverFromTrack(track,
webrtc.RtpTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionSendonly,
},
)
if err != nil {
panic(err)
}
}
// Set the remote SessionDescription
err = peerConnection.SetRemoteDescription(offer)
if err != nil {
panic(err)
}
// Create an answer
answer, err := peerConnection.CreateAnswer(nil)
if err != nil {
panic(err)
}
// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
if err != nil {
panic(err)
}
// Output the answer in base64 so we can paste it in browser
fmt.Println(signal.Encode(answer))
select {}
}
from mediadevices.
@lherman-cs why is it using google's servers?
from mediadevices.
Related Issues (20)
- Colour difference in generated video stream HOT 1
- How does screen capture work on Windows vs Linux? HOT 2
- ForceKeyFrame HOT 3
- Failed to start streaming: invalid argument HOT 5
- go build linux error HOT 3
- Add pion/.goassets
- GCC problem on Windows 10 HOT 1
- Display mouse cursor HOT 1
- Video not showing in video element in latest versions of chrome. HOT 5
- why does opening dev console in http example crash the server?
- rtp example problems
- Distorted audio capture on linux. HOT 5
- failed to find the best driver that fits the constraints to open usb camera HOT 1
- Multiple display for webcam device HOT 2
- use mediadevices.GetUserMedia() failed. err: failed to open device: failed to connect filters HOT 2
- jetson agx xavier ubuntu20.04 fail run HOT 2
- webrtc demo mic Sound tearing sensation
- Error in bridge.cpp when using openh264
- go1.22.2 - example/webrtc Audio works, but video doesnt HOT 5
- Video not show on mobile
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mediadevices.