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

Walter Tak walter at waltertak.com
Thu Jan 17 14:08:51 PST 2008


Hello David,

I would not recommend converting snapshots using ffmpeg on a red5 production 
server with 20+ streams simultaneously.

Your (Red5) system will grind to a halt when ffmpeg is consuming all your 
precious cpu-time.

Best way is to make the frames available on a location that can be accessed 
using http and let a second server fetch the
frames and convert them in a queue-system so the 2nd system will convert as 
many snapshots as possible based on rotation.

This can be done using simple shell/bash-scripts or something like php (CLI) 
and crontab. Nothing special.

This also gives the opportunity to watermark / brand your snapshots using 
extra libs like GD or Imagemagick etc etc.

Imho.

Regards,
Walter Tak


----- Original Message ----- 
From: "David Temes" <dtemes at infoco.es>
To: <red5 at osflash.org>
Sent: Thursday, January 17, 2008 4:33 PM
Subject: [Red5] server side snapshot....take two


> 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
>>
>
>
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
> 


-- 
I am using the free version of SPAMfighter for private users.
It has removed 14318 spam emails to date.
Paying users do not have this message in their emails.
Get the free SPAMfighter here: http://www.spamfighter.com/len





More information about the Red5 mailing list