Hello,all
I try to get the avc1 raw data from the .mp4 file.Added the pps and sps into
.h264,the .h264 file is flushing when play it in vlc. please give some advise.
There are my code.
if (movie != NULL) {
AP4_List<AP4_Track>& tracks = movie->GetTracks();
AP4_Debug("Found %d Tracks\n", tracks.ItemCount());
// get video track
To write the AVC (H.264) data from an MP4 file, you will need to read the access units and write them out. You might also need the picture set parameters from the sample description.
It looks like you're on the right track with the code above. I have not fully analyzed it, because I'd like to ask you a question first:
in which format would you like the H.264 output? Do you want NALs? Do you want MP4 access units? Something else?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,all
I try to get the avc1 raw data from the .mp4 file.Added the pps and sps into
.h264,the .h264 file is flushing when play it in vlc. please give some advise.
There are my code.
if (movie != NULL) {
AP4_List<AP4_Track>& tracks = movie->GetTracks();
AP4_Debug("Found %d Tracks\n", tracks.ItemCount());
// get video track
AP4_Track* video_track = movie->GetTrack(AP4_Track::TYPE_VIDEO);
if (video_track != NULL) {
// show info
AP4_Debug("Video Track:\n");
AP4_Debug(" duration: %ld ms\n", video_track->GetDurationMs());
AP4_Debug(" sample count: %ld\n", video_track->GetSampleCount());
AP4_TrakAtom* mp4_Video_Track = video_track->GetTrakAtom();
AP4_Debug(" mp4_Video_Track duration: %ld ms\n", mp4_Video_Track->GetDuration());
AP4_StsdAtom* mp4_Video_StsdAtom = (AP4_StsdAtom*)mp4_Video_Track->FindChild("mdia/minf/stbl/stsd");
AP4_AvccAtom* mp4_Video_AvccAtom = (AP4_AvccAtom*)mp4_Video_StsdAtom->FindChild("avc1/avcC");
//AP4_Ordinal len =mp4_Video_AvccAtom->GetLengthSize();
AP4_Ordinal sindex = mp4_Video_AvccAtom->GetSequenceParameters().ItemCount();
AP4_Ordinal pindex = mp4_Video_AvccAtom->GetPictureParameters().ItemCount();
/*WriterAvccHeader(output);
output->Write(mp4_Video_AvccAtom->GetSequenceParameters()[0].GetData(),mp4_Video_AvccAtom->GetSequenceParameters()[0].GetDataSize());
WriterAvccHeader(output);
output->Write(mp4_Video_AvccAtom->GetPictureParameters()[0].GetData(),mp4_Video_AvccAtom->GetPictureParameters()[0].GetDataSize());*/
AP4_StssAtom *mp4_StssAtom = (AP4_StssAtom*)mp4_Video_Track->FindChild("mdia/minf/stbl/stss");
AP4_Sample sample;
AP4_DataBuffer data;
AP4_Ordinal index =1;
while (AP4_SUCCEEDED(video_track->ReadSample(index, sample, data))) {
if(mp4_StssAtom->IsSampleSync(index))
{
WriterAvccHeader(output);
output->Write(mp4_Video_AvccAtom->GetSequenceParameters()[0].GetData(),mp4_Video_AvccAtom->GetSequenceParameters()[0].GetDataSize());
WriterAvccHeader(output);
output->Write(mp4_Video_AvccAtom->GetPictureParameters()[0].GetData(),mp4_Video_AvccAtom->GetPictureParameters()[0].GetDataSize());
AP4_Debug(" [%d] sync sample writing %ld bytes of data...\n",
index, sample.GetSize());
}
WriterAvccHeader(output);
output->Write(data.GetData()+4, data.GetDataSize()-4);
AP4_Debug(" [%d] writing %ld bytes of data...\n",
index, sample.GetSize());
index++;
}
} else {
AP4_Debug("No Video track found\n");
}
} else {
AP4_Debug("No Movie in file\n");
}
To write the AVC (H.264) data from an MP4 file, you will need to read the access units and write them out. You might also need the picture set parameters from the sample description.
It looks like you're on the right track with the code above. I have not fully analyzed it, because I'd like to ask you a question first:
in which format would you like the H.264 output? Do you want NALs? Do you want MP4 access units? Something else?