我将一些代码放在一起,使用xuggle从mp4中提取90秒。 问题是我正在制作2个文件,只是为了完成这件事。
我有更好的方法吗? 这是我的代码:
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;
}
这是CutChecker:
public class CutChecker extends MediaToolAdapter
{
/** {@inheritDoc} */
public Long timeInMilisec = (long) 0;
@Override
public void onVideoPicture(IVideoPictureEvent event)
{
timeInMilisec = event.getTimeStamp();
super.onVideoPicture(event);
}
}