javacv
javacv copied to clipboard
[http @ 0x7ff34800a800] Stream ends prematurely at 10350130, should be 335862362
using FFmpegFrameGrabber to intercept frames, the input uses the http stream, but in the process of intercepting frames, after intercepting a period of time it prints a log of the stream ending prematurely, as follows log : ` Warning: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] Packet corrupt (stream = 0, dts = 2114701) Warning:
Error: [hevc @ 0000000023587a40] Invalid NAL unit size (8478 > 7435). Error: [hevc @ 0000000023587a40] Error splitting the input into NAL units. Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x372923: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x372aa9: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 0, offset 0x372be7: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x375335: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x375475: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 0, offset 0x3755c8: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x376ce2: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x376e6a: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 0, offset 0x376f87: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x378571: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x3786a3: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 0, offset 0x378801: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x37d6a7: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x37d809: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 0, offset 0x37d926: partial file Error: [mov,mp4,m4a,3gp,3g2,mj2 @ 000000000169cbc0] stream 1, offset 0x393201: partial file`
mycode:
private static void ffmpegDemo(String inputPath, long startTime, int intervalSeconds, String outputPath, String outputFormat) throws IOException, InterruptedException {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputPath);
grabber.setVideoOption("rtsp_transport", "tcp"); // 使用TCP传输
try {
grabber.start();
} catch (FFmpegFrameGrabber.Exception e) {
throw new RuntimeException(e);
}
Frame frame;
//获取视频总帧数
Java2DFrameConverter converter = new Java2DFrameConverter();
while ((frame = grabber.grabImage()) != null) {
if (intervalSeconds != 0) {
if (grabber.getTimestamp() >= timestamp) {
String fileName = outputPath + File.separator + grabber.getFrameNumber() + outputFormat;
File file = new File(fileName);
//创建BufferedImage对象
BufferedImage bufferedImage = converter.getBufferedImage(frame);
ImageIO.write(bufferedImage, "png", file);
System.out.println("Grabber time:" + grabber.getTimestamp() + "image");
// 增加时间戳,以便下一次截取
timestamp += intervalSeconds * 1000L; // 将秒转换为微秒
}
} else {
//间隔时间为0,截取所有帧
String fileName = outputPath + File.separator + (grabber.getFrameNumber()+1) + outputFormat;
File file = new File(fileName);
//创建BufferedImage对象
BufferedImage bufferedImage = converter.getBufferedImage(frame);
ImageIO.write(bufferedImage, "png", file);
System.out.println("index:" + grabber.getFrameNumber() + "image");
}
}
long end = System.currentTimeMillis();
System.out.println("Time-consuming:" + (end - start) / 1000L + "s,Processing Frames:" + grabber.getFrameNumber());
System.out.println("i:" + i + "getFrameNumber:" + grabber.getFrameNumber());
grabber.close();
}`
After my test, if the original video quality is high, it takes longer to keep the picture after intercepting it, then this problem will occur, when I use a low quality video I don't have this problem, but I don't know the exact reason, I hope to get help, thanks!