我没有成功使用 gst1 Java 绑定设置简单的 decodebin GST 管道。我在 decodebin 中收到“内部数据流错误”错误。我使用 gst1-java-core 做错了吗?
还想知道是否使用 EOS 侦听器来确定管道是否异步结束是使用管道的正确方法?
public static void main(String[] args) throws InterruptedException
{
Gst.init();
System.out.println("Version: " + Gst.getVersionString());
System.out.println("Source: " + args[0]);
System.out.println("Target: " + args[1]);
final Pipeline pipeline = new Pipeline("MyPipeline");
Element fileSource = ElementFactory.make("filesrc", "MyFile");
fileSource.set("location", args[0]);
Element decode = ElementFactory.make("decodebin", "decode");
Element fileSink = ElementFactory.make("filesink", "MyTargetFile");
fileSink.set("location", args[1]);
pipeline.addMany(fileSource, decode, fileSink);
Element.linkMany(fileSource, decode, fileSink);
final CountDownLatch latch = new CountDownLatch(1);
// end of stream listener
EOS eos = new EOS()
{
public void endOfStream(GstObject source)
{
System.out.println(String.format("EOS for (%s)", source));
latch.countDown();
}
};
// state change listener
STATE_CHANGED state = new STATE_CHANGED()
{
public void stateChanged(GstObject source, State old, State current, State pending)
{
System.out.println(String.format("State changed for (%s) from (%s) to (%s)", source, old, current));
}
};
// error listener
ERROR error = new ERROR()
{
public void errorMessage(GstObject source, int code, String message)
{
System.err.println(String.format("Error (%d) for (%s): %s", code, source, message));
latch.countDown();
}
};
pipeline.getBus().connect(error);
pipeline.getBus().connect(state);
pipeline.getBus().connect(eos);
StateChangeReturn stateReturn = pipeline.play();
System.out.println("State return: " + stateReturn);
synchronized (latch)
{
latch.await();
}
pipeline.setState(State.NULL);
pipeline.close();
Gst.deinit();
}
Version: GStreamer 1.18.4
Source: /tmp/Imagine_Demo.mp4
Target: /tmp/out.yuv
State return: ASYNC
State changed for (BaseSink: [MyTargetFile]) from (NULL) to (READY)
State changed for (Element: [typefind]) from (NULL) to (READY)
State changed for (DecodeBin: [decode]) from (NULL) to (READY)
State changed for (BaseSrc: [MyFile]) from (NULL) to (READY)
State changed for (Pipeline: [MyPipeline]) from (NULL) to (READY)
State changed for (Element: [typefind]) from (READY) to (PAUSED)
State changed for (BaseSrc: [MyFile]) from (READY) to (PAUSED)
State changed for (Element: [qtdemux0]) from (NULL) to (READY)
State changed for (Element: [qtdemux0]) from (READY) to (PAUSED)
State changed for (Element: [h264parse0]) from (NULL) to (READY)
State changed for (Element: [h264parse0]) from (READY) to (PAUSED)
State changed for (Element: [avdec_h264-0]) from (NULL) to (READY)
State changed for (Element: [avdec_h264-0]) from (READY) to (PAUSED)
State changed for (Element: [aacparse0]) from (NULL) to (READY)
State changed for (Element: [aacparse0]) from (READY) to (PAUSED)
State changed for (Element: [avdec_aac0]) from (NULL) to (READY)
State changed for (Element: [avdec_aac0]) from (READY) to (PAUSED)
State changed for (DecodeBin: [decode]) from (READY) to (PAUSED)
Error (1) for (Element: [qtdemux0]): Internal data stream error.
State changed for (BaseSink: [MyTargetFile]) from (PLAYING) to (PAUSED)
State changed for (BaseSink: [MyTargetFile]) from (READY) to (READY)
State changed for (BaseSink: [MyTargetFile]) from (READY) to (NULL)
State changed for (Element: [avdec_aac0]) from (PAUSED) to (READY)
State changed for (Element: [aacparse0]) from (PAUSED) to (READY)
State changed for (Element: [avdec_h264-0]) from (PAUSED) to (READY)
State changed for (BaseTransform: [capsfilter0]) from (PAUSED) to (READY)
State changed for (Element: [h264parse0]) from (PAUSED) to (READY)
State changed for (Element: [multiqueue0]) from (PAUSED) to (READY)
State changed for (Element: [qtdemux0]) from (PAUSED) to (READY)
State changed for (Element: [typefind]) from (PAUSED) to (READY)
State changed for (Element: [avdec_aac0]) from (READY) to (NULL)
State changed for (Element: [aacparse0]) from (READY) to (NULL)
State changed for (Element: [avdec_h264-0]) from (READY) to (NULL)
State changed for (BaseTransform: [capsfilter0]) from (READY) to (NULL)
State changed for (Element: [h264parse0]) from (READY) to (NULL)
State changed for (Element: [multiqueue0]) from (READY) to (NULL)
State changed for (Element: [qtdemux0]) from (READY) to (NULL)
State changed for (DecodeBin: [decode]) from (PAUSED) to (READY)
State changed for (Element: [typefind]) from (READY) to (NULL)
State changed for (DecodeBin: [decode]) from (READY) to (NULL)
State changed for (BaseSrc: [MyFile]) from (PAUSED) to (READY)
State changed for (BaseSrc: [MyFile]) from (READY) to (NULL)
DtsGetHWFeatures: Create File Failed
DtsGetHWFeatures: Create File Failed
Running DIL (3.22.0) Version
DtsDeviceOpen: Opening HW in mode 0
DtsDeviceOpen: Create File Failed
但是,当我在控制台中的同一台计算机上运行管道时,它可以正常工作:
$ gst-launch-1.0 filesrc location=/tmp/Imagine_Demo.mp4 ! decodebin ! filesink location=/tmp/out.yuv
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
DtsGetHWFeatures: Create File Failed
DtsGetHWFeatures: Create File Failed
Running DIL (3.22.0) Version
DtsDeviceOpen: Opening HW in mode 0
DtsDeviceOpen: Create File Failed
Redistribute latency...
Redistribute latency...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:04.713531469
Setting pipeline to NULL ...
Freeing pipeline ...