Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting .mov file to .h264 file

ok, this is the case, i actually want to parse frames from a mov file. get the encoded h264 frames. and i've managed to do so by using ffmpeg but when i try to make a movie again by using ffmpeg -i test* test.mov i get test00: Invalid data found when processing input so there is something not correct with the structure of the frames. as i understand it a frame should have the following appearance:

00 00 00 01 XX data -------------

where XX is say whether it is a I-,P- or B-frame. or more specifically type(XX) = 0x0F && XX says if it is I(type(XX) = 5?),P(type(XX) = 7?) or B(type(XX) = 8?) frame. I'm not sure about these number, i've been looking for it but not found good sources. so that's question number one, what number should the NALU be for the different frames?

anyway, when i use av_read_frame on the mov file, i get frame that look like this:

4B = size, 1B = XX and then data. (at least this is what i think i get)

the files where i store the frames are always size long when i look at them in a hexeditor(otherwise as well of course). and XX is always 65(ie. type(XX) = 5) in the first and then 61(ie. type(XX) = 1) for a couple of frames and then back to being 65 for one frame and so on.

i guess that these are frames like: I P P P P P P I P P P P P P P I P P P P P P P .... however then my assumption about the type numbers for the different frame types are false, which is highly likely. (any suggestion on reading about this? except the ISO/IEC 14496-10, i don't understand it really).

I've tried to remove the size and append 00 00 00 01 before the XX byte and the data but without success. any tips on how i could modify the frames to be valid H264 encoded frames?

like image 468
Robin Rye Avatar asked Aug 25 '11 11:08

Robin Rye


1 Answers

First of all, I must recommend a nice tool for understanding H264 streams: http://sourceforge.net/projects/h264bitstream/

No, to answer your specific question, yes, the frames usually start with 65 and 61. The special NAL units that typically start with 67 and 68 are, respectively, SPS (sequence parameter set) and PPS (picture parameter set).

I also suggest that you try to use ffmpeg -i input.mov -vcodec copy output.h264 to get the Annex B stream (with 00 00 00 01) correctly as a single file.

I could not understand exactly, what you are trying to achieve by extracting frames from mov and putting them into test.mov again.

like image 53
Alex Cohn Avatar answered Nov 13 '22 12:11

Alex Cohn