FFmpeg decode H264 Naked stream and convert it into OpenCV mat__ffmpeg

Source: Internet
Author: User

Thanks to Dr. Rai for the Chinese video codec in the pay, http://blog.csdn.net/leixiaohua1020

Recently to do some video streaming things, to parse H264 bare stream and get OPENCV format of mat data to the algorithm engineers to run algorithms. Related resources have been difficult to find, often too old to make the API version of the replacement, no way to let new people or laymen [such as me] Quick validation of the code is feasible. In the reference to multiple blogs, the predecessors of the Code of the patchwork is finally written out this H264 decoder. Be a little bit of my humble ability to give back to this community.

Project Address:
Https://github.com/hirorogithub/ffmpeg_sample-H264_to_cv-Mat
Environmental dependency:
FFmpeg 3.3
opencv3.20 (in fact, 2.4 should be no problem)

Brief introduction of the file:
-H264Decoder.h H264Decoder.cpp: Decoder ontology, input H264 frame, (starting with 0001), Output Cv::mat (if you encounter a Sps,pps decoding failure, of course, the first encounter FFmpeg will record the SPS, PPS information is used for back decoding)
-H264decoder_jni.cpp h264decoder.java jni file and corresponding Java class note I pieced together the long information of the picture in the array returned in the JNI layer (2*sizeof (int)), So this array needs to be parsed accordingly. Because this side of the demand is the Java responsible for forwarding data, the actual running CV algorithm or in C + +, so there is such an operation, do not need to dispose of their own

Some pits:
FFmpeg oneself have a time.h, compile time to add the header file depends on what, very easy to make an error can not find time related basic types, solution Baidu has.

Some improvements:
I will consider making a sample of H264 bare stream and writing a simple call example for reference.

Time 2017-07-18: Have upload sample call and test data frame, remember correctly No. 0 is H264 the naked stream of the consolidated file, a file with many frames. The file after 1th is divided into 0001 H264 single frame files, frame files are packaged git

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.