问题
I am using an android v21 device to stream data to a javafx application. Its working fine but I have about 2 seconds of latency.
As of now the basic transportation goes like this
- android Cameratompegtest.class unkown latency
- android packetizer(udp) 10 millis
- windows depacketizer no buildup of data in buffers
- windows ffmpeg framgrabber unkown latency
- javafx imageview <1 millis
My data stream to my desktop and my packetizer is much faster than my frame rate and is often just waiting. There is no buildup of data anywhere else and therefore I assume no delay in any of my code. My big question is in regards to android MediaEncoder and secondly ffmpeg frame grabber.
How can I determine the cause of the slow down?
Do you have any suggestions?
My ffmpeg framgrabber
public RapidDecoder(final InputStream inputStream, final ImageView view)
{
System.out.println(TAG + " starting");
grabber = new FFmpegFrameGrabber(inputStream, 0);
converter = new Java2DFrameConverter();
mView = view;
emptyBuffer = new Runnable() {
@Override
public void run() {
System.out.println(TAG + " emptybuffer thread running");
try {
grabber.setOption("preset", "ultrafast");
grabber.start();
}catch (Exception e)
{
System.out.println(TAG + e);
}
while (true)
{
try{
grabFrame();
Thread.sleep(1);
}catch (Exception e)
{
System.out.println(TAG + " emptybuffer " + e);
}
}
}
};
display = new Runnable() {
@Override
public void run() {
System.out.println(TAG + " display thread running ");
while(true)
{
try{
displayImage();
Thread.sleep(10);
}catch (Exception e)
{
System.out.println(TAG + " display " + e);
}
}
}
};
}
public void generateVideo()
{
System.out.println(TAG + " genvid ");
new Thread(emptyBuffer).start();
new Thread(display).start();
}
public synchronized void grabFrame() throws FrameGrabber.Exception
{
//frame = grabber.grabFrame();
frame = grabber.grab();
//System.out.println("grab");
}
public synchronized void displayImage()
{
bufferedImage = converter.convert(frame);
frame = null;
if (bufferedImage == null) return;
mView.setImage(SwingFXUtils.toFXImage(bufferedImage, null));
//System.out.println("display");
}
}
my android code taken from bigflake website can be found here
https://bigflake.com/mediacodec/CameraToMpegTest.java.txt
来源:https://stackoverflow.com/questions/59185079/android-video-stream-to-windows-desktop-latency-issue