RTMP stream framerate continually drops

Questions involving a Windows version of FFmpeg.
rogerdpack
Posts: 1877
Joined: Fri Aug 05, 2011 9:56 pm

Re: RTMP stream framerate continually drops

Post by rogerdpack » Mon Feb 11, 2013 5:19 pm

so tcp relay does speed it up for you?

This was ffsplit's response; http://www.ffsplit.com/forums/showthrea ... mpeg-alone
basically they're kind of doing what tcp relay itself does. Interesting, eh?

I saw a patch once for ffmpeg's internal rtmp that would send buffered output, that, again, supposedly sped things up quite a bit (though no one has gotten back to me to work it out precisely yet I'd love to work with somebody on it).

siri
Posts: 2
Joined: Thu Feb 07, 2013 1:05 pm

Re: RTMP stream framerate continually drops

Post by siri » Wed Feb 13, 2013 11:45 am

Would you please send me a link to that ffmpeg patch you've mentioned? I would very appreciate it, If you can find it.
Thanks.

rogerdpack
Posts: 1877
Joined: Fri Aug 05, 2011 9:56 pm

Re: RTMP stream framerate continually drops

Post by rogerdpack » Wed Feb 13, 2013 10:01 pm

siri wrote:Would you please send me a link to that ffmpeg patch you've mentioned? I would very appreciate it, If you can find it.
Thanks.
http://lists.mplayerhq.hu/pipermail/ffm ... 32017.html
(NB this should improve speeds for ffmpeg's internal rtmp stuff, i.e. you have to configure and build it *without* librtmp for this approach to work. Also I'm pretty sure it doesn't apply cleanly to trunk...I could work on cleaning it up sometime if you'd like...)

FluxAureo
Posts: 1
Joined: Thu Aug 15, 2013 12:55 am

Re: RTMP stream framerate continually drops

Post by FluxAureo » Thu Aug 15, 2013 1:03 am

Hi there. Sorry to necro this old thread.

I read the whole post. Recently, I tried to stream to twitch.tv using ffmpeg and have the fps drop problems here mentioned. Is the problem asociated with the TCP connection then? Could I set a local server then forward my capture to Twitch?

My OS is Lubuntu,so I could do the valgrind memory dump that roger requested, 1 year ago.

hamletmun
Posts: 2
Joined: Wed Oct 09, 2013 5:48 pm

Re: RTMP stream framerate continually drops

Post by hamletmun » Wed Oct 09, 2013 5:53 pm

Try increasing SO_RCVBUF and SO_SNDBUF through Windows Registry.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AFD\Parameters]
"DefaultReceiveWindow"=dword:00010000
"DefaultSendWindow"=dword:00010000

rogerdpack
Posts: 1877
Joined: Fri Aug 05, 2011 9:56 pm

Re: RTMP stream framerate continually drops

Post by rogerdpack » Fri Oct 11, 2013 4:04 pm

FluxAureo wrote:Hi there. Sorry to necro this old thread.

I read the whole post. Recently, I tried to stream to twitch.tv using ffmpeg and have the fps drop problems here mentioned. Is the problem asociated with the TCP connection then? Could I set a local server then forward my capture to Twitch?

My OS is Lubuntu,so I could do the valgrind memory dump that roger requested, 1 year ago.
What OS? What did you switch from that seemed to be a drop?

speaker219
Posts: 3
Joined: Sat Jun 15, 2013 7:21 am

Re: RTMP stream framerate continually drops

Post by speaker219 » Fri Oct 25, 2013 3:17 am

Not exactly the same problem being discussed here, but has anyone noticed bandwidth spiking in ffmpeg when streaming to an RTMP server? (The above registry fix causes ffmpeg to work, TCPrelay also works but exhibits the same behavior).

For example -- ffmpeg shows a steady bitrate, 3000kbps, but the actual network output drops down to ~1600, occasionally skyrockets to 6000+ kbps, and then levels out for a while, and exhibits the same behavior again.

This is not an issue with routing to the host, as streaming using Wirecast or FMLE to the same RTMP server does not exhibit the wild bandwidth fluctuations.

Anyone have an idea as to what may cause this or possibly a fix?

ctetrick
Posts: 9
Joined: Wed Dec 31, 2014 8:08 pm

Re: RTMP stream framerate continually drops

Post by ctetrick » Tue Jan 06, 2015 7:26 pm

FluxAureo wrote:Hi there. Sorry to necro this old thread.

I read the whole post. Recently, I tried to stream to twitch.tv using ffmpeg and have the fps drop problems here mentioned. Is the problem asociated with the TCP connection then? Could I set a local server then forward my capture to Twitch?

My OS is Lubuntu,so I could do the valgrind memory dump that roger requested, 1 year ago.
I'm not afraid to necro this thread. :D

I've been looking at this for awhile now and I think I've at least narrowed some things down.

First, some observations:
Steaming to a local sever is fine.
Streaming to a twitch.tv server with low ping time is fine.
Streaming to a twitch.tv server with large ping time exhibits the frame rate drop.
Using a TCP Relay makes even a long ping server work.

There's a possible fix in librtmp:

In RTMP_SendPacket() [rtmp.c - in librtmp lib] I find something like this: (Psuedo code)

Code: Select all

if( protocol is HTTP )
{
  calculate number of chunks;
  if ( num chunks > 0 )
  {
    calculate size of buffer required;
    allocate buffer;
  }
}
while( data to be written )
{
  if ( have buffer )
  {
    copy chunk to buffer;
  }
  else
  {
     writeN(rtmp_context, source_data, chunk_len);
  }
    ...
  calculate next chunk;
}
if( have buffer )
{
  WriteN(rtmp_context, buffer, buffer_size);
}
The actual code in question:

Code: Select all

  /* send all chunks in one HTTP request */
  if (r->Link.protocol & RTMP_FEATURE_HTTP) 
  {
    int chunks = (nSize+nChunkSize-1) / nChunkSize;
    if (chunks > 1)
    {
      tlen = chunks * (cSize + 1) + nSize + hSize;
      tbuf = malloc(tlen);
      if (!tbuf)
        return FALSE;
      toff = tbuf;
    }
  }


By making this change (or just eliminating the if altogether):

Code: Select all

  if ((r->Link.protocol & RTMP_FEATURE_HTTP) ||
      (packet->m_packetType == RTMP_PACKET_TYPE_VIDEO) ||
      (packet->m_packetType == RTMP_PACKET_TYPE_AUDIO))
The problem largely goes away.

BTW, I tried changing the socket send buffer size, but that doesn't seem to fix it.

This could be a Windows sockets specific problem, but I can't confirm that.

Question:
Since this is rtmpdump code, where do I get something submitted (Assuming this is an acceptable fix)?

ctetrick
Posts: 9
Joined: Wed Dec 31, 2014 8:08 pm

Re: RTMP stream framerate continually drops

Post by ctetrick » Fri Jan 16, 2015 9:56 pm

OK. in a previous comment I suggested changing the rtmp send function to use the available buffering.
While this may make things a bit more efficient, it's not the real problem.
I've added a couple of options to librtmp. One to turn the NO_TCPDELAY flag off, and another to set the socket output buffer size. (the first is experimental.) without the arguments behavior is unchanged. I'm hoping to get a patch into librtmp.

I think this explains a number of previous observations.
Windows 7 uses a default buffer of 8Kb, a friend's Linux installation uses 16k, and I've read that many Linux implementations use 128k.
This would explain why some users report better results on Linux.
This would explain why apps like TCPRelay help assuming it changes the buffering.
Users have suggested changing the default buffer size in Windows using the registry as well. But I think that's a bad idea since it is likely to affect other applications or use a great deal of ram if you set it too high.

rogerdpack
Posts: 1877
Joined: Fri Aug 05, 2011 9:56 pm

Re: RTMP stream framerate continually drops

Post by rogerdpack » Mon Jan 26, 2015 8:15 am

does TCP_NODELAY make a difference here?
Could you post a diff against the librtmp git master for me? Was this merged/submitted upstream?
Thanks.

Post Reply
'