javacv
javacv copied to clipboard
avformat_open_input() error -2: Could not open input "java.io.BufferedInputStream@49829e35". (Has setFormat() been called?)
hello:
i'm use FFmpegFrameGrabber to get video metadata,then it return error infomation.The following is my code:
MetadataDto metadataDto = new MetadataDto();
log.info("start get video mata");
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(stream);
grabber.start();
int length = grabber.getLengthInFrames();
int lengthInVideo = grabber.getLengthInVideoFrames();
int i = 0;
Frame frame = null;
while (i < length) {
frame = grabber.grabFrame();
if ((i > FRAME_NUM) && (frame.image != null)) {
break;
}
i++;
}
Java2DFrameConverter converter = new Java2DFrameConverter();
BufferedImage bi = converter.getBufferedImage(frame);
long duration = grabber.getLengthInTime() / (1000 * 1000);
grabber.stop();
Look at the message displayed on the console for more information.
If you don't see any messages on the console, make sure that FFmpegLogCallback.set()
has been called.
Hello @saudet, I got the same error as @KtfwyCJ and I have also put on the FFmpegLogCallback.set() and here is what it says from the console:
op_kernel.cc:1401 OP_REQUIRES failed at strided_slice_op.cc:106 : Invalid argument: slice index 0 of dimension 1 out of bounds.
The original error message was alike with @KtfwyCJ's:
ERROR OCCURED : org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -2: Could not open input "java.io.BufferedInputStream@e90ad7b". (Has setFormat() been called?)
The code (ignore the Logs):
` fun javacvConvertLite(filename: File, cropSize: Crop): ArrayList<FloatArray> {
val converterToMat = ToMat()
var bmp: Bitmap? = null
val outputData: ArrayList<FloatArray> = ArrayList<FloatArray>()
try {
val filePath = Environment.getExternalStorageDirectory()
dir = File(filePath.absolutePath + "/SIBI/")
Log.d("dir_o", dir.toString())
frameDir = File(filePath.absolutePath + "/SIBI/Frames")
var inputStream: InputStream? = FileInputStream(filename)
val grabber = FFmpegFrameGrabber(inputStream)
hsv = Mat()
Log.d("cidx", "hsv")
skinMask = Mat()
Log.d("cidx", "skinMask")
grabber.startUnsafe()
Log.d("cidx", "start")
var idx = 1
while (true) {
Log.d("cidx", idx.toString())
val nthFrame = grabber.grabImage() ?: break
grabber.grabImage() ?: break
var mat = converterToMat.convertToOrgOpenCvCoreMat(nthFrame)
mat = trial4PreprocessImageGetSkin(mat, cropSize, idx++)
bmp = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, bmp)
var mobnet = mobileNetV2Classifier.recognize(bmp)[0]
Log.d("mobnet", mobnet.size.toString())
Log.d("mobnet", mobnet.toString())
outputData.add(mobnet)
/* Clean Components */
bmp.recycle()
bmp = null
mat.release()
}
grabber.stop()
grabber.release()
} catch (e: Exception) {
println("ERROR OCCURED : $e")
}
return outputData
}`
What the code does: It tries to convert an mp4 file input into a FloatArray, with ffmpg (15 FPS).
Do you know what's the problem/what to fix? @saudet
Thanks!
The mp4 format doesn't support streams very well. Please try with a file instead.
I try to grab a srt format stream ,bu it crash with error :
E/linker: normalize_path - invalid input: "lib/", the input path should be absolute W/linker: Warning: unable to normalize "lib/" (ignoring) E/linker: normalize_path - invalid input: "lib/", the input path should be absolute W/linker: Warning: unable to normalize "lib/" (ignoring) E/linker: normalize_path - invalid input: "lib/", the input path should be absolute W/linker: Warning: unable to normalize "lib/" (ignoring) E/linker: normalize_path - invalid input: "lib/", the input path should be absolute W/linker: Warning: unable to normalize "lib/" (ignoring) I/System.out: exception: org.bytedeco.javacv.FFmpegFrameGrabber$Exception: avformat_open_input() error -1330794744: Could not open input "srt://192.168.2.100:8080?streamid=live.sls.com/live/test". (Has setFormat() been called?) (For more details, make sure FFmpegLogCallback.set() has been called.) end I/AwareBitmapCacher: init lrucache size: 2097152 pid=18497
My code is like this . (SOURCE_RTSP just work fine , but SOURCE_SRT kill me ) : final String SOURCE_RTSP = "rtmp://192.168.2.100/live/room"; final String SOURCE_SRT = "srt://192.168.2.100:8080?streamid=live.sls.com/live/test";
final int TIMEOUT = 10; // In seconds.
public void rtspStreamingTest() {
try {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(SOURCE_SRT);
grabber.setOption(
TimeoutOption.STIMEOUT.getKey(),
String.valueOf(TIMEOUT * 1000000)
);
grabber.start();
Frame frame = null;
while ((frame = grabber.grab()) != null) {
System.out.println("frame grabbed at " + grabber.getTimestamp());
}
System.out.println("loop end with frame: " + frame);
} catch (FrameGrabber.Exception ex) {
System.out.println("exception: " + ex);
}
System.out.println("end");
}
after i put FFmpegLogCallback.set(); before FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(SOURCE_SRT);
same error
Please try again with JavaCV 1.5.6-SNAPSHOT: http://bytedeco.org/builds/
The mp4 format doesn't support streams very well. Please try with a file instead.
Ah yeah, I'm sorry for the late response, but you were right 😊
Works fine so far, after I changed the videos to the working/compatible ones.
Thanks! @saudet
Hello, how to solve this problem? My video stream input object is also java.io.BufferedInputStream, and the same error occurs. @saudet @KtfwyCJ @mrasyidg
@HuangDayu Not all formats support streams well. Please try another format.