Can not playback recording videos on TX2

Dear all,

Now I can record video and mux to mp4 file as well. Beside that I tried to split to many videos with specific duration such as 1 minute or 2 minutes. It’s almost finish, I could playback recording video file on PC size with all of media players but I could not playback with TX2 default media player. Only very first recording video files could playback on TX2.

This’s my encoder setting

ctx->enc = NvVideoEncoder::createVideoEncoder(enc_index_string);
    if (ctx->enc == NULL)
        ERROR_RETURN("Failed to create video encoder");

    if (ctx->enc->setCapturePlaneFormat(V4L2_PIX_FMT_H264, ctx->cam_w,
                ctx->cam_h, 4 * 1024 * 1024) < 0)
        ERROR_RETURN("Failed to set up ENC capture plane format");

    if (ctx->enc->setOutputPlaneFormat(V4L2_PIX_FMT_YUV420M, ctx->cam_w,
                ctx->cam_h) < 0)
        ERROR_RETURN("Failed to set up ENC output plane format");

    if (ctx->enc->setBitrate(ctx->bit_rate) < 0)
        ERROR_RETURN("Failed to set up ENC bitrate");

    if (ctx->enc->setProfile(V4L2_MPEG_VIDEO_H264_PROFILE_HIGH) < 0)
        ERROR_RETURN("Failed to set up ENC profile");

    if (ctx->enc->setLevel(V4L2_MPEG_VIDEO_H264_LEVEL_5_0) < 0)
        ERROR_RETURN("Failed to set up ENC level");

    if (ctx->enc->setRateControlMode(V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) < 0)
        ERROR_RETURN("Failed to set up ENC rate control mode");

    if (ctx->enc->setIFrameInterval(5) < 0)
        ERROR_RETURN("Failed to set up ENC frame interval");

    if (ctx->enc->setIDRInterval(5) < 0)
    	ERROR_RETURN("Failed to set up ENC IDR interval");

    if (ctx->enc->setFrameRate(30,1) < 0)
        ERROR_RETURN("Failed to set up ENC frame rate");

    if (ctx->enc->setInsertSpsPpsAtIdrEnabled(true) < 0)
    	ERROR_RETURN("Failed to set SpsPps enable");

    if (ctx->enc->setHWPresetType(V4L2_ENC_HW_PRESET_ULTRAFAST) < 0)
        ERROR_RETURN("Failed to set up ENC HW PRESET ALTRAFAST");

    if (ctx->enc->output_plane.setupPlane(V4L2_MEMORY_DMABUF, 10, true, false) < 0)
        ERROR_RETURN("Failed to set up ENC output plane");

    if (ctx->enc->capture_plane.setupPlane(V4L2_MEMORY_MMAP, 10, true, false) < 0)
        ERROR_RETURN("Failed to set up ENC capture plane");

This is very first recording video that could playback on TX2

https://drive.google.com/open?id=1E9s4ieppw0k6Sn9DgSCA7GLOXzmRseor

And recording video that could not playback on TX2

https://drive.google.com/open?id=1h2b3kh2VZHG-aKEQWaoQZ3tCw4yEdMu6

Thanks and Best Regards,
Vu Nguyen

Hi Vu,
It looks like the information mismatches:

ubuntu@tegra-ubuntu:~$ gst-launch-1.0 filesrc location= HY_0241_20180126_040406_N_CH1.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvoverlaysink
Setting pipeline to PAUSED ...
Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and MjstreamingPipeline is PREROLLING ...
NvMMLiteOpen : Block : BlockType = 261
TVMR: NvMMLiteTVMRDecBlockOpen: 7580: NvMMLiteBlockOpen
NvMMLiteBlockCreate : Block : BlockType = 261
TVMR: cbBeginSequence: 1166: BeginSequence  2560x720, bVPR = 0, fFrameRate = 0.000000
TVMR: LowCorner Frequency = 180000
TVMR: cbBeginSequence: 1545: DecodeBuffers = 3, pnvsi->eCodec = 4, codec = 0
TVMR: cbBeginSequence: 1606: Display Resolution : (2560x720)
TVMR: cbBeginSequence: 1607: Display Aspect Ratio : (2560x720)
TVMR: cbBeginSequence: 1649: ColorFormat : 5
TVMR: cbBeginSequence:1660 ColorSpace = NvColorSpace_YCbCr709
TVMR: cbBeginSequence: 1790: SurfaceLayout = 3
TVMR: cbBeginSequence: 1868: NumOfSurfaces = 7, InteraceStream = 0, InterlaceEnabled = 0, bSecure = 0, MVC = 0 Semiplanar = 1, bReinit = 1, BitDepthForSurface = 8 LumaBitDepth = 8, ChromaBitDepth = 8, ChromaFormat = 5
Allocating new output: 2560x720 (x 9), ThumbnailMode = 0
TVMR: cbBeginSequence: 1166: BeginSequence  1280x720, bVPR = 0, fFrameRate = 0.000000
TVMR: LowCorner Frequency = 100000
TVMR: cbBeginSequence: 1545: DecodeBuffers = 17, pnvsi->eCodec = 4, codec = 0
TVMR: cbBeginSequence: 1606: Display Resolution : (1280x720)
TVMR: cbBeginSequence: 1607: Display Aspect Ratio : (1280x720)
TVMR: cbBeginSequence: 1649: ColorFormat : 5
TVMR: cbBeginSequence:1660 ColorSpace = NvColorSpace_YCbCr709
TVMR: cbBeginSequence: 1790: SurfaceLayout = 3
TVMR: cbBeginSequence: 1868: NumOfSurfaces = 21, InteraceStream = 0, InterlaceEnabled = 0, bSecure = 0, MVC = 0 Semiplanar = 1, bReinit = 1, BitDepthForSurface = 8 LumaBitDepth = 8, ChromaBitDepth = 8, ChromaFormat = 5
Allocating new output: 1280x720 (x 23), ThumbnailMode = 0

It gives two resolutions 2560x720 and 1280x720 in the mp4 so that decoder cannot handle it.

Hi DaneLLL,

Maybe I figure out the reason. I used fixed sps and pps as below, just copied from the other project but didn’t understand each parameter.

unsigned char spspps[22] = {0x00, 0x00, 0x00, 0x01,
        			0x67, 0x42, 0x40, 0x20,
        			0x95, 0xA0, 0x0A, 0x00,
        			0x5B, 0x90, 0x00, 0x00,
        			0x00, 0x01, 0x68, 0xCE,
        			0x3C, 0x80};

Do you know how to change resolution in that spspps?

Thanks
Vu Nguyen

Hi Vu,
You can get sps/pps from h264 stream.

There are some samples:
https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/Utils.cpp
http://iphome.hhi.de/suehring/tml/
https://www.ffmpeg.org/

Hi DaneLLL,

After reading sps/pps from h264 stream and put to muxer, I could playback all video files on TX2.

Thanks and Best Regards,
Vu Nguyen