Link Copied
Hi,
I was trying (mistakingly) to mux an MP2 video stream into .mp4 file using the UMC:: MP4Muxer.
Multiplexing an MPEG4 encoded video with UMC:: MP4Muxer resulted in a prety playable .mp4 file (thanks to IPP guys).
Regarding the muxer function call sequence, PutData() encapsulates the necessary calls to Lock/UnlocBuffer functions.
I still have the question about the MP4 file type version, why version "1"?!
Best regards,
Tamer Assad#include
#include
#include "ipp.h"
#include "umc_defs.h"
#include "umc_video_data.h"
#include "umc_h264_video_encoder.h"
#include "umc_structures.h"
#include "umc_video_encoder.h"
#include "umc_mpeg2_muxer.h"
#include "umc_mp4_mux.h"
#include "umc_file_writer.h"
#include "vm_time.h"
#include "vm_strings.h"
#define MAXAFRAMESIZE 1000000
#define MAXYUVSIZE 200000000
void EncodeStream(Ipp8u *cYUVData, int imgWidth, int imgHeight, int frameNumber,char * tsFileName)
{
UMC::Status status;
UMC::MediaData DataOut, MuxData; UMC::VideoData DataIn;
UMC::H264EncoderParams Params; UMC::H264VideoEncoder H264Encoder;
// UMC::MPEG2Muxer Muxer; UMC::MPEG2MuxerParams MuxerParams;
UMC::MP4Muxer Muxer;
UMC::MuxerParams MuxerParams;
Ipp8u *cMaxVideoData=NULL;
UMC::VideoStreamInfo VideoInfo;
UMC::FileWriter Writer; UMC::FileWriterParams WriterParams;
strcpy(WriterParams.m_file_name, VM_STRING(tsFileName));
Writer.Init(&WriterParams);
MuxerParams.m_lpDataWriter = &Writer;
//MuxerParams.m_SystemType = UMC:: MPEG2_TRANSPORT_STREAM;
MuxerParams.m_SystemType = UMC::MPEG4_PURE_VIDEO_STREAM;
MuxerParams.m_nNumberOfTracks = 1;
MuxerParams.pTrackParams = new UMC::TrackParams[MuxerParams.m_nNumberOfTracks];
VideoInfo.clip_info.height=imgHeight; VideoInfo.clip_info.width=imgWidth;
VideoInfo.stream_type=UMC::H264_VIDEO;
VideoInfo.color_format=UMC::YV12; VideoInfo.interlace_type=UMC::PROGRESSIVE;
VideoInfo.bitrate=64000000; VideoInfo.streamPID=0;
MuxerParams.pTrackParams[0].type = UMC::VIDEO_TRACK;
MuxerParams.pTrackParams[0].info.video = &VideoInfo;
MuxerParams.pTrackParams[0].bufferParams.m_prefInputBufferSize=2000000;
MuxerParams.pTrackParams[0].bufferParams.m_prefOutputBufferSize=2000000;
if((status =Muxer.Init(&MuxerParams))!=UMC::UMC_OK)
return;
Params.info.clip_info.height=imgHeight; Params.info.clip_info.width=imgWidth;
Params.info.bitrate = 64000000;
Params.numThreads = 1;
if((status = H264Encoder.Init(&Params))!=UMC::UMC_OK)
return;
cMaxVideoData= ippsMalloc_8u(MAXAFRAMESIZE);
DataIn.Init(imgWidth,imgHeight,UMC::YV12,8);
DataIn.SetBufferPointer(cYUVData,imgWidth*imgHeight*3/2);
DataIn.SetDataSize(imgWidth*imgHeight*3/2);
DataOut.SetBufferPointer(cMaxVideoData,MAXAFRAMESIZE);
int nEncodedFrames=0;
while ( nEncodedFrames < frameNumber)
{
status = H264Encoder.GetFrame(&DataIn, &DataOut);
if (status == UMC::UMC_OK) {
nEncodedFrames++;
MuxData.SetBufferPointer((Ipp8u*)DataOut.GetBufferPointer(),DataOut.GetDataSize());
memcpy(MuxData.GetDataPointer(),DataOut.GetDataPointer(), DataOut.GetDataSize());
MuxData.SetDataSize(DataOut.GetDataSize());
MuxData.SetTime(nEncodedFrames*((double)1.0)/15);
do {
status = Muxer.PutVideoData(&MuxData);
if (UMC::UMC_ERR_NOT_ENOUGH_BUFFER == status)
vm_time_sleep(5);
}while (UMC::UMC_ERR_NOT_ENOUGH_BUFFER == status);
cYUVData+=imgWidth*imgHeight*3/2;
DataIn.SetBufferPointer(cYUVData,imgWidth*imgHeight*3/2);
DataIn.SetDataSize(imgWidth*imgHeight*3/2);
DataOut.SetBufferPointer(cMaxVideoData,MAXAFRAMESIZE);
}
}
Muxer.Close();
return;
}
void ReadYUVData(char* strFilename,Ipp8u *cYUVData, int imgWidth, int imgHeight, int frameNumber)
{
FILE* infp = fopen(strFilename, "rb");
if(infp==NULL)
return ;
fread(cYUVData,1,frameNumber*imgWidth*imgHeight*3/2, infp);
fclose(infp);
}
int main(int argc, vm_char* argv[]) {
ippStaticInit();
Ipp8u *cYUVData = ippsMalloc_8u(MAXYUVSIZE);
int VideoDataSize;
ReadYUVData("stream352x288.yuv",cYUVData,352,288,200);
EncodeStream(cYUVData,352,288,200,"testout.mp4");
return 0;
}
For more complete information about compiler optimizations, see our Optimization Notice.