본문 바로가기
놀기/잡스러운 것

[NVR 만들기] H.265 지원

by Hi~ 2023. 9. 2.

H.264를 기본으로 보통 사용하지만 압축효율이 좋은 H.265도 많이 쓴다. 한정된 저장 공간 안에 많은 일 수의 영상을 저장하기 위해서는 당연히 압축 효율이 좋은 것이 최고다. LIVE555에서도 H.265 Transport Stream을 지원한다.

 

bmNVR을 하면서 사용했던 testH264VideoToTransportStream와 동일한 형태의 testH265VideoToTransportStream가 sample program으로 포함되어 있다. 파일을 열어보면 라인 수도 동일하다.

 

 

차이점은 H264VideoStreamFramer를 쓰느냐 H265VideoStreamFramer를 쓰느냐의 차이다. H.264와 H.265는 NAL Type에서 달라 구분이 쉽다. 이 정보를 기반으로 어떤 Framer를 쓸지 정해서 호출하면 간단하게 두 코덱을 모두 지원할 수 있다.

 

  // Create a 'framer' filter for this file source, to generate presentation times for each NAL unit:
  H264VideoStreamFramer* framer = H264VideoStreamFramer::createNew(*env, inputSource, True/*includeStartCodeInOutput*/);

  // Then create a filter that packs the H.264 video data into a Transport Stream:
  MPEG2TransportStreamFromESSource* tsFrames = MPEG2TransportStreamFromESSource::createNew(*env);
  tsFrames->addNewVideoSource(framer, 5/*mpegVersion: H.264*/);

 

NAL 정보를 직접 보지않고 bmNVR의 continueAfterSETUP() 내에서 아래와 같이 video 정보를 그냥 봐도 된다. 비디오가 여러 채널이 들어 오면 좀 난감하겠지만, 임의의 RTSP 스트림을 모두 처리하고자하는 것이 목적이 아니므로 그냥 넘어가자.

void continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultString) {

	// 중략

    if (QString(scs.subsession->mediumName()).compare("video", Qt::CaseInsensitive) == 0)
    {

        if (QString(scs.subsession->codecName()).compare("H264", Qt::CaseInsensitive) == 0)
        {
            ((bmNVRRTSPClient *) rtspClient)->setVideoCodec(0);
            env << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. H264\n";
        }
        else if (QString(scs.subsession->codecName()).compare("H265", Qt::CaseInsensitive) == 0)
        {
            ((bmNVRRTSPClient *) rtspClient)->setVideoCodec(1);
            env << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. H265\n";
        }
        else {
            ((bmNVRRTSPClient *) rtspClient)->setVideoCodec(-1);
            break;
        }

 

댓글