GithubHelp home page GithubHelp logo

ffmpeg-to-webrtc's People

Contributors

ashellunts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffmpeg-to-webrtc's Issues

Receive audio and send to ffmpeg

Hello how are you?

Now I need to receive the sound from the browser microphone, this code receives the RTP Track and sends it via STDIN to ffmpeg, but I don't hear any sound, what am I doing wrong

package main

import (
	"fmt"
	"time"
	"os"
    "os/exec"

	"github.com/pion/rtcp"
	"github.com/pion/webrtc/v3"
	//gst "gstreamer-sink"
)

func check(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	// Prepare the configuration
	config := webrtc.Configuration{
		ICEServers: []webrtc.ICEServer{
			{
				URLs: []string{"stun:stun.l.google.com:19302"},
			},
		},
	}

	// Create a new RTCPeerConnection
	peerConnection, err := webrtc.NewPeerConnection(config)
	if err != nil {
		panic(err)
	}

	// Set a handler for when a new remote track starts, this handler creates a gstreamer pipeline
	// for the given codec
	peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {

		// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
		go func() {
			ticker := time.NewTicker(time.Second * 3)
			for range ticker.C {
				rtcpSendErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}})
				if rtcpSendErr != nil {
					fmt.Println(rtcpSendErr)
				}				
			}
		}()

		//codecName := strings.Split(track.Codec().RTPCodecCapability.MimeType, "/")[1]
		//fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), codecName)
		//pipeline := gst.CreatePipeline(track.PayloadType(), strings.ToLower(codecName))
		//pipeline.Start()
		
		buf := make([]byte, 1400)
		chBuff := make(chan []byte, 1400)

		go playTrack(chBuff)

		for {
			i, _, readErr := track.Read(buf)
			if readErr != nil {
				panic(err)
			}
			chBuff <- buf[:i]
			//pipeline.Push(buf[:i])
			//fmt.Printf("%x", buf[:i])
			//fmt.Println(track.PayloadType())			
		}
	})

	// 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())
	})

	// Wait for the offer to be pasted
	offer := webrtc.SessionDescription{}
	Decode(MustReadStdin(), &offer)

	// 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)
	}

	// Create channel that is blocked until ICE Gathering is complete
	gatherComplete := webrtc.GatheringCompletePromise(peerConnection)

	// Sets the LocalDescription, and starts our UDP listeners
	err = peerConnection.SetLocalDescription(answer)
	if err != nil {
		panic(err)
	}

	// Block until ICE Gathering is complete, disabling trickle ICE
	// we do this because we only can exchange one signaling message
	// in a production application you should exchange ICE Candidates via OnICECandidate
	<-gatherComplete

	// Output the answer in base64 so we can paste it in browser
	fmt.Println(Encode(*peerConnection.LocalDescription()))

	// Block forever
	select {}
}

func playTrack(ch <-chan []byte){
	//cmd := exec.Command("ffmpeg", "-i", "pipe:0", "-f", "alsa", "default")
	cmd:= exec.Command("ffmpeg", "-i", "pipe:0", "-c:a", "copy", "-sample_fmt", "s16p", "-ssrc", "1", "-payload_type", "111",  "-b", "96k", "-f", "alsa", "default")

    cmd.Stderr = os.Stderr // bind log stream to stderr
    //cmd.Stdout = resultBuffer // stdout result will be written here

    stdin, err := cmd.StdinPipe() // Open stdin pipe
    check(err)

    err = cmd.Start() // Start a process on another goroutine
    check(err)

	for {
    	_, err = stdin.Write(<-ch) // pump audio data to stdin pipe
    	check(err)
	}

    err = stdin.Close() // close the stdin, or ffmpeg will wait forever
    check(err)

    err = cmd.Wait() // wait until ffmpeg finish
    check(err)
}

All video frames parsed and sent

I'm trying to use this to make a web remote desktop client, and when using -preset ultrafast -tune zerolatency (edit: not sure this is the issue) I just get All video frames parsed and sent

How to stream rtsp streams with copy codec to webrtc.

I am trying to stream my cctv streams to webrtc i have alredy tested many commands none of them works.
It returns "All video frames parsed and sent"
Please help me.
I am using windows planning to deploy on linux.

ffmpeg opus

Thanks for the great example h264, could you help me to upload the audio with ffmpeg?

Latency is very high when using h264 encoding

When using the h.264 encoding of the warehouse demo, the native delay is about 10 seconds. But if I switch to vp8, the basic delay is about 200 milliseconds. Why is this? I just switched h264reader.NewReader to ivfreader.NewWith

Clarify Instructions

Is SDP a text file ?

This never completes. Just stuck like this and doesn't do anything.... Am I missing something?

image

"Put SDP from ffmpeg-to-webrtc into your browser"

Hi, where do I find the SDP from ffmpeg-to-webrtc?

I assume it's meant to appear in the commandline?
Nothing seems to appear after such as command is executed;
go run . -rtbufsize 100M -i test.mp4 -pix_fmt yuv420p -c:v libx264 -bsf:v h264_mp4toannexb -b:v 2M -max_delay 0 -bf 0 -f h264 -

I added ffmpeg.exe into the src directory.
Thanks!

Can you share a IP camera stream without reencoding with that?

As in the title.

I once looked for a solution to push h.264 stream from IP camera without reencoding via WebRTC and failed completely. I don't remember the details, but it got stuck in my head that every solution required re-encoding.

Reencoding multiple 1080p streams would kill the server and I'd like to push several streams via WebRTC at the same time.

Sorry if my question is incomplete at some point - I'm definitely a beginner when it comes to streaming.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.