[Live-devel] Am I doing this right?

Ben Rush ben at ben-rush.net
Thu Apr 6 07:48:24 PDT 2017


We're using Live555 for live RTSP video streaming and it's been working
flawlessly for us. The video we stream we also save to disk using some
other mechanism. We are now in a situation where our clients would like to
play back the recorded files on demand, and so we're looking to extend our
RTSP server with static file playback.

It's a long story, but we have a proprietary file format for saving our
video files, and so we need to do transcoding on the fly of these files to
H264 before streaming them out of Live555. The way I *think* I should do
this is as follows (Note, our files on disk are called "OCV" files, in the
event I refer to them as such at some point).

I've implemented a "OCVFileServerMediaSubsession" which inherits from
"FileServerMediaSubsession". I've also implemented an OCVFileSource which
inherits from FramedFileSource.

I've then implemented the required "createNewStreamSource" method as such:

FramedSource* OCVFileServerMediaSubsession::createNewStreamSource(unsigned
/*clientSessionId*/, unsigned& estBitrate) {
    estBitrate = 90000; // kbps, estimate

    // Create the video source:
    {
        std::ifstream in(fFileName, std::ifstream::ate |
std::ifstream::binary);
        fFileSize = in.tellg();
    }

    OCVFileSource* fileSource = OCVFileSource::createNew(envir(),
fFileName);
    if (fileSource == NULL) return NULL;

    // Create a framer for the Video Elementary Stream:
    return H264VideoStreamFramer::createNew(envir(), fileSource);
}

Then within OCVFileSource::doGetNextFrame() I use our own special file
reader to get a frame from the OCV file and I use lib x264 to encode it
into a group of NAL units (much like I do with our live camera solution). I
then set "fTo" with the encoded data, again, like our live solution, and
call

 nextTask() = envir().taskScheduler().scheduleDelayedTask(0,
        (TaskFunc*)FramedSource::afterGetting, this);

to reschedule another call to doGetNextFrame().

Is this the right way of reading a file from disk, encoding on the fly, and
passing it to Live555 as a file media server? I'm running into some crashes
which might very well be just something dumb I'm doing elsewhere, but might
also be because I'm just not properly setting things up/doing things the
"Live555 way" properly. I am basing everything on the
testOnDemandRTSPServer.cpp sample. The only difference is that I have to
transcode to H264 instead of reading a .264 file from disk.

...I wanted to confirm I had the general concept down right before digging
deeper into the nature of these crashes (which I'm purposefully leaving out
of this email so as to not confuse the point of the email which is just
confirming I have my head on straight).

Thanks for your time,
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20170406/b4a81ecd/attachment.html>


More information about the live-devel mailing list