Hi team,
we need capture video and encoded h264 data and save as mp4 format. but we get the wrong image when play back the mp4 file ,the color of image is pink,
we used a mem block to save nv12 data and read_video_frame from the block and fill to NvBuffer, when i used write_video_frame to save the data, it is pink too,so it seemed before i send the data to v4l2_buffer, it was wrong. anyone can help me to check the read video code?
int ArgusCameraCapture::read_video_frame(NvBuffer &buffer)
{
raw_buf encode_buf_data;
while (true)
{
bool queue_ret = encode_raw_buf_queue->wait_dequeue_timed(encode_buf_data, 1000);
if (!queue_ret)
{
usleep(1 * 1000);
continue;
}
else
{
break;
}
}
char *buf = encode_buf_data.mipi_data;
// // write_test
// if (test1)
// {
// u1fstream->write(encode_buf_data.mipi_data, 2896 * 1880 * 1.5);
// test1=0;
// }
for (int encode_i = 0; encode_i < buffer.n_planes; encode_i++)
{
NvBuffer::NvBufferPlane &plane = buffer.planes[encode_i];
// printf("n_planes %d\n", buffer.n_planes);
std::streamsize bytes_to_read = plane.fmt.bytesperpixel * plane.fmt.width;
// printf("bytes_to_read %d plane.fmt.bytesperpixel %d plane.fmt.width %d \n", bytes_to_read, plane.fmt.bytesperpixel, plane.fmt.width);
char *data = (char *)plane.data;
plane.bytesused = 0;
int index = 0;
for (int encode_j = 0; encode_j < plane.fmt.height; encode_j++)
{
// printf("1---------------------\n");
memcpy(data, buf + index, bytes_to_read);
index += bytes_to_read;
// printf("buffer->n_planes %d now%d plane.fmt.height %d now %d stride %d\n", buffer.n_planes, encode_i, plane.fmt.height, encode_j, plane.fmt.stride);
data += plane.fmt.stride;
// printf("plane.fmt.stride %d plane.fmt.height %d \n", plane.fmt.stride, plane.fmt.height);
}
plane.bytesused = plane.fmt.stride * plane.fmt.height;
// printf("plane.bytesused %d\n", plane.bytesused);
}
encode_mempool_queue->enqueue(encode_buf_data);
// if (test2){
// write_video_frame(ufstream, buffer);
// test2=0;
// }
return 0;
}