Hi ,
 I have the following question :

We currently use the live555 code to run a RTSP server source from a
camera. The camera generates H264 content as two streams (with different
resolutions high-res & low-res). There is no audio. We stream the low-res
on RTP, and optionally store the high-res to file. We would like to use
the live555 to store the high-res content locally as mp4 container file.
This is on a linux system.

Although we were partially successful with QuickTimeFileSink, the approach
is not clean. We don’t have a complete rtpSource built for the high-res
stream. Hence we had to skip the dereference to that object for RTPSeqNum
as below. Attached was my example code to generate the mp4 file.



void SubsessionIOState::afterGettingFrame(unsigned packetDataSize,

                                    struct timeval presentationTime) {

  // Begin by checking whether there was a gap in the RTP stream.

  // If so, try to compensate for this (if desired):

  unsigned short rtpSeqNum = 0;



  if (fOurSubsession.rtpSource()) {

    rtpSeqNum = fOurSubsession.rtpSource()->curPacketRTPSeqNum();

  }

  if (fOurSink.fPacketLossCompensate && fPrevBuffer->bytesInUse() > 0) {

    short seqNumGap = rtpSeqNum - fLastPacketRTPSeqNum;

    for (short i = 1; i < seqNumGap; ++i) {

      // Insert a copy of the previous frame, to compensate for the loss:

      useFrame(*fPrevBuffer);

    }

  }

  fLastPacketRTPSeqNum = rtpSeqNum;

….



Please let us know whether you will be able to support a mp4 container
file generation from this library. Whether the change we made above is
acceptable for the time being? If you do not plan to support this, but
have different suggestions about the approach or another alternate
library, we would really appreciate your feedback.
/* a derived MediaSubsession used to source from a local stream */
class H264VideoSubsession : public MediaSubsession {
    CSession* video_ = NULL;
    std::shared_ptr<FramedSource> src_;

public:
    H264VideoSubsession(MediaSession& parent) : MediaSubsession(parent) {
        video_ = new CSession;
        video_->start();
        video_->openFramedSource(fParent.envir(), src_);
        fCodecName = "H264";
        fReadSource = src_.get();
        fVideoWidth = 2560;
        fVideoHeight = 1440;
        fVideoFPS = 30;
    }
    virtual Boolean createSourceObjects(int useSpecialRTPoffset) {
        return true;
    }
};

/* a derived MediaSession to fake a SDP from RTPSource */
class H264MediaSession : public MediaSession {
public:
    H264MediaSession(UsageEnvironment& env) : MediaSession(env) {}

    virtual MediaSubsession* createNewMediaSubsession() {
        return new H264VideoSubsession(*this);
    }

    static H264MediaSession* create(UsageEnvironment& env) {
        H264MediaSession* p;

        p = new H264MediaSession(env);
        if (NULL != p) {
            p->initializeWithSDP(
                // sdp description
                "v=0\r\n"
                "m=video 0 RTP/AVP 96\r\n");
        }

        return p;
    }
};

static void sessionAfterPlaying(void* /*clientData*/) {}

int main(int argc, char** argv)
{
    std::string name;

    TaskScheduler* sched = BasicTaskScheduler::createNew();
    UsageEnvironment* env = BasicUsageEnvironment::createNew(*sched);

    MediaSession* session = H264MediaSession::create(*env);

    QuickTimeFileSink* qtOut = QuickTimeFileSink::createNew(*env,
        *session, "video_T.mp4",
        100000, /// fileSinkBufferSize,
        2560, 1440, 30,
        false, /// no packetLossCompensate,
        false, /// no syncStreams,
        false, /// no generateHintTracks,
        true); /// yes generateMP4Format

    qtOut->startPlaying(sessionAfterPlaying, NULL);

    std::cout << "Press Enter Key to quit.";
    std::getline(std::cin, name);

    Medium::close(qtOut); qtOut = NULL;
    MediaSubsessionIterator iter(*session);
    MediaSubsession* subsession;
    while ((subsession = iter.next()) != NULL) {
        Medium::close(subsession->sink);
        subsession->sink = NULL;
    }

    return 0;
}
_______________________________________________
live-devel mailing list
live-devel@lists.live555.com
http://lists.live555.com/mailman/listinfo/live-devel

Reply via email to