RTMP::Client - A Simple RTMP client
use RTMP::Client qw(rtmp_connect rtmp_play rtmp_call); print "connect success\n" if rtmp_connect('192.168.1.1', '1935', 'live/23'); rtmp_play('MainB_1', '-1.0', '-1.0'); rtmp_call('YourFunc', 'YourARGV');
This is a simple RTMP client without video or audio decode. It implemented in pure PERL including packing Adobe amf packages.
Just like the 'NetConnection.connect()' function in ActionScript, with args are set in different way.
Just like the 'NetStream.play()' function in ActionScript, with args are set in different way. You can use the last two args or not.
Just like the 'NetStream.call()' function in ActionScript, with args are set in different way.
use RTMP::Client qw(rtmp_connect rtmp_play rtmp_call);
Speed Detection
report download speed every 5 secs.
print "connect success\n" if rtmp_connect('192.168.1.1', '1935', 'live/23'); my $report_time = 5; rtmp_play('MainB_1', '-1.0', '-1.0', $report_time, \&speed_detector); sub speed_detector { my $rev_length = shift; my $speed = $rev_length / 1024 / $report_time; if ($speed > 3) { my $cur_time = strftime("%F_%T", localtime); print $cur_time, "\t", $speed, "\tKbytes/s\n"; } else { print "too slow !\n"; } }
Save to File
do things like "rtmpdump".http://rtmpdump.mplayerhq.hu/
print "connect success\n" if rtmp_connect('192.168.1.1', '1935', 'live/23'); my $loop_time = 10; rtmp_play('MainB_1', '-1.0', '-1.0', $report_time, \&save_to_file); sub save_to_file { my $rev_length = shift; my $rev_binary = shift; open my $fh,">>","/root/rtmp_dump.bin"; binmode $fh; print $fh $rev_binary; close $fh; }
No args need. Called in function rtmp_connect().
Output a available binary amf packet. Works on amf message body, just like add a right amf header before the message body.
It packs a attribute_name which less than 65536 bytes or return null.
Return 9 bytes binary data.
Return 2 bytes binary data.
it can pack a string which less than 65536 bytes or it return null. There will be a long string packer in future.
Return 1 byte binary data.
Recieve a rtmp chunk.
Recieve a rtmp message.
Wait until recieved bytes, then return it.
Wait $int_time_out Seconds, or Recieve $int_wanted_length bytes, then return it.
Send binary data to server.
Convert hex array to binary ,then send them to server.
Print binary data in a readable format.
Return rtmp timestamp of the chunk stream id in string format. From Adobe RTMP Spec: 1.Timestamps in RTMP Chunk Stream are given as an integer number of milliseconds. 2.each Chunk Stream will start with a timestamp of 0, but this is not required. 3.Timestamps MUST be monotonically increasing, and SHOULD be linear in time.
Dump the data to dec
print colorful strings
output the rtmp stream information to STDOUT
Written by ChenGang, yikuyiku.com@gmail.com http://blog.yikuyiku.com/
Copyright (c) 2011 ChenGang.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Kamaitachi
To install RTMP::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RTMP::Client
CPAN shell
perl -MCPAN -e shell install RTMP::Client
For more information on module installation, please visit the detailed CPAN module installation guide.