| Last Modified On : | November 20, 2009 12:11 AM PST |
Rate |
|
void DecodeStream( Ipp8u *cVideoData,int VideoDataSize,
Ipp8u *cYUVData, int& imgWidth, int & imgHeight, int & frameNumber )
{
UMC::Status status; UMC::MediaData DataIn; UMC::VideoData DataOut;
UMC::VideoDecoderParams Params;
UMC::H264VideoDecoder H264Decoder;
int frameSize=0;
DataIn.SetBufferPointer(cVideoData,VideoDataSize);
DataIn.SetDataSize(VideoDataSize);
//use default paramter, threading number=1
Params.m_pData = &DataIn; Params.lFlags=0; Params.numThreads=1;
if(status = H264Decoder.Init(&Params)!=UMC::UMC_OK)
return;
H264Decoder.GetInfo(&Params);
imgWidth=Params.info.clip_info.width; imgHeight=Params.info.clip_info.height;
frameSize = imgWidth*imgHeight*3/2;
DataOut.Init(imgWidth,imgHeight,UMC::YV12,8);
DataOut.SetBufferPointer(cYUVData,frameSize);
int exit_flag=0; frameNumber=0;
do{ status = H264Decoder.GetFrame(&DataIn, &DataOut);
if (status == UMC::UMC_OK){
cYUVData += (frameSize);
DataOut.SetBufferPointer(frameSize);
frameNumber++;
}
if((status !=UMC::UMC_OK)||(frameNumber >=MAXFRAME))
exit_flag = 1;
}while (exit_flag!=1);
do{ status = H264Decoder.GetFrame(NULL, &DataOut);
if (status == UMC::UMC_OK) {
cYUVData += (frameSize);
DataOut.SetBufferPointer(cYUVData,frameSize);
frameNumber++;
}
}while(status == UMC::UMC_OK);
return;
}
void EncodeStream(Ipp8u *cYUVData, int imgWidth, int imgHeight, int frameNumber,
Ipp8u *cVideoData,int &VideoDataSize )
{
UMC::Status status;
UMC::MediaData DataOut; UMC::VideoData DataIn;
UMC::H264EncoderParams Params;
UMC::H264VideoEncoder H264Encoder;;
int FrameSize;
Params.key_frame_controls.method=1;
Params.info.clip_info.height=imgHeight;
Params.info.clip_info.width=imgWidth;
Params.info.bitrate = 1000000;
Params.numThreads = 1;
if((status = H264Encoder.Init(&Params))!=UMC::UMC_OK)
return;
FrameSize = imgWidth*imgHeight*3/2;
DataIn.Init(imgWidth,imgHeight,UMC::YV12,8);
DataIn.SetBufferPointer(cYUVData,FrameSize);
DataIn.SetDataSize(FrameSize);
DataOut.SetBufferPointer(cVideoData,MAXVIDEOSIZE);
VideoDataSize=0;
int nEncodedFrames=0;
while ( nEncodedFrames < frameNumber)
{
status = H264Encoder.GetFrame(&DataIn, &DataOut);
if (status == UMC::UMC_OK)
{
nEncodedFrames++;
VideoDataSize+=DataOut.GetDataSize();
DataOut.MoveDataPointer(DataOut.GetDataSize());
cYUVData+=FrameSize;
DataIn.SetBufferPointer(cYUVData,FrameSize);
DataIn.SetDataSize(FrameSize);
}
}
return;
}
void EncodeStream(vm_char * inputfilename, vm_char * outputfilename )
{
Ipp32u videoTrack=0; int exit_flag =0;
UMC::Status status;
UMC::MediaData in; UMC::VideoData out;
UMC::FIOReader reader; UMC::FileReaderParams readerParams;
UMC::SplitterParams splitterParams; UMC::SplitterInfo * streamInfo;
UMC::MP4Splitter Splitter;
UMC::VideoStreamInfo *videoInfo=NULL;
UMC::VideoDecoder * videoDecoder; UMC::VideoDecoderParams videoDecParams;
UMC::FWVideoRender fwRender; UMC::FWVideoRenderParams fwRenderParams;
readerParams.m_portion_size = 0;
vm_string_strcpy(readerParams.m_file_name, inputfilename);
if((status = reader.Init(&readerParams))!= UMC::UMC_OK)
return;
splitterParams.m_lFlags = UMC::VIDEO_SPLITTER;
splitterParams.m_pDataReader = &reader;
if((status = Splitter.Init(splitterParams))!= UMC::UMC_OK)
return;
Splitter.GetInfo(&streamInfo);
for (videoTrack = 0; videoTrack < streamInfo->m_nOfTracks; videoTrack++) {
if (streamInfo->m_ppTrackInfo[videoTrack]->m_Type == UMC::TRACK_H264)
break;
}
videoInfo = (UMC::VideoStreamInfo*)(streamInfo->m_ppTrackInfo[videoTrack]->
m_pStreamInfo);
if(videoInfo->stream_type!=UMC::H264_VIDEO)
return;
videoDecParams.info = (*videoInfo);
videoDecParams.m_pData = streamInfo->m_ppTrackInfo[videoTrack]->m_pDecSpecInfo;
videoDecParams.numThreads = 1;
videoDecoder = (UMC::VideoDecoder*)(new UMC::H264VideoDecoder());
if((status = videoDecoder->Init(&videoDecParams))!= UMC::UMC_OK)
return;
fwRenderParams.out_data_template.Init(videoInfo->clip_info.width, videoInfo->clip_info.height,
videoInfo->color_format);
fwRenderParams.pOutFile = outputfilename;
if(status = fwRender.Init(&fwRenderParams)!= UMC::UMC_OK)
return;
Splitter.Run();
do{
do{
if (in.GetDataSize() < 4) {
do{ status= Splitter.GetNextData(&in,videoTrack);
if(status==UMC::UMC_ERR_NOT_ENOUGH_DATA)
vm_time_sleep(5);
}while(status==UMC::UMC_ERR_NOT_ENOUGH_DATA);
if(((status != UMC::UMC_OK) && (status != UMC::UMC_ERR_END_OF_STREAM))||
(status == UMC::UMC_ERR_END_OF_STREAM)&& (in.GetDataSize()<4)) {
exit_flag=1;
}
}
fwRender.LockInputBuffer(&out);
videoDecoder->GetFrame(&in,&out);
fwRender.UnLockInputBuffer(&out);
fwRender.RenderFrame();
}while(!exit_flag&&(status ==UMC::UMC_ERR_NOT_ENOUGH_DATA||status==UMC::UMC_ERR_SYNC));
}while (exit_flag!=1);
do{
fwRender.LockInputBuffer(&out);
status = videoDecoder->GetFrame(NULL,&out);
fwRender.UnLockInputBuffer(&out);
fwRender.RenderFrame();
}while(status == UMC::UMC_OK);
}
void EncodeStream (Ipp8u *cYUVData, int imgWidth, int imgHeight, int frameNumber,
vm_char * tsFileName) { UMC::Status status; UMC::MediaData DataOut, MuxData; UMC::VideoData DataIn; UMC::H264EncoderParams Params; UMC::H264VideoEncoder H264Encoder; UMC::MPEG2Muxer Muxer; UMC::MPEG2MuxerParams MuxerParams; Ipp8u *cMaxVideoData=NULL;
int FrameSize; UMC::VideoStreamInfo VideoInfo; UMC::FileWriter Writer; UMC::FileWriterParams WriterParams; strcpy(WriterParams.m_file_name, tsFileName); Writer.Init(&WriterParams); MuxerParams.m_lpDataWriter = &Writer; MuxerParams.m_SystemType = UMC:: MPEG2_TRANSPORT_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=1000000; 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 = 1000000; Params.numThreads = 1; if((status = H264Encoder.Init(&Params))!=UMC::UMC_OK) return;
FrameSize = imgWidth*imgHeight*3/2; cMaxVideoData= ippsMalloc_8u(MAXAFRAMESIZE); DataIn.Init(imgWidth,imgHeight,UMC::YV12,8); DataIn.SetBufferPointer(cYUVData,FrameSize); DataIn.SetDataSize(FrameSize); 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)/30);
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+=FrameSize;
DataIn.SetBufferPointer(cYUVData,FrameSize);
DataIn.SetDataSize(FrameSize);
DataOut.SetBufferPointer(cMaxVideoData,MAXAFRAMESIZE); } } Muxer.Close(); return; }
Change DataIn.SetBufferPointer(cYUVData,imgWidth*imgHeight*3/2); to // Compared to I420 (YUV) plans are in YV12 (YVU) //LPBYTE pSrcY = cYUVData; //LPBYTE pSrcU = pDestY + (imgWidth * imgHeight); //LPBYTE pSrcV = pDestU + ((imgWidth * imgHeight) / 4); DataIn.SetPlanePointer(pSrcY, 0); // Y DataIn.SetPlanePointer(pSrcU, 1); // U DataIn.SetPlanePointer(pSrcV, 2); // V
| March 9, 2009 5:30 PM PDT
Sharon Greenfield (Intel)
|
Robert, I just tested it, and it does via javascript pop up another window and let me download the file. If you are unable to get to the perl file that way, you are welcome to download it directly from: http://software.intel.com/file/7781 Thanks, Sharon |
| June 3, 2009 8:12 PM PDT
Pradeep |
Hi, In the above simple encoder inside the function EncodeStream, you mention the following initialization: UMC::H264EncoderParams Params; UMC::H264VideoEncoder H264Encoder; But when I run i get the following error: error C2039: 'H264EncoderParams' : is not a member of 'UMC' error C2065: 'H264EncoderParams' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'Params' error C2065: 'Params' : undeclared identifier error C2039: 'H264VideoEncoder' : is not a member of 'UMC' ..... Please let me know the reason. Thanks, Pradeep |
| June 3, 2009 8:42 PM PDT
Chao Y (Intel)
|
Pradeep, Have you downloaded the full sampe or just copy & past the code from the webpage? It looks that you missed some head file here. thanks, Chao |
| June 3, 2009 8:49 PM PDT
Pradeep |
I used the full sample file. Thanks, Pradeep |
| June 4, 2009 11:16 AM PDT
Pradeep |
I would appreciate if you could point me to the missing information in the sample encoder file. Thanks, Pradeep |
| June 16, 2009 2:28 AM PDT
Ying H (Intel)
|
Hi Pradeep, The parameter H264EncoderParams is defined in the header file "umc_h264_video_encoder.h". Could you pleae check if the line #include "umc_h264_video_encoder.h" are in your code? Regards, Ying |
| June 16, 2009 10:36 AM PDT
DEN |
I am trying to play MPEG4 DIVX4 video stream using “Creating a simple decoder”, but something goes wrong. Sample of my stream (~700kb) can be downloaded here: http://www.sendspace.com/file/05i13q The only change I made is I replaced UMC::H264VideoDecoder with UMC::MPEG4VideoDecoder. I've got an error on UMC::MPEG4VideoDecoder::GetFrame. The error depends on the output color format I request. This is strange - the stream is pure MPEG4 DIVX4 stream, why IPP can't decode it? Or maybe “Creating a simple decoder” is incomplete and I should add some additional initialization? Btw, VLC Player plays that stream fine. |
| June 16, 2009 7:18 PM PDT
Chao Y (Intel)
|
DEN, any other place to download the stream? The URL does not looks to work here: http://www.sendspace.com/file/05i13q |
| June 16, 2009 7:49 PM PDT
DEN | Chao Yu, sure, try this direct link: http://www.insidecpp.ru/stream.bin |
| June 16, 2009 8:54 PM PDT
Chao Y (Intel)
| This looks to be a corrupted stream. When I tried other tools (e.g FFMPEG), it reported many errors. Is this expected? |
| June 19, 2009 12:15 PM PDT
boggy550326
| In simple decoder sample, the whole H264 data are read into a big buffer and then passed to decoder.This works fine. In my case, I have to read the H264 data in a loop in 64k block and decode them, the generated YUV data has some lost frames. |
| June 21, 2009 6:24 AM PDT
Chao Y (Intel)
| This example code are simple code. For more complex example on using UMC, you can refer to the "simpleplayer" application in the UMC example. |
| July 23, 2009 12:59 AM PDT
Richard Koslik |
Hello, is there also a working example for delphi language? I can't find any delphi dll wrapper units in the "ipp-samples" package for decoding MPEG4 or H264. Only a simple image processing example which does not use the required dll for decoding... In my application i need to display RAW MPEG4 frames(24bit) from a stream. I have already the frame in memory and need now to decode... Can anybody help please? Thanks in advise, richard. |
| August 15, 2009 11:13 AM PDT
Heidarian
|
ِDear I created new console app. project in VS 2008 and added simpledecoder.cpp to project, and also add the following directory to include path of project: ..audio-video-codecscoreumcinclude ..audio-video-codecscodech264_decinclude ..audio-video-codecscorevminclude (nothing else added to "Executable files" and "Library files") when I build the project in debug mode I got 17 errors of LNK2019 type, some of them are as follow: 1>simpledecoder.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall UMC::H264VideoDecoder::GetFrame(class UMC::MediaData *,class UMC::MediaData *)" (?GetFrame@H264VideoDecoder@UMC@@UAEHPAVMediaData@2@0@Z) referenced in function "void __cdecl DecodeStream(unsigned char *,int,unsigned char *,int &,int &,int &)" (?DecodeStream@@YAXPAEH0AAH11@Z) 1>simpledecoder.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall UMC::VideoData::SetBufferPointer(unsigned char *,unsigned int)" (?SetBufferPointer@VideoData@UMC@@UAEHPAEI@Z) referenced in function "void __cdecl DecodeStream(unsigned char *,int,unsigned char *,int &,int &,int &)" (?DecodeStream@@YAXPAEH0AAH11@Z) Could anyone tell me what is the problem? Should I add any more path? Thanks in advance |
| August 15, 2009 11:15 AM PDT
Heidarian
|
ِDear I created new console app. project in VS 2008 and added simpledecoder.cpp to project, and also add the following directory to include path of project: ..audio-video-codecscoreumcinclude ..audio-video-codecscodech264_decinclude ..audio-video-codecscorevminclude (nothing else added to "Executable files" and "Library files") when I build the project in debug mode I got 17 errors of LNK2019 type, some of them are as follow: 1>simpledecoder.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall UMC::H264VideoDecoder::GetFrame(class UMC::MediaData *,class UMC::MediaData *)" (?GetFrame@H264VideoDecoder@UMC@@UAEHPAVMediaData@2@0@Z) referenced in function "void __cdecl DecodeStream(unsigned char *,int,unsigned char *,int &,int &,int &)" (?DecodeStream@@YAXPAEH0AAH11@Z) 1>simpledecoder.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall UMC::VideoData::SetBufferPointer(unsigned char *,unsigned int)" (?SetBufferPointer@VideoData@UMC@@UAEHPAEI@Z) referenced in function "void __cdecl DecodeStream(unsigned char *,int,unsigned char *,int &,int &,int &)" (?DecodeStream@@YAXPAEH0AAH11@Z) Could anyone tell me what is the problem? Should I add any more path? Thanks in advance |
| August 15, 2009 11:17 AM PDT
Heidarian
|
ِDear I created new console app. project in VS 2008 and added simpledecoder.cpp to project, and also add the following directory to include path of project: ..audio-video-codecscoreumcinclude ..audio-video-codecscodech264_decinclude ..audio-video-codecscorevminclude (nothing else added to "Executable files" and "Library files") when I build the project in debug mode I got 17 errors of LNK2019 type, some of them are as follow: 1>simpledecoder.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall UMC::H264VideoDecoder::GetFrame(class UMC::MediaData *,class UMC::MediaData *)" (?GetFrame@H264VideoDecoder@UMC@@UAEHPAVMediaData@2@0@Z) referenced in function "void __cdecl DecodeStream(unsigned char *,int,unsigned char *,int &,int &,int &)" (?DecodeStream@@YAXPAEH0AAH11@Z) Could anyone tell me what is the problem? Should I add any more path? Thanks in advance |
| August 24, 2009 10:36 AM PDT
Michael |
Why does the simple player, this example, and mpeg2 encoder encode swizzle of color streams - also known as BROKEN. Heres my test code. //Open mpg FILE *pFile = fopen("C:/MPEG2.mpg", "rb"); //Get length of file fseek(pFile, 0, SEEK_END); fpos_t nFilePos; fgetpos(pFile, &nFilePos); //Reset it and allocate fseek(pFile, 0, SEEK_SET); Ipp8u *cYUVData = ippsMalloc_8u(static_cast<unsigned int>(nFilePos)); //unsigned char *pVidInBuf = new unsigned char[]; //Read into it size_t unBytesRead = fread(cYUVData, static_cast<unsigned int>(nFilePos), 1, pFile); #define MAXVIDEOSIZE 100000000 #define MAXYUVSIZE 200000000 Ipp8u *cVideoData = ippsMalloc_8u(MAXVIDEOSIZE); // //Encoder int nWidth = 720; int nHeight = 480; UMC::Status status; MediaData DataOut; VideoData DataIn; MPEG2VideoEncoder enc; MPEG2EncoderParams Params; Params.info.clip_info.width = nWidth; Params.info.clip_info.height = nHeight; Params.info.bitrate = 4000000; Params.info.framerate = 30; status = enc.Init(&Params); if(status != UMC_OK) { return 0; } //set data in //oops twice... i think mpeg is yuv420. DataIn.Init(nWidth, nHeight, UMC::YUV420, 8); DataIn.SetBufferPointer(cYUVData, nWidth * nHeight * 3 / 2); DataIn.SetDataSize(nWidth*nHeight*3/2); //wondering if the div 2 is a alignment or something DataOut.SetBufferPointer(cVideoData, MAXVIDEOSIZE); int VideoDataSize=0; int nEncodedFrames=0; int frameNumber = 22; while ( nEncodedFrames < frameNumber) { status = enc.GetFrame(&DataIn, &DataOut); if (status == UMC::UMC_OK) { nEncodedFrames++; VideoDataSize+=DataOut.GetDataSize(); DataOut.MoveDataPointer(DataOut.GetDataSize()); cYUVData+=nWidth*nHeight*3/2; DataIn.SetBufferPointer(cYUVData,nWidth*nHeight*3/2); DataIn.SetDataSize(nWidth*nHeight*3/2); } } FILE *pfOut = fopen("C:/out.mpg", "wb"); //oops lollers int nWriteCount = fwrite(cVideoData, VideoDataSize, 1, pfOut); fclose(pfOut); |
| August 31, 2009 1:57 AM PDT
YanQin |
Hi, I manage to encode h.264 video with the sample code of simple encoder. However the colour of the encoded video is not correct. May I know how could i solve the problem? Thanks in advance |
| October 13, 2009 8:38 PM PDT
Chao Y (Intel)
|
Heidarian, For the linkage errors, it looks that you missed a few UMC libraries. You can follow the example project file at udio-video-codecsapplicationsimple_playersimple_player.sln 1>simpledecoder.obj : error LNK2019: unresolved external symbol "public: virtual int __thiscall UMC::H264VideoDecoder::GetFrame(class UMC::MediaData *,class UMC::MediaData *)" (?GetFrame@H264VideoDecoder@UMC@@UAEHPAVMediaData@2@0@Z) referenced in function "void __cdecl DecodeStream(unsigned char *,int,unsigned char *,int &,int &,int &)" (?DecodeStream@@YAXPAEH0AAH11@Z) Open solution file, right click the Solution, Check "Common Properties""Project Dependencies", Select "simple_player" project, you can find that it depends on other UMC libraries. Thanks, Chao |
| October 13, 2009 8:50 PM PDT
Chao Y (Intel)
|
YanQin, For the question: "I manage to encode h.264 video with the sample code of simple encoder. However the colour of the encoded video is not correct. May I know how could i solve the problem?" What is the input video format? This sample code assume the input data is YUV420. For each frame, Y data first, then U and V. Regards, Chao |

English | 中文 | Русский | Français
Chao Y (Intel)
|
Robert
I can't seem to download the GenSlu.pl perl script from the link on this page:
http://software.intel.com/en-us/articles/creating-microsoft-.....ect-files/
Would you please provide a live link or send the script directly.
Thank you,
Robert