Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting I-Frames from H264 in MPEG-TS in C

Tags:

c

h.264

I am experimenting with video and would like to know how I can extract I-frames from H264 contained in MPEG-TS container. What I want to do is generate preview images out of a video stream. As the I-frame is supposed to be a complete picture fro which P- and B-Frames derive, is there a possibility to just extract the data of the picture without having to decode it using a codec?

I have already done some work with MPEG-TS container format but I am not that much specialized in codecs.

I am rather in search of information.

Thanks a lot.

like image 317
Helder AC Avatar asked Feb 21 '23 00:02

Helder AC


2 Answers

I am no expert in this domain but I believe the answer to your question is NO.

If you want to save the I-frame as a JPEG image, you still need to "transcode" the video frame i.e. you first need to decode the I-frame using a H264 decoder and then encode it using a JPEG encoder. This is so because the JPEG encoder does not understand a H264 frame, it only accepts uncompressed video frames as input.

As an aside, since the input to the JPEG encoder is an uncompressed frame, you can generate a JPEG image from any type of frame (I/P/B) as it would already be decoded (using reference I frame, if needed) before feeding to the encoder.

like image 127
puffadder Avatar answered Feb 23 '23 13:02

puffadder


As others have noted decoding h.264 is complicated. You could write your own decoder but it is a major effort. Why not use an existing decoder?

Intel's IPP library has the basic building blocks for a decoder and a sample decoer:

Code Samples for the Intel® Integrated Performance Primitives

There's libavcodec:

Using libavformat and libavcodec

Revised avcodec_sample.0.4.9.cPP

like image 27
Guy Sirton Avatar answered Feb 23 '23 13:02

Guy Sirton