As the saying goes, it is better to teach people to fish than to teach people to fish. What is recorded here is in the actual project, how to solve the problem when I encounter it, to provide you with a reference to the idea of ~

I. Problems encountered

Check the real-time video on the mobile terminal through the PC background. A frame appears first, and then the picture freezes. After a few seconds, the picture becomes smooth.

Second, analyze the problem

1) For this problem, we first need to check whether it is a problem on the mobile terminal or on the PC terminal. Otherwise, we will directly throw it to our colleagues on the PC terminal and they will do a lot of work and finally find it is a problem on the mobile terminal, which will be embarrassing.

2) Let’s take a look at which end of the investigation is the problem?

In fact, the idea is very simple, we need to save a local YUV and H264 stream file, and then with the help of software to check whether the local stream file is normal. If there is a problem, it is the mobile end of the problem, otherwise, you can let PC colleagues together to troubleshoot.

I. As shown in the following code block, I saved the YUV stream data to a local file before the stream was pushed to the background;

Ii. Save the encoded H264 stream as shown in the code block below

  private void saveStreamFile(byte[] buffer, String encodeFormat, int width, int height) {
        String dirString = "/sdcard/videoStream/";
        File dirFile = new File(dirString);

        if (!dirFile.exists()) {
            dirFile.mkdirs();
        }

        File saveFile = new File(dirString + width + "_" + height + "Stream.yuv");

        try {
            FileOutputStream fileOutputStream = new FileOutputStream(saveFile, true);
            fileOutputStream.write(buffer);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Copy the code

Iii, the stream file is saved, is how to view the problem.

I am using The ElecardStreamEyeTools tool, which can play yuV files and H264 streams. You need to change the suffix to.yuv to view them.

As shown below, yuV stream files are selected Elecard YUV Viewer to view, h264 stream files are selected Elecard StreamEye to view.

3) After the previous wave, it’s time for a basic conclusion. Play local saved YUV and H264 stream files, found that they are smooth, no lag phenomenon. And found that H264 stream file inside, is enough I frame, this time can let the PC terminal colleagues together investigation.

Add: ElecardStreamEyeTools tools download address: download.csdn.net/download/Mr…


I have been engaged in Android Camera related development for 5 years

Now I work in Shenzhen

Welcome to follow my wechat official account “Xiaochi Notes”.

We learn and communicate together

——– 2021.02.26 Shenzhen 15:17