Java 来自 .ts 文件的 BufferedImages
Java BufferedImages from .ts File
如何从 Java 中的 .ts 文件中获取 BufferedImage(定义位置处的帧)?如果可能,我不想使用任何 JNI / CLI 包装器。
System.out.println( JCodecUtil.detectFormat( file ) );
Demuxer demuxer = JCodecUtil.createDemuxer( JCodecUtil.detectFormat( file ), file );
for ( DemuxerTrack demuxerTrack : demuxer.getVideoTracks() ) {
Packet packet;
while ( ( packet = demuxerTrack.nextFrame() ) != null ) {
System.out.println( "frame " + packet.getDuration() );
}
}
第一个代码段的输出只是 MPEG_TS
[ERROR] . (:0): Format MPEG_TS is not supported
MPEG_TS
[ERROR] . (:0): Format MPEG_TS is not supported
for ( DemuxerTrack demuxerTrack : JCodecUtil.createM2TSDemuxer( file, TrackType.VIDEO ).v1.getTracks() ) {
Packet packet;
while ( ( packet = demuxerTrack.nextFrame() ) != null ) {
System.out.println( "frame : " + ImageIO.read( new ByteArrayInputStream( packet.getData().array() ) ) );
}
}
在此代码段中,它只是为每个帧输出 null。如何解决这个问题?
Picture tmp = Picture.create(1920, 1088, ColorSpace.YUV420);
VideoDecoder vd = JCodecUtil.createVideoDecoder(JCodecUtil.detectDecoder(data.duplicate()), data.duplicate());
Picture pic = vd.decodeFrame(data, tmp.getData());
BufferedImage buf = AWTUtil.toBufferedImage(pic);
如何从 Java 中的 .ts 文件中获取 BufferedImage(定义位置处的帧)?如果可能,我不想使用任何 JNI / CLI 包装器。
System.out.println( JCodecUtil.detectFormat( file ) );
Demuxer demuxer = JCodecUtil.createDemuxer( JCodecUtil.detectFormat( file ), file );
for ( DemuxerTrack demuxerTrack : demuxer.getVideoTracks() ) {
Packet packet;
while ( ( packet = demuxerTrack.nextFrame() ) != null ) {
System.out.println( "frame " + packet.getDuration() );
}
}
第一个代码段的输出只是 MPEG_TS
[ERROR] . (:0): Format MPEG_TS is not supported
MPEG_TS
[ERROR] . (:0): Format MPEG_TS is not supported
for ( DemuxerTrack demuxerTrack : JCodecUtil.createM2TSDemuxer( file, TrackType.VIDEO ).v1.getTracks() ) {
Packet packet;
while ( ( packet = demuxerTrack.nextFrame() ) != null ) {
System.out.println( "frame : " + ImageIO.read( new ByteArrayInputStream( packet.getData().array() ) ) );
}
}
在此代码段中,它只是为每个帧输出 null。如何解决这个问题?
Picture tmp = Picture.create(1920, 1088, ColorSpace.YUV420);
VideoDecoder vd = JCodecUtil.createVideoDecoder(JCodecUtil.detectDecoder(data.duplicate()), data.duplicate());
Picture pic = vd.decodeFrame(data, tmp.getData());
BufferedImage buf = AWTUtil.toBufferedImage(pic);