I depacketize the H264 video fragments from an IP.RTP stream and save them to video.ivf file. After depacketizing i have only [SPS] ,[PPS] and [non-IDR slice]. I try to create IDR slice by using x264 lib. x264 lib creates IDR frame which consists of 0x000001[SPS] 0x000001[PPS] 0x0001[SE slice] and 0x0001[I slice]. i insert it in the beginning of my file. But when i try to play this with VLC player it doesn't plays well. if i convert it to video.mp4 by ffmpeg i get playablr file. I think the problem is that after creating IDR frame with x264 lib I get SPS and PPS frames different from those that I get from the stream. My question is how to set parameters for x264 if i have real SPS and PPS frames to get the same SPS and PPS frames.
Here is my code:
x264_param_t param;
`x264_param_t param`;
`/* Get default params for preset/tuning */
x264_param_default_preset(¶m, "medium", NULL);`
`/* Configure non-default params */
param.i_csp = X264_CSP_I420;
param.i_width = width;//640 GET FROM SPS !!!!!!!!!!
param.i_height = height;//360; GET FROM SPS !!!!!!!!!!!!!!
param.b_vfr_input = 0; //frame rate
param.b_repeat_headers = 1;
param.b_annexb = 1;
`x264_t *encoder = x264_encoder_open(¶m);`
if (encoder)
{
// These are the two picture structs. Input must be alloc()
// Output will be created by the encode process
x264_picture_t pic, pic_out;
int r = x264_picture_alloc(&pic, X264_CSP_I420, width, height);
if (r == 0)
{
pic.i_type = X264_TYPE_IDR;
int y_bytes = width * height;
int uv_bytes = width * height / 4;
UCHAR* result = pic.img.plane[0];
// luma
for (unsigned int y = 0; y < height; y++)
{
for (unsigned int x = 0; x < width; x++)
pic.img.plane[0][y * width + x] = 0x16;
}
// chroma
for (unsigned int y = 0; y < height / 2; y++)
{
for (unsigned int x = 0; x < width / 2; x++)
{
pic.img.plane[1][y * width / 2 + x] = 0x16;
pic.img.plane[2][y * width / 2 + x] = 0x80;
}
}
int i_frame_size = x264_encoder_encode(encoder, &nal, &i_nal, &pic, &pic_out);
}
}`
Maybe i should set another parameters for x264_param_t param which i can get from SPS and PPS
can someone help me with this issue