originating from: http://www.mworkbox.com/wp/work/314.html2013-05-04
MP4 's video H264 package is available in 2 formats: H264 and AVC1, which are easy to ignore for this detail. The author also encountered this problem when adapting LIVE555 streaming media to increase MP4 file type support.
(a) First of all, the principle of understanding the difference between the 2 formats:
AVC1 Description: H. bitstream without start codes. The video generated by the FFmpeg transcoding is not 0x00000001 with the starting code.
H264 Description: H. bitstream with start codes. Generally, the suppression format of Hdvd and other films is with the starting code 0x00000001.
Source Document: http://msdn.microsoft.com/zh-cn/library/dd757808 (v=vs.85). aspx
(b) Second, through the VLC player, you can view the specific format. After you open the video, you can view the codec format by using the menu "Tools"/"Codec information", for example, codec information:
Code: H264–mpeg-4 AVC (part) (AVC1)
Code: H264–mpeg-4 AVC (part) (H264)
(iii) Finally, after sharing the FFmpeg demux MP4 file, convert the video stream to live555 's experience and methods for direct use of H264 ES streams:
for (AVC1), after Av_read_frame, take the first four bytes for length, replace the first four bytes directly with 0x00,0x00,0x00,0x01, but note that each frame can have more than one naul:
Avpacket PKT;
Avpacket* Packet=&pkt;
Av_init_packet(Packet);
Av_read_frame(CTX, packet);
If(Packet->stream_index==0)
{IS video stream
ConstChar Start_code[4]={0,0,0,1};
If(is_avc_||memcmp(Start_code, packet->data,4)!=0)
{is AVC1 code, with no start code of H264
int Len=0;
uint8_t*p= Packet->data;
Is_avc_= True;
Do
{Add Start_code for each NAL, one frame may has multi nals.
Je= Ntohl(*((Long*) p));
memcpy(p, Start_code,4);
P+=4;
P+ = Len;
if (P >= packet->data + packet->size)
{
&NB Sp break
&NB Sp } while (1
/span>
For another format, (H264), each packet is processed directly on each packet call Av_bitstream_filter_filter:
Bsfc_= Av_bitstream_filter_init("H264_mp4toannexb");
If(PKT->stream_index==0)
{IS video stream
Avbitstreamfiltercontext* BSFC= Bsfc_;
int a;
While(BSFC){
Avpacket NEW_PKT=*pkt;
A= Av_bitstream_filter_filter(BSFC, Encode_ctx_Null,
&new_pkt.Data,&new_pkt.Size,
Pkt->data, PKT->size,
Pkt->flags& Av_pkt_flag_key);
If(A==0&& new_pkt.Data! = PKT->data&& new_pkt.Destruct){
uint8_t*t=(uint8_t*)(NEW_PKT.Size+ ff_input_buffer_padding_size);The new should is a subset of the old so cannot overflow
If(t){
memcpy(t, New_pkt.Data, New_pkt.Size);
memset(t+ NEW_PKT.Size,0, ff_input_buffer_padding_size);
New_pkt.Data= T;
A=1;
}Else
A= Averror(Enomem);
}
If(A>0&& PKT->data! = new_pkt.Data){
Av_free_packet(PKT);
New_pkt.Destruct= Av_destruct_packet;
}ElseIf(A<0){
EnviR() << "!!!!!!!!!! Av_bitstream_filter_filter failed " << ", res= " << a << "\ n ";
}
*pkt = New_pkt;
BSFC = BSFC->next;
}
}
Go MP4 file Two formats differences between AVC1 and H264 and using FFmpeg demux for h264 bitstream matters