I am trying to use javacv to fetch a rtsp monitoring camera and grabber the frames, but meet "avcodec_open2() error -40: Could not open audio codec" error when the grabber is prepare to start after setup the parameters.
Javacv version:
- org.bytedeco.javacv-platform, 1.4.1
- org.bytedeco.javacpp-presets.opencv-platform, 3.4.1-1.4.1
Here is the Jave Exception Infomation:
org.bytedeco.javacv.FrameGrabber$Exception: avcodec_open2() error -40: Could not open audio codec.
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:835) ~[javacv-1.4.1.jar:1.4.1]
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:663) ~[javacv-1.4.1.jar:1.4.1]
rtsp infomation:
For the rtsp source, I also tried to download the FFplay and use command
.\ffplay.exe -rtsp_transport tcp rtsp://admin:[email protected]
to show the frames from monitoring camera, and it works, and with following information
Input #0, rtsp, from 'rtsp://admin:[email protected]':
- Metadata:
- title : Media Presentation
- Duration: N/A, start: 0.000000, bitrate: N/A
- Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 15 fps, 24.17 tbr, 90k tbn, 30 tbc
- Stream #0:1: Audio: aac, 16000 Hz, 1 channels, fltp
- Metadata:
[aac @ 000001fc123be880] Audio object type 0 is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
And here is the source code:
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber ("rtsp://admin:[email protected]");
grabber.setImageHeight(640);
grabber.setImageWidth(360);
grabber.setOption("rtsp_transport", "tcp");
grabber.start(); // Where meet the problem
Java2DFrameConverter converter = new Java2DFrameConverter();
BufferedImage bufferedImage = converter.convert( grabber.grab() );
ByteArrayOutputStream bateArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpeg", bateArrayOutputStream);
byte[] data = bateArrayOutputStream.toByteArray();
bateArrayOutputStream.close();
I have tested to change the rtsp to a mp4 file, the code can work.
How can I fix this problem? Thanks very much!
grabber.setOption("an","");
andgrabber.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
to ignore the audio part, but still meet the same issue. – Jeremy Lu