FFmpeg h264 decoding, shielding screen frames caused by network packet loss and other reasons

Source: Internet
Author: User

It seems that the problem can only be solved in this way. Now we need to test more to prevent new problems. Currently, it does not affect the existing code, and the frame of the screen is directly blocked.

 

Ideas:
I asked about h264 decoding of the set-top box. They used hardware decoding. They simply set an interface provided by hardware decoding: Set the error processing mode.
I think this error handling mode will definitely block the wrong frames, so it won't be enough to display them on the screen.

 

Therefore, there is a problem: Is there an error handling mode for FFMPEG to make the frame (in h264 format) of the screen invisible?
I checked some information and couldn't find it.

 

PS: If you know, leave a message.

 

I assume that FFMPEG does not have this mode. I used my method to simulate an error handling mode.
Add a variable named datadamage to avframe (ff_common_frame.
If this variable is 0, it indicates that there is no error in this frame. If it is 1, it indicates that there is an error.

 

How to use it?
When av_decode_video () solves a frame, judge the flag:
Is 1. Do not render, block it. If the current frame is a key frame and the flag is 1, all frames before the next key frame will be shielded.
If the value is 0, rendering is normal.

 

Now the question becomes the question of when to set the mark.
First, we need to know when a frame (h264) starts decoding and when it starts. (The last frame ends when the next frame starts decoding ).
Here is a basis. When current_mb_slice = 0, it indicates the start of a frame.
Of course, you can also use the 2nd method: ff_h1__frame_start (). This is the beginning of a frame.

 

So how can we judge this frame error?
The method I used is:
Because h264 frames are measured in units of slice MB, when any slice or any MB of the frame is wrong, this frame sets the error mark as long as there is an error.
In addition, there is some information before each frame of h264, Which is sps pps. in theory, the error mark should be set for all frames between the next SPs or PPS. This is not done yet (it has no effect currently ). You may have to carefully consider the tests in the next few days.

 

The above is the current solution, and it is also the only solution that can block the frame of the screen so far.
Wait until the test is complete.

 

If you have any suggestions for this solution, please submit them. I am very grateful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.