[Red5] server side snapshot....take two

David Temes dtemes at infoco.es
Thu Jan 17 07:33:29 PST 2008


For those of you that showed interest in the SnapshotListener here is an 
updated version with a few changes: Now instead of writing a one frame flv I 
am opening a ffmpeg process and directly writing a png.

It's working fine in my winXP box, however I can see the ffmpeg process 
listed for 3 or 4 seconds in the taskmanager and sometimes I catch the file 
in the middle of the writing process, and of course it shows rubbish. Please 
report if it works in linux.

Regards
David
*************
/*

Snapshot listener
author: David Temes

*/
package es.infoco.server.dtemes;


import org.red5.server.api.stream.IStream;
import org.red5.server.api.stream.IStreamPacket;
import org.red5.server.api.stream.IStreamListener;

import org.red5.server.api.stream.IBroadcastStream;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.red5.server.net.rtmp.event.VideoData;

import org.apache.mina.common.ByteBuffer;
import org.red5.server.api.Red5;
import java.io.FileOutputStream;
import java.io.OutputStream;


public class SnapshotListener implements IStreamListener {

 protected static Logger log = LoggerFactory.getLogger(Application.class);
  private static final String FFMPEG = "c:\\dtemes\\varios\\ffmpeg.exe ";
  private static final String OUTPUTPATH = "c:\\";


  public void packetReceived(IBroadcastStream stream,
                    IStreamPacket packet)
          {

          if (packet instanceof VideoData)
           {
            VideoData vd = (VideoData) packet;
            if (vd.getFrameType()==VideoData.FrameType.KEYFRAME)
            {

             //remove the listener
             stream.removeStreamListener(this);

             org.apache.mina.common.ByteBuffer buff= packet.getData();
             int size=buff.limit();

             log.info("k>"+stream.getPublishedName()+" length="+size);
             //log.info("k>"+Red5.getConnectionLocal().getClient().getId());


             byte[] blockData = new byte[size];
             buff.get(blockData,0,size);

             try{
             //FileOutputStream fo= new 
FileOutputStream("c:\\"+stream.getPublishedName()+".flv");


             Process p =  Runtime.getRuntime().exec(this.FFMPEG+" -f 
flv -i - -vcodec png -vframes 1 -an -f rawvideo -s 160x120 
"+OUTPUTPATH+stream.getPublishedName()+".png");
             OutputStream fo = p.getOutputStream();

             //write FLV header , size bytes 14,15 and 16
             byte[] header= {'F','L','V',0x01,0x01,0x00,0x00,0x00,0x09,
                     0x00,0x00,0x00,0x00,0x09,0x00,0x00,0x00,
                     0x00,0x00,0x00,0x00,0x00,0x00,0x00};

                     header[14]=(byte)((size&0xFF0000)>>2);
                     header[15]=(byte)((size&0xFF00)>>1);
                     header[16]=(byte)((size&0xFF));

             fo.write(header, 0, header.length);
             fo.write(blockData, 0, size);
             fo.close();

             log.info ("snapshot ready?");
             }
             catch (Exception e) {log.info(e.toString());}


            }
           }

          }
}
*************


David Temes.
----- Original Message ----- 
From: "AleAmex" <ale_ame at libero.it>
To: <Red5 at osflash.org>
Sent: Thursday, January 17, 2008 3:09 PM
Subject: [Red5] Slow flv video streaming


>
> Hi everybody,
> I built a java application that streams in broadcast flv video file, with
> some like this:
>
>        IServerStream tempServerStream;
>        SimplePlayItem item = new SimplePlayItem();
>        String nomeFile = "video.flv";
>        item.setName(nomeFile);
>        tempServerStream.addItem(item);
>        tempServerStream.start();
>
> but I've a problem.
> Many times red5 has problems streaming some files, for instance for a file
> with duration of 20 minute length, it needs 25 minutes to stream it, with
> the problem that client show a not smooth video but often stop to wait
> buffering.
> This especially happens (happens more) with long file and file with little
> metadata (but have lots of metadata isn't enough).
> This isn't a bandwidth or cpu problem.
>
> Please please please help me!
> -- 
> View this message in context: 
> http://www.nabble.com/Slow-flv-video-streaming-tp14919637p14919637.html
> Sent from the Red5 - English mailing list archive at Nabble.com.
>
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
> 





More information about the Red5 mailing list