Skip to content

ViacomInc/HLS-CC-Decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HLS-CC-Decoder

CCDecoder was built to decode 608 captions payloads from flashls (flashls.org / https://github.com/mangui/flashls)

You must use flashls v0.4.4.20 or higher.

Development

We welcome contributions to this project, to help us out please:

  • Fork this project
  • Make your changes
  • Send a Pull Request

We will do our very best to address any pull requests as quickly as possible.

Build the project

Clone the project from this repo

This project can be built via ide (flashbuilder/intellij) or by commandline. There are no external libraries.

If you need to build flashls:

Clone the project from the repo: https://github.com/mangui/flashls

Navigate to build/ folder. Build command: FLEXPATH=/path/to/flex/sdk sh ./build.sh where FLEXPATH is the path to your flex/air sdk location.

NOTE: lib folder must contain blooddy_crypto.swc (https://github.com/blooddy/blooddy_crypto)

Using the Decoder

First import the Decoder into your player project

import com.viacom.brbpl.decoder.Decoder608;

Create an instance of the decoder and attach listeners for the command and caption data events:

_ccDecoder  = new Decoder608();
_ccDecoder.addEventListener(CCDataEvent.CC_DATA, onCaptionDataDecode, false, 0, true);
_ccDecoder.addEventListener(CCDataEvent.CC_COMMAND, onCaptionCommandDecode, false, 0, true);

Attach a client to flashls netstream to get the caption info event:

var netstreamClient:Object = new Object();  
_hls.stream.client = netstreamClient;  
netstreamClient.onCaptionInfo = this.onCaptionInfo;  

In your player be sure to import a Base64 decoder. In this case we will use the same decoder that flashls uses for encoding. flashls uses blooddy_crypto.swc (http://www.blooddy.by/en/crypto/) for base 64 encoding.

import by.blooddy.crypto.Base64;

In the captionInfo event Base64 decode the .data which contains the closed caption data packet. There exists some leading 0's from the base64 encoding and size and em data that is not currently used. We will start the cc decode at position 6:

    public function onCaptionInfo(info:Object):void
	{			
	    var captionBytes =	Base64.decode(info.data);
		//3 leading 0 bytes from the base64encoding -then size and em data can be ignored
		//start decode at position 6
		captionBytes.position = 6;
		_ccDecoder.processCCData(captionBytes);		
	}

Events

Once processCCData is called the decoder will fire CCDataEvents.

CCDataEvent.CC_DATA:

A CC_DATA event will be fired from the decoder when a CC data packet contains closed caption data to be displayed. The .data property of the event contains a JSON object that has the information for that packet, including style and position information. Here is what data for CC_DATA event looks like:

{
    "italic":false,
    "underline":false,
    "captionText":"AT",
    "isCommand":false,
    "textColor":"white",
    "backgroundColor":"black",
    "transparent":false,
    "column":16,
    "row":14
}
CCDataEvent.CC_COMMAND:

A CC_COMMAND event will be fired when a CC data packet contains a 608 command. (https://en.wikipedia.org/wiki/EIA-608#Control_commands) The .data property of the event contains the same JSON layout as the CC_DATA event, however isCommand will be true and the captionText will contain the command to be executed.

{
    "captionText":"erase displayed memory",
    "isCommand":true,
    "italic":false,
    "underline":false,
    "textColor":"white",
    "backgroundColor":"black",
    "transparent":false,
    "column":0,
    "row":15
}

JS Rendering

When sending ccdata to JS for rendering be sure to use flash's built in encodeURIComponent() function, and JS built in decodeURIComponent().

private function onCaptionDataDecode(event:CCDataEvent):void
{	
	ExternalInterface.call("onCCData", encodeURIComponent(event.data));
}
private function onCaptionCommandDecode(event:CCDataEvent):void
{			
    ExternalInterface.call("onCaptionCommand",encodeURIComponent(event.data));
}

Demo

There is a demo available here: demo-coming-soon

The source for this demo player, as well as the javascript used to render the captions and the demo page itself is available in the demo folder in this repository.

Authors/Contributors