arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.35k stars 3.51k forks source link

video does not stream locally. #200

Closed p10tyr closed 11 years ago

p10tyr commented 11 years ago

I compile nginx 1.4 with your module on the Raspberry Pi.

I can send rtmp (ffmpeg) data to an external server that uses crtmp-server. When ever I stop and start a player it takes a few seconds and the video plays live video fine. (but it needs to use psips patch)

So then I change the ffmpeg destination to the Raspberry. When I press play on player and then start ffmpeg the local player will show video stream fine. As soon press stop and press play it does not stream. I have to stop ffmpeg and start it again- then the player will instantly start to show video.

This is somewhat strange because I added push to external the crtmp-server in the live app. So I start ffmpeg to local Pi nginx stream. The player using remote rtmp stream can start and stop without any issues. But the player using raspberries rtmp stream just dies.

When looking at the stat it shows the video stats; ffmpeg does not report errors; the remote stream can stop and start at will but the local one just wont play after I stopped it.

I have been using osmf strobe meida player. The local stream is hosted on raspberry and the remote stream on a proper server. I open both url's side by side with the exact same versions of the player - just different stream source.

The script I use to pipe the camera module stream is ...

#!/bin/bash  
 urllocal="rtmp://localhost/myapp/mystream"  
 fifo="live.fifo.h264"  
 rm -f "$fifo"  
 mkfifo "$fifo" 

 #this uses the patched version of raspivid with infinite time and -g option  
 raspivid \  
  -fps 25 -g 100 \  
  -t 0 -b 3500000 -o "$fifo" & 

 ffmpeg -y \  
  -f h264 \  
  -i "$fifo" \  
  -c:v copy \  
  -map 0:0 \  
  -f flv "$urllocal"   

At the moment in the log file I found this peculiar line. When I press play the omsf debugger shows me that it is downloading something.... very slowly but it does not recognise a stream. I leave it and after a while it just shows some random error number and this shows up in the log.

2013/06/11 20:20:20 [info] 2447#0: *36 client connected '192.168.1.100'
2013/06/11 20:20:20 [info] 2447#0: *36 connect: app='myapp' args='' flashver='WIN 11,7,700,203' swf_url='http://192.168.1.104/osmf/StrobeMediaPlayback.swf' tc_url='rtmp://192.168.1.104:193
5/myapp' page_url='http://192.168.1.104/osmf/debug.html' acodecs=3575 vcodecs=252 object_encoding=3, client: 192.168.1.100, server: 0.0.0.0:1935
2013/06/11 20:20:20 [info] 2447#0: *37 client sent invalid method while reading client request line, client: 192.168.1.100, server: localhost, request: "..©S"....éH.W.M.Õ¶1.äé°òã}. .àWA¤d..a.lù¶?Ã6þE.¹ª(>{Ã"
2013/06/11 20:20:20 [info] 2447#0: *32 disconnect, client: 192.168.1.100, server: 0.0.0.0:1935

I am recompiling now with the debug option. Hopefully I can find something more.

p10tyr commented 11 years ago

I recompiled with debug it and changed worker processes to 1.

It seams to work locally now... Not sure if it was the worker processes or something corrupt on the Pi.

arut commented 11 years ago

Great! This error client sent invalid method is produced by nginx HTTP (not RTMP). It look like you send RTMP data to HTTP port.

BTW please try adding wait_video on to rtmp configuration. That might solve the problem of client hanging.

p10tyr commented 11 years ago

Now the remote stream does not work at all? I also put in the wait_video and did not change anything - I have no sound just video so I don't think that will do much?

p10tyr commented 11 years ago

I stopped it all. Deleted the log and started nginx service. Started ffmpeg and waitied till fps shows. Refreshed local client it connects and plays OK now. Refreshed for remote stream push.. blank- no error on player. Stopedd nginx. Here is the log- It is massive...

http://pkula.no-ip.org/public/errord.txt

p10tyr commented 11 years ago

Roman- I left it running all night and this morning both streams work. There is one issue though. The external stream has artefacts. When viewing side by side (local vs remote) the local is nice and smooth the remote is artefact. I have a 20MB upload and the stream bitrate is 3000kb/s. The remote server is using crtmp-server. Do you think If I compiled nginx with your module on the remote server it would work better? (As a side note- when I stream rtmp direct to the external server bypassing your module (just ffmpeg url) with the exact same setting there are no artefacts and streams well) This is the external page that reads the external feed (pushed by the Pi- Nobody is watching the feed locally) http://www.pku.la/

arut commented 11 years ago

I have no sound just video so I don't think that will do much?

it does it sends empty audio frame to prevent client from waiting audio

arut commented 11 years ago

what do you mean artefacts?

p10tyr commented 11 years ago

So if the source feed has no audio. the rtmp module will still send empty audi frame to prevent delay?

Artifacts- like parts of the image freezing up until a keyframe is received and the whole image is refreshed. Like if a person is walking it leaves a shadow of him behind for 2,3 seconds, then keyframe the picture is clear- repeats over and over. Or sometimes strange squares shadow showing up in random places (you know like very bad internet connection on skype/satellite signal)

OK- You might say slow internet. But I have 20mb upload to 100MB/100MB server. When I use push from rtmp-module to Ubuntu(crtmp) this happens.

When I use ffmpeg direct to Ubuntu(crtmp) the picture is always very clear.

So I tried to change the local bitrate, frame size, fps for rtmp-module. It does -not- make a difference. There is always artifacts from pushed stream? You can see it now on http://pku.la - Make it full screen and watch the water or trees.

Local stream is very clean and does not do this.

arut commented 11 years ago

So if the source feed has no audio. the rtmp module will still send empty audi frame to prevent delay?

exactly

As for artifacts they may appear when frames are dropped. Please set up /stat location and watch your connections (both publisher and player) for dropped frames.

p10tyr commented 11 years ago

Here is a side by side. Left is Local and right if from remote stream. I noticed the artefacts got really bad when I started watching the local stream...

image

arut commented 11 years ago

Here is a side by side. Left is Local and right if from remote stream. I noticed the artefacts got really bad when I started watching the local stream...

but how did you see them before?

p10tyr commented 11 years ago

That is real time. I have two monitors. First site is on nginx html using feed from 192.168.1.104 (left) Second site is on IIS html using feed from internet IP (right)

Take screen shot of the same feed at once:

(left) rtmp -> browser [LAN]

(right) rtmp ->push to wan server -> comes back to local browser [WAN]

When only using ffmpeg to WAN this problem does not happen. Also when no client is watching local (lan) then remote (wan) is much better when using push in rtmp-module.

arut commented 11 years ago

I've read about Raspberry Pi camera. So I have the questions for you

Artifacts should have been caused by network problems. I'll fix nginx-rtmp to show real dropped frames number in stat (now it shows dropped timestamp gaps which are zeroed after stream sync, not very useful)

p10tyr commented 11 years ago

I used psips to stream video direct into VLC using UDP broadcast form ffmpeg- Without it there are no keyframes and the video never starts. With your module rtmp I never use PSIPS because your module does all the stuff inside already. psips is aslo used to make HLS frames when using raspivid segmentation only(because raspivid does not make these frames) and using ffmpeg there is no hardware acceleration yet on the Pi :(

But now the video does not fail- it has been running for 3~4 days. Only when I start the stream there is not video on the external feed? I wait a few hours and it is OK.

Artifacts do not show when I send stream direct to external server- using psips or not it is very good. These artifacts only show when I watch local stream from LAN, then another computer from the internet using external feed from nginx-rtmp gets some artifacts.

When I do not watch local stream using LAN the external is OK.

towolf commented 11 years ago

I don’t want to get too off-topic, so I’ll mention that I see no corruptions so far.

What I don’t understand is that I run a very similar setup to Mr @ppumkin (only under Arch Linux with 1.4.1 and ffmpeg 1.2.1) and while he reports single digit CPU usage I get a pegged CPU equally shared between the ffmpeg process and nginx process.

Any idea where this could come from? I even recompiled with the same options he used.

arut commented 11 years ago

What's the number of workers?

towolf commented 11 years ago

workers = 1

I have a hunch now that @ppumkin might be using ffmpeg internal rtmp and I compiled with librtmp. You think that might make a difference? Takes 2-3 hours to recompile ...

arut commented 11 years ago

If you try that we'll know :)

towolf commented 11 years ago

Compiling ...

By the way, I’ve discovered the recorder features and they are way cool!

With the raspberry suggested streaming solutions you always had to choose: Do I want RTMP, do I want HLS, do I want a timelapse? With your module one can get all in one.

My question about record keyframes is, would there be a chance to override the output fps?

I’ve configured fps=25 and gop=100, so with record keyframes I get 0.25 fps. If I want to misuse(?) this feature to also create timelapses on the fly could this value be overridden? Should I file another issue?

towolf commented 11 years ago

Bingo! I’ve got it down to 10-20% CPU total by using internal rtmp protocol.

p10tyr commented 11 years ago

Everything seems to be stable. I still get these weird artefacts from time to time. But to be honest I will not be pushing the stream in my end application so its not a major concern for me. But I will be interested in any commits that you make with the dropped frames stats. Thanks for the great work!

PS- Where do I donate?? I have been looking around. Do you work for a company? How is this funded?

arut commented 11 years ago

BTW I've ordered Raspberry Pi and I'm going to set up streaming stuff on it.

p10tyr commented 11 years ago

You need to put more links to this donation site. I have never seen it when reading your blogsm wikis or on github... I am sure more people will donate if they can see the link (also put in a Bitcoin/Litecoin address - that is really popular for donations now a days).

Enjoy the Raspberry. It is quite a nice piece of hardware :) :+1: