[FFmpeg-user] Raspivid with ffmpeg on both sources (youtube & rtsp)

Moritz Barsnick barsnick at gmx.net
Fri Jun 23 20:02:48 EEST 2017


On Mon, Jun 19, 2017 at 20:17:34 +0000, Nicolas Winandy wrote:
> So, I looked in the ffmpeg documentation and found an interesting thread on multiple outputs : https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs.

That's probably the right place to learn.

> Then, I have tried the piped processes and another ffmpeg call to the inital command:
> 
> raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | ffmpeg -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/<SESSION> | ffmpeg -f h264 -i - -vcodec copy -f rtsp -rtsp_transport tcp rtsp://localhost:8888/live.sdp

That's not correct, and certainly not what the wiki page recommends.
The ffmpeg call after the final pipe isn't being fed anything.

Let us see what you are doing:

$ raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | [...]

I can only assume that that's correct, and gives a raw H.264 stream on
stdout. ("-t 0" isn't documented. Does that imply "infinite"? Can't you
just omit it?)

$ [...] | ffmpeg -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/<SESSION>

You don't need "-strict experimental" for the aac encoder anymore. BTW,
why not omit the audio? Does YouTube need it?

"-g 50" doesn't have any effect with "-c:v copy".

Apart from that: Does this part work (if you omit the part after)?
Well, fine then so far.

$ [...] | ffmpeg -f h264 -i - -vcodec copy -f rtsp -rtsp_transport tcp rtsp://localhost:8888/live.sdp

This would do the same thing to a local RTSP stream (if the part in the
middle weren't there). Does this work by itself?

I guess, with some Unix shell magic and/or "tee" (the program, not the
ffmpeg muxer), you could probably feed both ffmpegs' stdins from
raspivid's stdout. But since you asked about the ffmpeg way:

Both your desired outputs use the same "copy" encoding, which is cheap,
so you can just do two encodes to two outputs:

$ raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | \
  ffmpeg -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k \
  -map 0:a -map 1:v -f rtsp -rtsp_transport tcp rtsp://localhost:8888/live.sdp -f flv rtmp://a.rtmp.youtube.com/live2/<SESSION>

If you eventually need to do actual non-copy encoding, you may want to
use the "tee" muxer, where you only need to encode once (assuming both
targets desire the same parameters).

Cheers,
Moritz


More information about the ffmpeg-user mailing list