Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

stream rtmp + rtmpdump + php + JW Player (re-streaming). Fix FLV fragment/part


I'm trying to re-stream for several days. So I am humbly asking for your help.

*Objetive:* re-stream last "40 seconds" or 2mb of video live stream;
*Procedure:*
<ol>
<li>Get stream whith rtmpdump, file output: stream9hd.flv</li>
<li>Create new file 9hd.flv with fragment video of stream9hd.flv every 2 seconds with php</li>
<li>Fix the flv to play. How to fix??</li>
<li>Play with JW Player</li>
</ol>
*Problem:* Fix the flv to play with JW Player.



------------------------------------------------------------
1 - stream rtmp + rtmpdump (command line in php)
------------------------------------------------------------
bc.. exec("/usr/bin/rtmpdump-2.3/rtmpdump -r ''rtmp://173.192.94.185:1935/liverepeater/'' -a ''liverepeater/'' -f ''LNX 10,2,153,1'' -W ''http://www.cdnbr.biz/swf/player.swf'' -p ''http://www.cdnbr.biz/canais/History%20HD.html'' -y ''hd'' -o ''/var/www/html/dirtitle/tvplayer/stream9hd.flv'' --live > /dev/null &",);



------------------------------------------------------------
2 - extract last 2mb of stream9hd.flv with php
------------------------------------------------------------
bc.. function ftruncate_end($filein,$fileout,$endbytes){
$fp=fopen($filein,"rb");
fseek($fp,-$endbytes);
$data=fread($fp,$endbytes);
fclose($fp);
$fp=fopen($fileout,"wb");
fwrite($fp,$data);
fclose($fp);
}
ftruncate_end("stream9hd.flv","9hd.flv",2097152);



------------------------------------------------------------
3 - fix 9hd.flv? how to fix?
------------------------------------------------------------
- You must have a way of fixing the flv in real time with PHP. FLV is being extracted from stream9hd.flv every 2 seconds.
- Flvtool2 is possible to use, but after 2 seconds have to fix again. If the fix again the JW FLV Player stop the video. So I think flvtool2 does not work in this case.

Please, any ideas?

------------------------------------------------------------
4 - Play whith JW Player. This right?
------------------------------------------------------------
bc.. <script type="text/javascript">
jwplayer("mediaplayer").setup({
autostart: true,
provider:'video',
file: "http://domain.biz/tvplayer/9hd.flv",
type: "video",
duration: 0,
flashplayer: "player.swf",
volume: 10,
width: 720,
'skin': 'bekle.zip',
events: {
onError: function(event) {
alert('erro: '+event.message);
}
}
});
</script>




thanks. sorry my english.

3 Community Answers

Ethan Feldman

JW Player Support Agent  
0 rated :

Do you have an example of this that we can take a look at?

JW Player

User  
0 rated :

*File Input:* http://filmes-online.biz/livestream/stream9hd.flv
*File Output:* http://filmes-online.biz/livestream/9hd.flv

*Example JW Player:* http://filmes-online.biz/livestream/readme.html


------------------------------------------------------------
Attempted PHP stream:
------------------------------------------------------------
bc.. function flvh(){
print("FLV");
print(pack('C',1));
print(pack('C',1));
print(pack('N',9));
print(pack('N',9));
}

clearstatcache();$inf=stat($file);$mtime=$inf[mtime];
$fp=@fopen($file,"rb");flvh();print(fread($fp,$inf[size]));
fseek($fp,-200,SEEK_END);$proc=fread($fp,200);
fclose($fp);

while(connection_status()==0){usleep(1000);

clearstatcache();$inf=stat($file);
if($inf[mtime]!=$mtime){usleep(5000);clearstatcache();$inf=stat($file);$mtime=$inf[mtime];
$fp=@fopen($file,"rb");$tot=fread($fp,$inf[size]);
$pose=mb_strpos($tot,$proc,0,'iso-8859-1');
fseek($fp,-200,SEEK_END);$proc=fread($fp,200);
fseek($fp,$pose);print(fread($fp,$inf[size]));@ob_flush();@flush();@ob_end_flush();
@fclose($fp);
}

}




ps.: sorry, in extract 2mb, replace:
bc.. fseek($fp,-$endbytes);

to
bc.. fseek($fp,-$endbytes,SEEK_END);

Ethan Feldman

JW Player Support Agent  
0 rated :

I think there is a server issue at hand here.

I see the player trying to request this file, but it never loads – http://filmes-online.biz/livestream/9hd.flv

This question has received the maximum number of answers.