google-code-export / rtmplite

Automatically exported from code.google.com/p/rtmplite
3 stars 1 forks source link

ffmpeg encoder connection: KeyError: 'objectEncoding' #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
On Ubuntu 10.10 I download rtmplite-6.0. I start the application...

python rtmp.py -d

On the same machine, I attempt to connect to it with a live rtmp stream from 
ffmpeg....

ffmpeg -i "/somevideo.vob" -re -vcodec libx264 -vpre default -b 500000 -s 
320x180 -strict experimental -g 25 -me_method zero -acodec aac -ab 96000 -ar 
48000 -ac 2 -b 500K -f flv  rtmp://127.0.0.1/live/livestream

I get the following output from rtmp.py...

connection received from ('127.0.0.1', 34624)
socket.read[23] calling recv()
socket.read[1537] 
"\x03\x00\x19\x160\x00\x00\x00\x00gE\x8bk\xc6#{2i\x98<dsH3fQ\xdc\xb0t\xff\\I\x19
J\x94\xe8*\xecXUb)\x1f\x8e#\xcd|\xe8F\xbaX\x1b=\xab\xd7~P\xf2A\xb1.\xfb\x1e\xb7A
\xe3\xa9\xe2yF\xe1Eu|\x00_Q\xc2b\xd0[T\x08 
\x12\xf8'\xb1M\x1b#\x16\x02\xe8\xe9\x16\x1f\xe7\xcd\x90...(1537)"
socket.write[1537] 
"\x03\x00\x19\x160\x00\x00\x00\x00gE\x8bk\xc6#{2i\x98<dsH3fQ\xdc\xb0t\xff\\I\x19
J\x94\xe8*\xecXUb)\x1f\x8e#\xcd|\xe8F\xbaX\x1b=\xab\xd7~P\xf2A\xb1.\xfb\x1e\xb7A
\xe3\xa9\xe2yF\xe1Eu|\x00_Q\xc2b\xd0[T\x08 
\x12\xf8'\xb1M\x1b#\x16\x02\xe8\xe9\x16\x1f\xe7\xcd\x90...(1537)"
socket.read[1536] calling recv()
socket.read[1536] 
"\x00\x19\x160\x00\x00\x00\x00gE\x8bk\xc6#{2i\x98<dsH3fQ\xdc\xb0t\xff\\I\x19J\x9
4\xe8*\xecXUb)\x1f\x8e#\xcd|\xe8F\xbaX\x1b=\xab\xd7~P\xf2A\xb1.\xfb\x1e\xb7A\xe3
\xa9\xe2yF\xe1Eu|\x00_Q\xc2b\xd0[T\x08 
\x12\xf8'\xb1M\x1b#\x16\x02\xe8\xe9\x16\x1f\xe7\xcd\x90\x11...(1536)"
socket.write[1536] 
"\x00\x19\x160\x00\x00\x00\x00gE\x8bk\xc6#{2i\x98<dsH3fQ\xdc\xb0t\xff\\I\x19J\x9
4\xe8*\xecXUb)\x1f\x8e#\xcd|\xe8F\xbaX\x1b=\xab\xd7~P\xf2A\xb1.\xfb\x1e\xb7A\xe3
\xa9\xe2yF\xe1Eu|\x00_Q\xc2b\xd0[T\x08 
\x12\xf8'\xb1M\x1b#\x16\x02\xe8\xe9\x16\x1f\xe7\xcd\x90\x11...(1536)"
socket.read[1] calling recv()
socket.read[97] 
'\x03\x00\x00\x00\x00\x00U\x14\x00\x00\x00\x00\x02\x00\x07connect\x00?\xf0\x00\x
00\x00\x00\x00\x00\x03\x00\x03app\x02\x00\x04live\x00\x04type\x02\x00\nnonprivat
e\x00\x05tcUrl\x02\x00\x15rtmp://127.0.0.1/live\x00\x00\t'
Protocol.parseMessage msg= <Message header=<Header channel=3 time=0 size=85 
type=20 streamId=0> 
data='\x02\x00\x07connect\x00?\xf0\x00\x00\x00\x00\x00\x00\x03\x00\x03app\x02\x0
0\x04live\x00\x04type\x02\x00\nnonprivate\x00\x05tcUrl\x02\x00\x15rtmp://127.0.0
.1/live\x00\x00\t'>
Traceback (most recent call last):
  File "rtmp.py", line 295, in parseMessages
    yield self.messageReceived(msg)
  File "/home/simonb/Documents/Source/rtmplite/multitask.py", line 963, in run_next
    output = task.send(input)
  File "/home/simonb/Documents/Source/rtmplite/multitask.py", line 182, in send
    return self.task.send(value)
  File "rtmp.py", line 611, in messageReceived
    self.objectEncoding = self.agent['objectEncoding']
KeyError: 'objectEncoding'
Protocol.parseMessages exception None
socket.read[1] calling recv()

Original issue reported on code.google.com by sblandf...@gmail.com on 4 Feb 2011 at 6:39

GoogleCodeExporter commented 9 years ago
It seems that ffmpeg doesn't send an expected value for objectEncoding. As a 
work around, I set it to 0.0 as a default.

Line 625 of rtmp.py version 0.7.
                if 'objectEncoding' in self.agent:
                  self.objectEncoding = self.agent['objectEncoding']
                else:
                  self.objectEncoding = 0.0

Now ffmpeg connects OK but I am unable to see the video coming back with the 
command...
rtmpdump -r rtmp://localhost/live/livestream -o - -v | ffplay

rtmpdump reports...

[h264 @ 0x1997a50]no frame!
[aac @ 0x1993ef0]channel element 1.0 is not allocated
    Last message repeated 1 times

Original comment by sblandf...@gmail.com on 6 Feb 2011 at 9:54

GoogleCodeExporter commented 9 years ago
I've also had no luck with ffmpeg playing out an rtmp stream to rtmplite.  

I did get the included rtmpclient.py to dump a local video to the server using:
{{{
 python rtmpclient.py test.flv "rtmp://127.0.0.1/live?id=testStream"
}}}
I could then watch the video using the included testClient.swf from my browser.

However, I've not had any luck with ffmpeg playing from or streaming video to 
the server... I've just updated to the latest ffmpeg version as described 
below, which at least could 'connect' to the server and get it to print out 
debugging messages for receiving data on the correct port... 

Streaming to server from ffmpeg command:
{{{
 ffmpeg -i test.flv -re -f flv rtmp://127.0.0.1/live?id=testStream
}}}
This hangs in the "Handshake" portion, perhaps 

Playing video from the server command:
{{{
 ffplay "rtmp://127.0.0.1/live?id=testStream live=1"
}}}
This gives me the error "Cannot read RTMP handshake response"

I've also tried the same experiment using a different piece of python rtmp 
server software called "rtmpy" with even less success.  Though it complains 
about FCPublish?  From ffmpeg code it says: "'FCPublish' call and send it to 
the server. It should make the server preapare for receiving media streams."

I don't know too much about the rtmp protocol, but my gut feeling is that 
ffmpeg needs some sort of ack from the server before it actually starts to 
stream the data... I can tell that it never starts, because the server debug 
spews data when it is working with the included demo programs, but it never 
spews debug data from ffmpeg.

I'm not sure how to complete the 'handshake' to make ffmpeg happy, but perhaps 
I'll look into it... Or just look into red5 or wowza...

-John

------------
FFmpeg version git-b466827, Copyright (c) 2000-2011 the FFmpeg developers
  built on Feb 10 2011 11:25:21 with gcc 4.4.1
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvorbis --enable-libx264 --enable-libxvid --enable-x11grab --enable-libmp3lame
  libavutil    50. 37. 0 / 50. 37. 0
  libavcore     0. 16. 1 /  0. 16. 1
  libavcodec   52.112. 0 / 52.112. 0
  libavformat  52. 98. 0 / 52. 98. 0
  libavdevice  52.  2. 3 / 52.  2. 3
  libavfilter   1. 75. 0 /  1. 75. 0
  libswscale    0. 12. 0 /  0. 12. 0
  libpostproc  51.  2. 0 / 51.  2. 0
-----------

Original comment by leimg...@gmail.com on 10 Feb 2011 at 5:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,

I did a quick experiment to find that ffmpeg didn't accept the AMF0 encoded 
packet for onStatus with code=NetStream.Publish.Start. Note that rtmplite only 
supports AMF0.

I will keep this issue open, so that can keep track of progress on 
transitioning to AMF3.

(Two changes I had to do for getting connect working with ffmpeg will be 
checked in soon: send both handshake packets instead of waiting for reply from 
client, and ignore missing "objectEncoding" in connect.)

Original comment by voiprese...@gmail.com on 11 Feb 2011 at 1:50

GoogleCodeExporter commented 9 years ago

Original comment by voiprese...@gmail.com on 11 Feb 2011 at 1:53

GoogleCodeExporter commented 9 years ago
As it turns out, the problem was not related to AMF3 but the following:

1. Handshake needs to send all the data from server before waiting for next 
ping from ffmpeg.
2. Server should use Object instead dict (EcmaArray) for various notifications 
such as NetStream.Publish.Start.
3. Treat a missing objectEncoding as value of 0.0 (for AMF0).

Original comment by voiprese...@gmail.com on 14 Feb 2011 at 6:21

GoogleCodeExporter commented 9 years ago
Fixed in rtmplite svn r45 and download version 7.1.

To test it try the following:
1. Run rtmplite on localhost.
$ python rtmp.py

2. Go to rtmplite's test client page at 
http://myprojectguide.org/p/rtmplite/test/
Click on connect. Change NetStream from user1 to test. Click on play. Now web 
client is playing stream "test".

3. Start ffmpeg to stream existing video file to localhost myapp with stream 
name "test".
./ffmpeg -v 6 -loglevel debug -i 
http://myprojectguide.org/p/flash-videoio/sample1.flv -f flv 
rtmp://127.0.0.1/myapp/test

4. This should start publishing sample1.flv from ffmpeg to rtmplite, which 
plays it to the web client.

Original comment by voiprese...@gmail.com on 14 Feb 2011 at 6:27