我正在尝试使用Xuggler 5.4库将RTSP流中的视频下载到计算机上的文件中。
String outputFilename = "D:\\downloadedrtsp.avi";
String inputSource = "rtsp://[ip-address]:[port]/user=[username]&[password]=password&channel=1&stream=1.sdp";
try {
IContainer container = IContainer.make();
IMetaData im = IMetaData.make();
im.setValue("max_delay", (1000000l) + "");
int retval = im.setValue("rtsp_transport", "tcp");
container.open(inputSource, IContainer.Type.READ, null, false, true, im, null);
IMediaReader mediaReader = ToolFactory.makeReader(container);
IMediaWriter mediaWriter = ToolFactory.makeWriter(outputFilename, mediaReader);
mediaReader.addListener(mediaWriter);
IError error;
while ((error = mediaReader.readPacket()) == null) {
logger.info("reading packet");
}
} catch (Exception e) {
e.printStackTrace();
}
但代码失败了,堆栈跟踪
15:40:52.500 [main] ERROR org.ffmpeg - [tcp @ 00000000171C6BE0] Failed to resolve hostname \downloadedrtsp.avi: ???? ???? ??????????.
15:40:52.500 [main] ERROR com.xuggle.xuggler - Error: could not write header for container (../../../../../../../csrc/com/xuggle/xuggler/Container.cpp:827)
java.lang.RuntimeException: Error Operation not permitted, failed to write header to container com.xuggle.xuggler.IContainer@387681280[url:D:\downloadedrtsp.avi;type:WRITE;format:com.xuggle.xuggler.IContainerFormat@387719536[oname:rtsp;olongname:RTSP output format;omimetype:null;oextensions:null;];] while establishing stream com.xuggle.xuggler.IStream@387690704[index:1;id:0;streamcoder:com.xuggle.xuggler.IStreamCoder@384527536[codec=com.xuggle.xuggler.ICodec@387719392[type=CODEC_TYPE_AUDIO;id=CODEC_ID_AAC;name=libvo_aacenc;];time base=1/8000;frame rate=0/0;sample rate=8000;channels=1;];framerate:0/0;timebase:1/90000;direction:OUTBOUND;]
at com.xuggle.mediatool.MediaWriter.getStream(MediaWriter.java:1058)
at com.xuggle.mediatool.MediaWriter.encodeAudio(MediaWriter.java:830)
at com.xuggle.mediatool.MediaWriter.onAudioSamples(MediaWriter.java:1441)
at com.xuggle.mediatool.AMediaToolMixin.onAudioSamples(AMediaToolMixin.java:89)
at com.xuggle.mediatool.MediaReader.dispatchAudioSamples(MediaReader.java:628)
at com.xuggle.mediatool.MediaReader.decodeAudio(MediaReader.java:555)
at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:469)
at ua.datalink.main.StreamTranscodingExample.readHigherLevel(StreamTranscodingExample.java:103)
at ua.datalink.main.StreamTranscodingExample.main(StreamTranscodingExample.java:121)
该文件是在程序启动时创建的,但它是空的。问题出在哪里?我花了好几个小时来搞清楚,但仍然没有结果。