Boumcke
22nd April 2008, 15:49
Hi,
I'm a PhD student in a belgian university, currently working on video transmission over mobile networks. I recently encountered a problem while manipulating H.264 sequences, and I'm looking for any kind of advice that could help me understand what I'm doing wrong.
What I'm trying to achieve here is exploit the slices in H.264 to modify the content of a video sequence in the compressed domain, i.e. by changing directly the bitstream of the sequence. My goal is to be able to completely replice one slice of a sequence by a whole different sequence, providing that the dimensions of the discarded slice and those of the new sequence are identical. I've identified several parameters of the slice headers (particularly idr_pic_id) that need to be adapted in order to obtain a H.264 compliant sequence, and I have now a prototype application capable of producing a "composite" stream which is in my opinin compliant with the standard. However, my attempts to decode it fail miserably, as the modified part of the bitstream is decoded erroneously.
Here's a description of the operations my program actually does on the bitstream :
- It first parses the stream of the original sequence, waiting for a header indicating an I-frame.
- When an I-frame is detected, it parses the stream further to detect if the frame is divided in multiple slices.
- As soon as a second slice is identified, it replaces the part of the bitstream correponding to the second slice of the frame by a stream representing the sequence to be inserted in the original one.
The output of the program is then a new stream, where all the "slice 2"-related NALs have been replaced by custom created NALs with different data. As for now I'm only working on 1 I-frame sequences to test the validity of the output stream. I'm using the JM decoder to decoded the output sequence, but every attempt I've done so far fails, every time with the same conclusion : modifying the NALs data cause an error in the decoding process of the first MB of the second slice.
Here's a detailed description of what happens. Suppose we have to sequences : the first one (original sequence) is encoded in two slices (dimensions 11x6 macroblocks and 11x3 macroblocks), the second one (external sequence) is encoded in one slice only (dimensions 11x3 macroblocks). Both sequences only contain one I-frame.
- When I decode only the external sequence, I found that the values immediately following the slice header are '0000000011...', indicating a first macroblock of type I_4x4. That is indeed the type given by the JM logs for this macroblock.
- The original sequence is then passed through my prototype application which replaces the NAL corresponding to the second macroblock by a newly created NAL containing the modified external sequence's slice's header and it's data.
- When I decode this new "composite" sequence, the value immediately following the second slice's header stay unchanged '0000000011', but the JM logs indicate that the first macroblock of this slice is decoded as a I_PCM macroblock.
It's interesting to notice that even when I keep the header of the orignal sequence's second slice (the only modification is then the replacement of the slice data with the external slice data), the same error happens in the decoding process.
My current knowledge of the H.264 standard is not deep enough to allow me to understand what I'm doing wrong in my program, and why the first macroblock of the second slice in the composite sequence is incorrectedly interpreted as an I_PCM macroblock. I know this is a tricky question, as the manipulations I realize are hard to explain clearly, but any piece of advice would be greatly appreciated.
Thanks a lot if you read the whole post, and thanks even more if you're able to give me a little help...
I'm a PhD student in a belgian university, currently working on video transmission over mobile networks. I recently encountered a problem while manipulating H.264 sequences, and I'm looking for any kind of advice that could help me understand what I'm doing wrong.
What I'm trying to achieve here is exploit the slices in H.264 to modify the content of a video sequence in the compressed domain, i.e. by changing directly the bitstream of the sequence. My goal is to be able to completely replice one slice of a sequence by a whole different sequence, providing that the dimensions of the discarded slice and those of the new sequence are identical. I've identified several parameters of the slice headers (particularly idr_pic_id) that need to be adapted in order to obtain a H.264 compliant sequence, and I have now a prototype application capable of producing a "composite" stream which is in my opinin compliant with the standard. However, my attempts to decode it fail miserably, as the modified part of the bitstream is decoded erroneously.
Here's a description of the operations my program actually does on the bitstream :
- It first parses the stream of the original sequence, waiting for a header indicating an I-frame.
- When an I-frame is detected, it parses the stream further to detect if the frame is divided in multiple slices.
- As soon as a second slice is identified, it replaces the part of the bitstream correponding to the second slice of the frame by a stream representing the sequence to be inserted in the original one.
The output of the program is then a new stream, where all the "slice 2"-related NALs have been replaced by custom created NALs with different data. As for now I'm only working on 1 I-frame sequences to test the validity of the output stream. I'm using the JM decoder to decoded the output sequence, but every attempt I've done so far fails, every time with the same conclusion : modifying the NALs data cause an error in the decoding process of the first MB of the second slice.
Here's a detailed description of what happens. Suppose we have to sequences : the first one (original sequence) is encoded in two slices (dimensions 11x6 macroblocks and 11x3 macroblocks), the second one (external sequence) is encoded in one slice only (dimensions 11x3 macroblocks). Both sequences only contain one I-frame.
- When I decode only the external sequence, I found that the values immediately following the slice header are '0000000011...', indicating a first macroblock of type I_4x4. That is indeed the type given by the JM logs for this macroblock.
- The original sequence is then passed through my prototype application which replaces the NAL corresponding to the second macroblock by a newly created NAL containing the modified external sequence's slice's header and it's data.
- When I decode this new "composite" sequence, the value immediately following the second slice's header stay unchanged '0000000011', but the JM logs indicate that the first macroblock of this slice is decoded as a I_PCM macroblock.
It's interesting to notice that even when I keep the header of the orignal sequence's second slice (the only modification is then the replacement of the slice data with the external slice data), the same error happens in the decoding process.
My current knowledge of the H.264 standard is not deep enough to allow me to understand what I'm doing wrong in my program, and why the first macroblock of the second slice in the composite sequence is incorrectedly interpreted as an I_PCM macroblock. I know this is a tricky question, as the manipulations I realize are hard to explain clearly, but any piece of advice would be greatly appreciated.
Thanks a lot if you read the whole post, and thanks even more if you're able to give me a little help...