Rtmp streaming problems

Hello,
I’m having trouble getting rtmp stream output (ffmpeg consumer) working properly on CasparCG both with version 2.2 stable, and last build from master (I think it is 2.3 beta 1 or so?). I’m trying to use it on Ubuntu 18.04.4, but I’ve redone some tests on Windows with similar results.

ADD 1 STREAM rtmp://$server/$application/$stream -codec:v libx264 -codec:a aac -b:v 6000k -filter:v format=yuv422p -b:a 128k -filter:a pan=stereo|c0=c0|c1=c1 -format flv
[2020-06-13 01:27:42.033] [info]    Received message from Console: ADD 1 STREAM rtmp://$server/$application/$stream -codec:v libx264 -codec:a aac -b:v 6000k -filter:v format=yuv422p -b:a 128k -filter:a pan=stereo|c0=c0|c1=c1 -format flv\r\n
#202 ADD OK
[2020-06-13 01:27:42.034] [info]    ffmpeg[rtmp://$server/$application/$stream] Initialized.
[2020-06-13 01:27:42.037] [info]    [ffmpeg] [libx264 @ 0x7f5a7a596400] using SAR=1/1
[2020-06-13 01:27:42.037] [info]    
[2020-06-13 01:27:42.038] [info]    [ffmpeg] [libx264 @ 0x7f5a7a596400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[2020-06-13 01:27:42.038] [info]    
[2020-06-13 01:27:42.053] [warning] Assertion Failed: counter < 8 file:/source/core/consumer/frame_consumer.cpp line:93 
[2020-06-13 01:27:42.061] [info]    [ffmpeg] [libx264 @ 0x7f5a7a596400] profile High 4:2:2, level 4.2, 4:2:2 8-bit
[2020-06-13 01:27:42.061] [info]    
[2020-06-13 01:27:42.062] [info]    [ffmpeg] [Parsed_pan_0 @ 0x7f5a7a58b940] Pure channel mapping detected:
[2020-06-13 01:27:42.062] [info]    [ffmpeg]  0
[2020-06-13 01:27:42.062] [info]    [ffmpeg]  1
[2020-06-13 01:27:42.062] [info]    [ffmpeg] 
[2020-06-13 01:27:42.062] [info]    
[2020-06-13 01:27:43.579] [warning] [ffmpeg] [flv @ 0x7f5a7a597900] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[2020-06-13 01:27:43.579] [warning] 
[2020-06-13 01:27:43.579] [error]   [ffmpeg] [flv @ 0x7f5a7a597900] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 40 >= NOPTS
[2020-06-13 01:27:43.579] [error]   
[2020-06-13 01:27:43.579] [error]   Exception: /source/modules/ffmpeg/consumer/ffmpeg_consumer.cpp(602): Throw in function caspar::ffmpeg::ffmpeg_consumer::initialize(const caspar::core::video_format_desc&, int)::<lambda()>::<lambda()>::<lambda()> mutable
[2020-06-13 01:27:43.579] [error]   Dynamic exception type: boost::exception_detail::clone_impl<caspar::ffmpeg::ffmpeg_error_t>
[2020-06-13 01:27:43.579] [error]   [caspar::tag_stacktrace_info*] =  0# caspar::stacktrace_info() in bin/casparcg
[2020-06-13 01:27:43.579] [error]    1# caspar::detail::scope_exit<caspar::ffmpeg::ffmpeg_consumer::initialize(caspar::core::video_format_desc const&, int)::{lambda()#1}::operator()() const::{lambda()#4}::operator()() const::{lambda()#1}>::~scope_exit() in bin/casparcg
[2020-06-13 01:27:43.579] [error]    2# caspar::ffmpeg::ffmpeg_consumer::initialize(caspar::core::video_format_desc const&, int)::{lambda()#1}::operator()() const::{lambda()#4}::operator()() const in bin/casparcg
[2020-06-13 01:27:43.579] [error]    3# 0x00007F5D5C84D6DF in /usr/lib/x86_64-linux-gnu/libstdc++.so.6
[2020-06-13 01:27:43.579] [error]    4# 0x00007F5D5559A6DB in lib/libpthread.so.0
[2020-06-13 01:27:43.579] [error]    5# clone in /lib/x86_64-linux-gnu/libc.so.6
[2020-06-13 01:27:43.579] [error]   
[2020-06-13 01:27:43.579] [error]   [boost::errinfo_errno_*] = 0, "Success"
[2020-06-13 01:27:43.579] [error]   [boost::errinfo_api_function_*] = avio_closep(&oc->pb)
[2020-06-13 01:27:43.579] [error]   
[2020-06-13 01:27:43.579] [error]    0# caspar::log::get_stack_trace[abi:cxx11]() in bin/casparcg
[2020-06-13 01:27:43.579] [error]    1# caspar::detail::scope_exit<caspar::ffmpeg::ffmpeg_consumer::initialize(caspar::core::video_format_desc const&, int)::{lambda()#1}::operator()() const::{lambda()#4}::operator()() const::{lambda()#1}>::~scope_exit() in bin/casparcg
[2020-06-13 01:27:43.579] [error]    2# caspar::ffmpeg::ffmpeg_consumer::initialize(caspar::core::video_format_desc const&, int)::{lambda()#1}::operator()() const::{lambda()#4}::operator()() const in bin/casparcg
[2020-06-13 01:27:43.579] [error]    3# 0x00007F5D5C84D6DF in /usr/lib/x86_64-linux-gnu/libstdc++.so.6
[2020-06-13 01:27:43.579] [error]    4# 0x00007F5D5559A6DB in lib/libpthread.so.0
[2020-06-13 01:27:43.579] [error]    5# clone in /lib/x86_64-linux-gnu/libc.so.6
[2020-06-13 01:27:43.579] [error]   
[2020-06-13 01:27:43.581] [error]   Exception: /source/modules/ffmpeg/consumer/ffmpeg_consumer.cpp(615): Throw in function caspar::ffmpeg::ffmpeg_consumer::initialize(const caspar::core::video_format_desc&, int)::<lambda()>::<lambda()>
[2020-06-13 01:27:43.581] [error]   Dynamic exception type: boost::exception_detail::clone_impl<caspar::ffmpeg::ffmpeg_error_t>
[2020-06-13 01:27:43.581] [error]   [caspar::tag_stacktrace_info*] =  0# caspar::stacktrace_info() in bin/casparcg
[2020-06-13 01:27:43.581] [error]    1# caspar::ffmpeg::ffmpeg_consumer::initialize(caspar::core::video_format_desc const&, int)::{lambda()#1}::operator()() const::{lambda()#4}::operator()() const in bin/casparcg
[2020-06-13 01:27:43.581] [error]    2# 0x00007F5D5C84D6DF in /usr/lib/x86_64-linux-gnu/libstdc++.so.6
[2020-06-13 01:27:43.581] [error]    3# 0x00007F5D5559A6DB in lib/libpthread.so.0
[2020-06-13 01:27:43.581] [error]    4# clone in /lib/x86_64-linux-gnu/libc.so.6
[2020-06-13 01:27:43.581] [error]   
[2020-06-13 01:27:43.581] [error]   [boost::errinfo_errno_*] = 22, "Invalid argument"
[2020-06-13 01:27:43.581] [error]   [boost::errinfo_api_function_*] = av_interleaved_write_frame(oc, pkt.get())
[2020-06-13 01:27:43.581] [error]   
[2020-06-13 01:27:43.581] [error]    0# caspar::log::get_stack_trace[abi:cxx11]() in bin/casparcg
[2020-06-13 01:27:43.581] [error]    1# caspar::ffmpeg::ffmpeg_consumer::initialize(caspar::core::video_format_desc const&, int)::{lambda()#1}::operator()() const::{lambda()#4}::operator()() const in bin/casparcg
[2020-06-13 01:27:43.581] [error]    2# 0x00007F5D5C84D6DF in /usr/lib/x86_64-linux-gnu/libstdc++.so.6
[2020-06-13 01:27:43.581] [error]    3# 0x00007F5D5559A6DB in lib/libpthread.so.0
[2020-06-13 01:27:43.581] [error]    4# clone in /lib/x86_64-linux-gnu/libc.so.6
[2020-06-13 01:27:43.581] [error]

The last line is actualy without any text after [error].

I also tried streaming without specifying -codec:v after seeing many posts recommening it on this forum. I got it streaming, but the quality is just ugly and many servers which create HLS from rtmp are not accepting this stream, and are only playing audio.

I also have problem authenticating with rtmp servers requiring it. When using rtmp://$username:$password@$fqdn/… it shows, that domain name $username was not found. When trying command with pubUser=$username pubPasswd=$password it seems it just ignores these parameters.

Any ideas on these issues?
Before somebody posts something like “just use Google search”, “look into ffmpeg documentation”, or “look at the discussions about this on this forum” please note that I’ve just spent almost 2.5 days doing just that. Also it seems that the problems aren’t that much related to ffmpeg as everything works absolutely fine when streaming with pure ffmpeg.
Thank you in advance.

Just output to udp://127.0.0.1:1234 from Caspar and pickit up with ffmpeg on the same machine “ffmpeg -i udp://127.0.0.1:1234 -c:v copy -c:a copy -f flv rtmp…”

1 Like

This hack actually works. Thank you! There is still a small problem tho, I’ve got my hexa core i5 ussage at 100%. I’ll try on PC actually built for streaming, when I will be back at work.

For me it didn’t work with codec copy however so the commands I used were
ADD 1 STREAM udp://127.0.0.1:1234 -codec:a aac -strict -2 -b:a 128k -ar:a 48000 -b:v 6000k -filter:v format=pix_fmts=yuv444p,scale=1920x1080,fps=25 -filter:a pan=stereo|c0=c0|c1=c1 -format mpegts for CasparCG, and ffmpeg -i udp://127.0.0.1:1234 -c:v libx264 -c:a aac -b:v 6000k -b:a 128k -f flv rtmp://$server/$application/$stream for ffmpeg

EDIT: In this post I didn’t use the -codec:v libx264 in CasparCG, but even with that, the -c:v copy didn’t work. It is saying “no frame!”.

Is it erroring out on no frame, or just waiting for a keyframe to arrive before continuing? Try adding “-copyinkf” after “-c:v copy”

Tried, and still got the same error

[h264 @ 0x55b9e88a3e60] decode_slice_header error
[h264 @ 0x55b9e88a3e60] no frame!
[h264 @ 0x55b9e88a3e60] non-existing PPS 0 referenced

These problems didn’t appear when I used tcp instead of udp. However the rtmp stream isn’t readable anyway. The weird thing is it has q=-1 in log.
frame= 7755 fps= 25 q=-1.0 size= 231788kB time=00:05:10.20 bitrate=6121.1kbits/

With using tcp and forcing reencoding to libx264 and aac, the result actually looks great. Is there any serious limitation with tcp, that I should be aware of?

Hello, now it seems like I had to do something wrong. The -codec:v copy works if tcp is used.
Now I’m trying to find solution to another problem. I cannot force CasparCG to output the stream interlaced. In ffmpeg, I do it with -x264-params interlaced=1 -filter:v setfield=tff. I have already tried -filter:v tinterlace and fieldorder with various combinations. I have also tried defining interl=1 in scale video filter. The streaming PC is powerfull enough to keep up with two encodings, but I’d like to avoid the loss of quality.

CCG 2.2+ does everything progressive internally. Why would you want interlaced on RTMP?

Because the stream is for HbbTV “extra” channel going through distributor’s CDN, and the distributor wants the stream to be interlaced. Also TVs are good at deinterlacing, so why not to save bitrate while still having fluent movements.

The x264 encoder is actually less efficient when doing interlaced. It is in general recommend to only use that if the receiving device does not support progressive inputs for some reason.

About sending an interlaced stream from CasparCG… I believe " -x264-params" is not a recognised option by CasparCG. Because it uses the “-” as a delimiter it ends up being parsed incorrectly, you might have better luck using “-x264opts” Iirc.

Do you mean I would have better picture with 1080p50, than 1080i50 with the same bitrate (6Mbps)?

I have already tried x264opts too, but getting [warning] ffmpeg[tcp://127.0.0.1:5000] Unused option x264opts=interlaced=1

If someone was wondering about commands I use now (almost complete workaround, but not supporting interlace), I’m putting them here:
ffmpeg:
ffmpeg -i tcp://127.0.0.1:5000?listen -codec:v copy -codec:a copy -f flv rtmp://$user:$password@$fqdn:1935/$app/$stream
CasparCG:
ADD 1 STREAM tcp://127.0.0.1:5000 -codec:v libx264 -preset:v faster -codec:a aac -strict -2 -b:a 128k -ar:a 48000 -b:v 6000k -filter:v format=pix_fmts=yuv420p,fps=25 -filter:a pan=stereo|c0=c0|c1=c1 -format mpegts
Big thanks especially to @hreinnbeck as this is based on his first reply.
I’m using ffmpeg 4.3.2, CasparCG 2.3 beta1 and Ubuntu 18.04.4

Hello,

I’m writing another update with some tips if someone was trying to do what I’m doing.

We switched to 25p for now.

-x264opts actually works, but you have to specify :v suffix.

It is good to limit maximum bitrate, otherwise ffmpeg is having quite variable bitrate, that could lead to buffer overflow at the receiving end. You can do it with e.g. -maxrate:v 6500k -bufsize:v 2000k.

If the stream is converted to a different format at the other end, you should specify keyint in x264opts. The HLS that the stream is being converted to, has 4s long segments, so I specified keyint=50, that is 2s (HLS is not the only format it is converted to, but it was most used for testing).

I added -re parameter in ffmpeg comand. It is generally not recommended for live sources, but in this case, it sends too many frames when the stream starts without it. That could lead to problems on the receiving end.

hi i had the same problem as you for video sending like i sended the video as 1920x1080 via rtmp to youtube but it was not the quality i exprected its like half worst so i did some research in the code and saw the default screen was 720x576 i was very confused and did not know what to do if it has something to do with that bad quality or something and when i saw you’r post i think its what i need but the problem is i dont know anything about coding and would like to know if its possible for you make a full rtmp example code for 1920x1080p

other question if possible can you do it in h265
thank you

I had the same problem today.
I solved it by adding the parameter -format flv to the ffmpeg-args.