Hi,
The h264 stream can be split at SPS/PPS/IDR. Please refer to running 01_video_encode:
- Apply the patch
diff --git a/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp b/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp
index d68d4ec..947e48f 100644
--- a/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp
+++ b/multimedia_api/ll_samples/samples/01_video_encode/video_encode_main.cpp
@@ -224,6 +224,15 @@ encoder_capture_plane_dq_callback(struct v4l2_buffer *v4l2_buf, NvBuffer * buffe
if ( (ctx->enableGDR) && (ctx->GDR_out_file_path) && (num_encoded_frames >= ctx->gdr_out_frame_number+1))
write_encoder_output_frame(ctx->gdr_out_file, buffer);
+#define NAL_UNIT_SPS 7
+uint8_t *data_ptr;
+data_ptr = (uint8_t *)buffer->planes[0].data;
+if (*data_ptr == 0 && *(data_ptr+1) == 0 && *(data_ptr+2) == 0 && *(data_ptr+3) == 1) {
+ if ((*(data_ptr+4) & 0x1F) == NAL_UNIT_SPS)
+ printf("[%d]th: x%02x %02x %02x %02x %02x is SPS/PPS/IDR \n",
+ num_encoded_frames, *data_ptr, *(data_ptr+1), *(data_ptr+2), *(data_ptr+3), *(data_ptr+4));
+}
+
num_encoded_frames++;
if (ctx->report_metadata)
- Rebuild the sample and run
nvidia@nvidia:/usr/src/jetson_multimedia_api/samples/01_video_encode$ ./video_encode /home/nvidia/a.yuv 320 240 H264 /home/nvidia/a.264 -idri 30 --insert-spspps-idr
Creating Encoder in blocking mode
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
875967048
842091865
H264: Profile = 66, Level = 51
[1]th: x00 00 00 01 67 is SPS/PPS/IDR
[31]th: x00 00 00 01 67 is SPS/PPS/IDR
[61]th: x00 00 00 01 67 is SPS/PPS/IDR
[91]th: x00 00 00 01 67 is SPS/PPS/IDR
[121]th: x00 00 00 01 67 is SPS/PPS/IDR
[151]th: x00 00 00 01 67 is SPS/PPS/IDR
[181]th: x00 00 00 01 67 is SPS/PPS/IDR
[211]th: x00 00 00 01 67 is SPS/PPS/IDR
[241]th: x00 00 00 01 67 is SPS/PPS/IDR
[271]th: x00 00 00 01 67 is SPS/PPS/IDR
Could not read complete frame from input file
File read complete.
Got 0 size buffer in capture
App run was successful
It sets IDR interval to 30 and enables inserting SPS/PPS at IDR frames.
You can apply the same and when seeing SPS/PPS/IDR, terminate the current MP4 and start a new MP4.This can get valid MP4 files.
IDR interval can be adjusted per your usecase. For IDR interval=30 in 30fps source, you can see the split point every second.