2

I intend to create multiple stream output - 1 to RTMP and the other as mp4 file as below:

/var/lib/snapd/snap/bin/ffmpeg -i rtmp://127.0.0.1:1935/live/$key -i /home/apache/logo.png -f image2 -loop 1 -i /home/apache/prod1.png -filter_complex "[0:v][1:v]overlay=x=30:y=10[vt];[vt][2:v]overlay=x='if(lte(-w+(t)*100,200),-w+(t)100+100,200)':y=10" -framerate 25 -r 30 -ar 44100 -c:a libfdk_aac -b:a 20000k -movflags +faststart -preset medium -crf 1 -tune zerolatency -maxrate 20000k -vcodec libx264 -fflags nobuffer -g 60 -max_muxing_queue_size 1024 -f flv pipe:1 | /var/lib/snapd/snap/bin/ffmpeg -i pipe:0 -vf drawtext="textfile=/home/apache/sampletext.txt: reload=1: fontcolor=white: fontsize=24: box=1: [email protected]: boxborderw=5: y=((h)-20):x=w-(mod(4n,w+tw)-tw/40)" -framerate 25 -r 30 -ar 44100 -c:a libfdk_aac -b:a 20000k -movflags +faststart -preset medium -crf 1 -tune zerolatency -maxrate 20000k -vcodec libx264 -fflags nobuffer -g 60 -max_muxing_queue_size 1024 -bsf:a aac_adtstoasc -map 0 -flvflags no_duration_filesize -f tee '[f=flv]'rtmp://127.0.0.1:1935/live/rp$key'|[f=mp4]/home/apache/test.mp4'

And seeing below error on the rtmp output:

Output #0, flv, to 'pipe:1': Metadata: encoder : Lavf58.20.100 Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 320x240, q=-1--1, 30 fps, 1k tbn, 30 tbc (default) Metadata: encoder : Lavc58.35.100 libx264 Side data: cpb: bitrate max/min/avg: 20000000/0/0 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (libfdk_aac) ([10][0][0][0] / 0x000A), 44100 Hz, mono, s16, 20000 kb/s Metadata: encoder : Lavc58.35.100 libfdk_aac [image2 @ 0x5613e017e200] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8) Input #0, flv, from 'pipe:0': Metadata: encoder : Lavf58.20.100 Duration: 00:00:00.00, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (High), yuv420p(progressive), 320x240, 30 fps, 30 tbr, 1k tbn, 60 tbc Stream #0:1: Audio: aac (LC), 44100 Hz, mono, fltp, 20000 kb/s Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (libfdk_aac)) [Parsed_drawtext_0 @ 0x561287697200] Using "/usr/share/fonts/dejavu/DejaVuSans.ttf" [libx264 @ 0x5612876a0000] VBV maxrate specified, but no bufsize, ignored [libx264 @ 0x5612876a0000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [libx264 @ 0x5612876a0000] profile High, level 1.3 Output #0, tee, to '[f=flv:onfail=ignore]rtmp://127.0.0.1:1935/live/rpdc78|[f=mp4]/home/apache/test.mp4': Metadata: encoder : Lavf58.20.100 Stream #0:0: Video: h264 (libx264), yuv420p, 320x240, q=-1--1, 30 fps, 30 tbn, 30 tbc Metadata: encoder : Lavc58.35.100 libx264 Side data: cpb: bitrate max/min/avg: 20000000/0/0 buffer size: 0 vbv_delay: -1 Stream #0:1: Audio: aac (libfdk_aac), 44100 Hz, mono, s16, 20000 kb/s Metadata: encoder : Lavc58.35.100 libfdk_aac frame= 53 fps=0.0 q=0.0 size= 249kB time=00:00:02.31 bitrate= 877.9kbits/s speed=4.39x ^M[flv @ 0x561287a1b500] Failed to update header with correct duration. [flv @ 0x561287a1b500] Failed to update header with correct filesize. [tee @ 0x5612876677c0] Slave muxer #0 failed: Connection reset by peer, continuing with 1/2 slaves

I could see the 2nd output being saved to the right mp4 file, but 1st output just failed.

1 Answer 1

2

I think the problem you're experiencing is due to your live stream output. I've done a lot of live streaming in the past, and this issue was the first stumbling stone for me.

I believe you won't be able to stream your video in FLV format, considering that format requires all the metadata about the stream to be at the end of the stream (or file), which you won't have up until you finish your streaming. You can have all the metadata of that stream once you're finished streaming, but then your stream has already ended.

For a very short live streams, this issue will manifest itself in a way that the client/browser is showing the "loading" icon for a long time (until you finish your stream), at which point it will start displaying the stream.

But for a lengthy live stream, you'll probably need to pick the right format for your output stream. You can try using a muxer/format which has the metadata embedded into packets frequently (like mpegts) or you can try the segmented output like hls (more info), which sends multiple chunks of your media/stream with all the metadata within each chunk, so there's no issue consuming that stream by the client player / browser. You can even use rtp if your media server supports it.

See more examples on live streaming here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .