extract 90 seconds with xuggle

35 Views Asked by At

I put together some code , using xuggle, to extract 90 seconds from an mp4. Problem is I am producing 2 files just to get this done.

Is there a better way for me to do this? Here is my code:

IMediaReader reader = ToolFactory.makeReader(fileName);
                    CutChecker cutChecker = new CutChecker();
                    reader.addListener(cutChecker);
                    IMediaWriter writer = ToolFactory.makeWriter("preview_" + fileName, reader);
                    cutChecker.addListener(writer);
                    Boolean updated = false;
                    try{
                        while (reader.readPacket() == null) {
                            if ((cutChecker.timeInMilisec >= 90 * 1000000) && (!updated)) {
                                cutChecker.removeListener(writer);
                                writer.close();
                                writer = ToolFactory.makeWriter("_original" +fileName, reader);
                                cutChecker.addListener(writer);
                                updated = true;
                            }
                        }
                    }catch(RuntimeException re){
                        logger.info(re);
                        continue;
                    }

Here is the CutChecker:

public class CutChecker extends MediaToolAdapter
{
/** {@inheritDoc} */

    public Long timeInMilisec = (long) 0;

    @Override
    public void onVideoPicture(IVideoPictureEvent event)
      {
    timeInMilisec = event.getTimeStamp();
    super.onVideoPicture(event);
    }
    }
0

There are 0 best solutions below