Facility Control

 View Only
  • 1.  Thumbnail bytes data

    Posted 05-26-2019 10:33

    Hello

    I want to represent clip thumbnail from my video server in DB. So, the server return me very long response with thumbnail data, that starts with ffd8 and ends with ffd9 headers. Its jpeg headers.

    Is DB have any tools to encode such a data to file?  

    Thank you,

    Alex.



  • 2.  RE: Thumbnail bytes data

    Posted 05-28-2019 22:33

    Hi Alex.

    What is your transport protocol? It is certainly possible to detect the start/end words and write the bytes to a file which can then be loaded to view.  

    If it is a steady stream of them, I would use a <listener/> tag and set 0xFFD8 as the "sync word" and 0xFFD9 as the delimeter - you'll get task triggered each time 0xFFD9 is received containing the bytes you're after. 

    James


    #DashBoard


  • 3.  RE: Thumbnail bytes data

    Posted 05-29-2019 10:56

    Hello James, 

    This is AMP protocol, and thumbnail data is a part of AMP message.

    I believe i can setup special listener that listens to same location and port, with 0xFFD8 as the "sync word" and 0xFFD9 as the delimeter. 

    1. In "sync word" i should write "0xFFD8" or "FFD8" ?

    2. Ok, i got the thumbnail data, how i write it to file? Something like this i guess?

    Thank you!

    var output = null;
    var dst = *dest file path.jpg*
    var bytes = x //thumbnail data from listener
    output = ogscript.createFileOutput(dst, false); //Create the file writer
    output.writeByteArray(bytes); //Write the file

    #DashBoard


  • 4.  RE: Thumbnail bytes data

    Posted 05-29-2019 13:42

    Hi Alex.

    You do not need the "0x" prefix for the sync word - it is already assumed that you will be hex-encoding it.

    Your listener code will look something like:

    if (event.isMessageEvent())
    {
    var bytes = event.getBytes();
    var output = null;
    try
    {
    output = ogscript.createFileOutput(dst, false);
    //If you need the sync word, write it here with ogscript.writeShort(0xFFD8);
    output.writeByteArray(bytes);
    //If you need the sync word, write it here with ogscript.writeShort(0xFFD9);
    output.close();
    }
    catch (e)
    {
    ogscript.debug(e);
    }

    if (output != null)
    {
    output.close();
    }
    }

    #DashBoard


  • 5.  RE: Thumbnail bytes data

    Posted 06-01-2019 17:13

    Hello James

    Thanks you for your help.

    Unfortunately, for some reason my listener doesn't catch any bytes.. here is the code:

    <listener autostart="false" connecthost="10.168.1.89" connectport="3811" delimiter="FFD9" delimitertype="bytes" id="thumbnail" name="thumbnail" syncword="FFD8">
    <task tasktype="ogscript">if (event.isConnectEvent())
    {
    ogscript.debug('connected')
    ogscript.putObject('thumbnail', this);
    this.writeString('CRAT0007204vtr2\n', false); // connect command to server - in this case i connect to VTR2

    }

    if (event.isMessageEvent())
    {
    ogscript.debug('message')
    var bytes = event.getBytes();
    var output = null;
    var dst = params.getValue('filePath', 0);

    try
    {
    output = ogscript.createFileOutput(dst, false);
    //If you need the sync word, write it here with ogscript.writeShort(0xFFD8);
    output.writeByteArray(bytes);
    //If you need the sync word, write it here with ogscript.writeShort(0xFFD9);
    output.close();
    }
    catch (e)
    {
    ogscript.debug(e);
    }

    if (output != null)
    {
    output.close();
    }
    }</task>
    </listener>

    Thank you!

     


    #DashBoard


  • 6.  RE: Thumbnail bytes data

    Posted 06-03-2019 20:24

    I do notice that you're missing semicolons after your ogscript.debug statements.

    Is your connect event ever getting called? Is there a command you need to send to the server to ask it to give you a thumbnail?


    #DashBoard


  • 7.  RE: Thumbnail bytes data

    Posted 06-03-2019 20:44

    Hi James, 

    Yes, ok, added semicolons, thanks. 

    Listener is triggered via listener.start button. Yes its starts and i got bytes back from server while using fixed length (1) delimiter - actually, i just collect it byte by byte and write to parameter:

    if (event.isMessageEvent())
    {
    var str = event.getBytesAsString() + "";
    params.setValue('sum', 0, params.getValue('sum', 0) + str);


    }

     

    To get thumbnail, i send an command to the server, yes. 


    #DashBoard


  • 8.  RE: Thumbnail bytes data

    Posted 06-19-2019 21:25

    Once you get the first byte of your message, you can continue reading from the listener's input stream if you pass "this.getInputStream()" into ogscript.createMessageParser:

     

    if (event.isMessageEvent())
    {
    var cmdTypeBytes = event.getBytes();
    var commandType = cmdTypeBytes[0] << 8 | cmdTypeBytes[1];
    var messageParser = ogscript.createMessageParser(this.getInputStream());
    var length = messageParser.readShort();
    var string = messageParser.readString(length);

    ogscript.rename('output', 'TYPE: ' + commandType + ' MESSAGE: ' + string);
    }

     

    If you do this, just make sure you check the "Stop all receive/task execution on pause" checkbox to keep more tasks from getting queued/called with information from inside of your listener's connection.


    #DashBoard