Android video stream to windows desktop - Latency Issue

对着背影说爱祢 提交于 2019-12-13 03:05:51

问题


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

  1. android Cameratompegtest.class unkown latency
  2. android packetizer(udp) 10 millis
  3. windows depacketizer no buildup of data in buffers
  4. windows ffmpeg framgrabber unkown latency
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!