I decode h264 file with DecodeFrameNoDelay
function and get yuvData
buffer
I want write the yuvData
buffer to file .yuv and play with ffmpeg command. But when I play yuv file with ffmpeg command the result is not correct.
This is ffmpeg command I use to play yuv file:
ffplay -f rawvideo -pix_fmt yuv420p -video_size 1280x720 input_video.yuv
This is my code use to decode h264 file and write yuvData
buffer to file .yuv
void init(int width, int height) {
WelsCreateDecoder(&decoder);
decodingParam = {0};
decodingParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
decoder->Initialize(&decodingParam);
bufferInfo = {0};
bufferInfo.iBufferStatus = 1;
yuvData = new uint8_t*[3];
yuvData[0] = new uint8_t[width * height];
yuvData[1] = new uint8_t[width * height / 4];
yuvData[2] = new uint8_t[width * height / 4];
}
bool decode(const unsigned char* rawEncodedData, int rawEncodedDataLength, uint8_t** yuvData, char *name) {
int err = decoder->DecodeFrameNoDelay(rawEncodedData, rawEncodedDataLength, yuvData, &bufferInfo);
int width = bufferInfo.UsrData.sSystemBuffer.iWidth;
int height = bufferInfo.UsrData.sSystemBuffer.iHeight;
FILE *pFile = fopen(std::string("screen.yuv").c_str(), "ab");
fwrite(yuvData[0], 1, width * height, pFile);
fwrite(yuvData[1], 1, width * height / 4, pFile);
fwrite(yuvData[2], 1, width * height / 4, pFile);
fclose(pFile);
std::cout << width << height << std::endl;
if (err != 0) {
std::cout << "H264 decoding failed. Error code: " << err << "." << std::endl;
parseErrorCode(err);
return false;
}
printf("H264 decoding success, err: %d, name: %s, status: %d\n", err, name, bufferInfo.iBufferStatus);
return true;
}
I have some question need make clear:
1/yuvData
buffer I get from DecodeFrameNoDelay
function is really yuv420
format ?
2/Something wrong with my code ?
Any help is appreciated.
Thanks and best regards.