MonaSolutions / MonaServer2

Temporary project planned to replace MonaServer
GNU General Public License v3.0
270 stars 36 forks source link

Feature request: Possibility to record small clips of x amount of seconds of a complete camera session #33

Open al-sabr opened 4 years ago

al-sabr commented 4 years ago

Greetings!

I would like to know how complicated is it to implement a feature that specify Mona that I want to record my Webcam and that I want that the recording being persisted like session1_00.flv, session1_01.flv, session1_02.flv, etc .... session1_x.flv inside of folder session1 which is the stream name.

I am using Adobe AIR with RTMP.

Thank you.

al-sabr commented 4 years ago

Mathieu, Thomas any tip about where to work for this?

thomasjammet commented 4 years ago

LUA implementation is a bit instable for now but you can try with the following script. Just create the file main.lua in MonaServer www/ directory and copy the following lines :

function onConnection(client)

    function client:onRecordMedia(packet)
        client.file:write(tostring(packet))
    end

    function client:onAudio(track, tag, packet, reliable)
        client.recorder:writeAudio(tag, packet)
    end

    function client:onVideo(track, tag, packet, reliable)
        client.recorder:writeVideo(tag, packet)
    end

    function client:onPublish(publication)
        client.fileName = "dump_" .. publication.name .. "_" .. mona:time() .. ".flv"
        NOTE("Begin dumping file '", client.fileName ,"'")
        client.file = io.open(client.fileName, "wb")

        -- Create the FLV Media writer and start it
        client.recorder = mona:newMediaWriter("flv")
        client.recorder.onWrite = client.onRecordMedia
        client.recorder:beginMedia()

        -- Subscribe to the new publication
        client.subscription = mona:newSubscription(publication.name)
        client.subscription.onAudio = client.onAudio
        client.subscription.onVideo = client.onVideo
    end

    function client:onUnpublish(publication)
        if client.file then
            NOTE("End dumping file '" , client.fileName, "'")
            client.recorder:endMedia()
            client.file:close()
        end
    end
end

Sadly this is just a POC for now, we don't have time to make LUA stable for now, but at least you can try and see how it will work.

al-sabr commented 4 years ago

OK you thought I was talking about Lua. I was more asking C++ side so that such small features I could add with your guidance.

thomasjammet commented 4 years ago

The lua script are here to make it easier for users to implement a custom behavior. If you need a C++ implementation this will cost more time to explain and we are too busy for this, I hope you understand. Now if you want to start from your own you can try to implement your custom code here in onPublish function : https://github.com/MonaSolutions/MonaServer2/blob/master/MonaTiny/sources/MonaTiny.cpp#L154

al-sabr commented 4 years ago

I really don't understand why extending Mona has to be dependant on Lua when you can create dynamic extension for any C++ code via the CppMicroservices framework which is perfectly suitable for that purpose.

Creating a bundle delivered as a DLL/SO file and handle during runtime via CppMicroservices is so much easier than having to rely on Lua.

As I mentioned earlier why not make Mona a dynamic server where we can add and remove new functionalities on the fly without getting out of C++?

Why no one gets the fact that compiled static code can also be hooked into a running application an make that code become dynamic?

al-sabr commented 4 years ago

Thanx for the answer I really appreciate the guidance.