Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode as RTP stream #25

Open
mkhahani opened this issue Oct 12, 2019 · 1 comment
Open

Encode as RTP stream #25

mkhahani opened this issue Oct 12, 2019 · 1 comment

Comments

@mkhahani
Copy link

What would be the equivalent code for the following command? We plan to use beamcoder in a WebRTC project if is possible.

ffmpeg \
  -re \
  -v info \
  -i video.mp4 \
  -map 0:v:0 \
  -pix_fmt yuv420p -c:v libvpx -b:v 1000k -deadline realtime -cpu-used 4 \
  -f tee \
  "[select=v:f=rtp:ssrc=2222:payload_type=101]rtp://192.168.1.100:10090"
@Bahlinc-Dev
Copy link

Bahlinc-Dev commented Mar 2, 2022

First of all you are only encoding video, but not sending audio because you inserted a "tee" which makes multiple muxers, but then only are using the video stream part. The payload type also does not look right, should be 103 I think?

Anyways, to send video via rtp you would use this:

`//video stream to rtp
const vmux = await beamcoder.muxer({
format_name: 'rtp'
});

vmux.newStream(demux.streams[0]); // get stream from demuxer or make a new one

await vmux.openIO({
url: 'rtp://192.168.1.100:10090' + '?rtcpport=' // where to send the stream remove rtcp part if not needed
});

await vmux.writeHeader({
payload_type: 103, // IMPORTANT. libav sets a default of -1 for the payload type, webrtc does not like that
ssrc: 1111, // stream identifier, can be any positive integer number (must be expected by your webrtc implementation)
});

let vDiff;
while (true) {
const packet = await demux.read();

// video packets
if (packet.stream_index === 0) {
  if (!vDiff) vDiff = packet.pts; // if first packet is > 0 pts, subtract that out so we always forward a stream starting at zero (players like that)
  packet.pts = packet.pts - vDiff;
  packet.dts = packet.pts; // unless you have b frames, dts can equal pts.  You probably don't have b frames.
  await vmux.writeFrame({
    packet: packet
  });
}

}`

If you plan on passing audio also, opus requires a few steps depending on the source. You probably need a filter instead of just passing from decoder to encoder. Especially if changing sample rate from source.

(edit: not sure why the formatting here is messed up?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants