server
server copied to clipboard
ffmpeg customer stream to rtmp doesn't work with Twitch
Hi, When I try to stream CasparCG output to Periscope (twitter), audio is ok but video is absent. Everything was correct with CasparCG 2.0.7 but not with CasparCG V2.2 and V2.3.
Steps to reproduce
With CasparCG 2.0.7, following command is OK (video and audio are correct on Periscope preview):
ADD 1-9003 STREAM rtmp://fr.pscp.tv:80/x/<STREAMKEY> -codec:v libx264 -filter:v format=yuv420p,scale=960:540 -level:v 3.0 -profile:v main -preset:v veryfast -maxrate:v 800k -b:v 800k -bufsize:v 800k -x264opts:v keyint=60 -codec:a aac -ar:a 48k -b:a 88k -strict -2 -f flv
With FFMPEG 4.2.2 (libavcodec 58. 54.100), this batch is OK as well:
ffmpeg -re -i myvideo.mp4 -codec:v libx264 -filter:v format=yuv420p,scale=960:540,fps=30 -level:v 3.0 -profile:v main -preset:v veryfast -maxrate:v 800k -b:v 800k -bufsize:v 800k -x264opts:v keyint=60 -bf:v 30 -codec:a aac -ar:a 48k -b:a 88k -strict -2 -f flv rtmp://fr.pscp.tv:80/x/<STREAMKEY>
but with CasparCG V2.3, there is no video on Periscope preview:
ADD 1-9003 STREAM rtmp://fr.pscp.tv:80/x/<STREAMKEY> -codec:v libx264 -filter:v format=yuv420p,scale=960:540,fps=30 -level:v 3.0 -profile:v main -preset:v veryfast -maxrate:v 800k -b:v 800k -bufsize:v 800k -x264opts:v keyint=60 -bf:v 30 -codec:a aac -ar:a 48k -filter:a pan=stereo|c0=c0|c1=c1 -b:a 88k -strict -2 -format flv
Could it be because CasparCG doesn't send framerate in rtmp video header ?
Environment
- Commit: 94db7f22 Dev
- Server version: v2.3.0
- Operating system: Windows 10
- GPU : NVIDIA GeForce GTX 1050
- channel Configuration is 720p3000.
Hi, Do you need more informations for this issue ? The same behavior appears when I try to stream out to Twitch
I can confirm that I'm having the same issue with server versions >2.2.x. Using 2.0.7, the video information are available but not with >2.2.x (haven't tried 2.1)
This is what the RTMP server sees when using 2.0.7:
"publisher": {
"app": "live",
"stream": "1",
"clientId": "7PJ0QKG1",
"connectCreated": "2020-06-20T11:56:03.755Z",
"bytes": 1217167,
"ip": "::ffff:172.21.5.200",
"audio": {
"codec": "AAC",
"profile": "LC",
"samplerate": 48000,
"channels": 2
},
"video": {
"codec": "H264",
"width": 1280,
"height": 720,
"profile": "High",
"level": 3.1,
"fps": 30
}
And this is when using 2.2/2.3:
"publisher": {
"app": "live",
"stream": "1",
"clientId": "E0YRA1IU",
"connectCreated": "2020-06-20T12:09:20.077Z",
"bytes": 117094,
"ip": "::ffff:172.21.5.200",
"audio": {
"codec": "AAC",
"profile": "LC",
"samplerate": 44100,
"channels": 2
},
"video": {
"codec": "H264",
"width": 0,
"height": 0,
"profile": "",
"level": 0
}
Some decoders need the size and frame rate information to accept the stream (etc. gstreamer and ccg itself) but ffmpeg can find that by parsing the stream.
My workaround is to re-stream the feed using ffmpeg but to make ffmpeg insert the information I have to re-encode the stream which of course consumes unnecessary resources and introduces more latency.
From recent post in the forum a FFMPEG bug is suspected. Can anybody check that an issue a bug in FFMPEG's repository if that is the case?
I don't think it's a FFMPEG issue because when I try to stream with FFMPEG only (the same version) it works fine.
Did anyone fix this, I think I am seeing the same thing on twitch.
Hi, Even if Periscope ends at end of march, the issue still the same for Twitch for example. I've just tested it with last CasparCG build (2.3.1 december 15th 2020)
Yes, this is an issue with rtmp endpoints in general with casparcg. I notice the same thing when streaming direct with ffmpeg only.
I'm surprised that you have the same problem with ffmpeg directly. Because I try again with directly with ffmpeg. And there is no problem: Twitch get the framerate given in ffmpeg parameters. And video is OK on Twitch :
ffmpeg -re -i MYVIDEO.mp4 -codec:v libx264 -filter:v format=yuv420p,scale=960:540,fps=30 -level:v 3.0 -profile:v main -preset:v veryfast -maxrate:v 800k -b:v 800k -bufsize:v 800k -x264opts:v keyint=60 -bf:v 30 -codec:a aac -filter:a pan=stereo|c0=c0|c1=c1 -ar:a 48k -b:a 88k -strict -2 -f flv rtmp://live.twitch.tv/app/<STREAMKEY>
@STL1811 What I meant to say was I’m observing the same thing you are seeing where ffmpeg directly works fine but in Caspar it does not.
"-filter:v" should be "-vf"
@medcelerate So, we notice the same behaviour.
@hreinnbeck
"-filter:v" should be "-vf"
There is no change with "-vf"
any updates on this issue?
Anyone was able to fix this ?Kindly help.
If anyone facing this issue i've found a fix. add -flags:v +global_header arg when adding RTMP stream this will enable individual stream headers required for FLV.
Technically this should be added based on the Muxer we use but there is code bug in CarparCG where we open the encoder before setting AV_CODEC_FLAG_GLOBAL_HEADER flag.
FF(avcodec_open2(enc.get(), codec, &dict));
...
...
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
enc->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
Which should be like
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
enc->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
FF(avcodec_open2(enc.get(), codec, &dict));
Older casparcg has this sequence so it's working @ronag @Julusian can you guys patch this up in 2.3.x lts? it might help other people who are facing this RTMP bug
Thank you @sreekanthjbjn !
when I move setting enc->flags
before avcodec_open2
in ffmpeg_consumer.cpp, I can see stream header in Twitch Inspector and stream is visible in Twitch.
Hi, Actually it still 1 issue in RTMP global header : framerate is missing. Using Caspar 2.0.7, header contains : audiocodecid:10 audiodatarate:86.9140625 audiosamplerate:44100 audiosamplesize:16 duration:0 encoder:Lavf55.33.100 filesize:0 framerate:25 height:720 stereo:true videocodecid:7 videodatarate:2441.40625 width:1280 Using Caspar 2.3, header contains : audiocodecid:10 audiodatarate:125 audiosamplerate:48000 audiosamplesize:16 duration:0 encoder:Lavf58.29.100 filesize:0 height:1080 stereo:true videocodecid:7 videodatarate:4394.53125 width:1920.
Do you know the way to add framerate to this header. I try to compare Caspar 2.0.7 an Caspar 2.3 source code, but I can't find it. Thank you for your help.