protected function formatCaption($captionLines, $format=null)
	{
		$result = array();
		$result['caption'] = '';
		$result['extension'] = 'txt';

		if ($format === null) $format = $this->captionFormat;

		if ($format == 'srt') {
			$result['extension'] = 'srt';

			$sequence = 1;
			foreach ($captionLines as $captionLine) {
				$start = $this->parseFloatTime($captionLine['start']);
				$end = $this->parseFloatTime($captionLine['end']);

				$result['caption'] .= ($sequence++) . "\n";
				$result['caption'] .= str_replace('.', ',', vsprintf('%02d:%02d:%02.3f', $start)) . ' --> ';
				$result['caption'] .= str_replace('.', ',', vsprintf('%02d:%02d:%02.3f', $end)) . "\n";
				$result['caption'] .= $captionLine['text'] . "\n\n";
			}
			$result['caption'] = trim($result['caption']);
		} elseif ($format == 'sub') {
			$result['extension'] = 'sub';

			foreach ($captionLines as $captionLine) {
				$result['caption'] .= '{' . intval($captionLine['start'] * $this->defaultFPS) . '}';
				$result['caption'] .= '{' . intval($captionLine['end'] * $this->defaultFPS) . '}';
				$result['caption'] .= $captionLine['text'] . "\n";
			}
			$result['caption'] = trim($result['caption']);
		} elseif ($format == 'ass') {
			$result['extension'] = 'ass';
			$result['caption'] = <<<EOF
[Script Info]
ScriptType: v4.00+
Collisions: Normal
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
WrapStyle: 0
ScaledBorderAndShadow: no

[V4+ Styles]
Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
Style: Default,Arial,16,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0
Style: Top,Arial,16,&H00F9FFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,8,10,10,10,0
Style: Mid,Arial,16,&H0000FFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,5,10,10,10,0
Style: Bot,Arial,16,&H00F9FFF9,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text

EOF;
			foreach ($captionLines as $captionLine) {
				$start = $this->parseFloatTime($captionLine['start']);
				$end = $this->parseFloatTime($captionLine['end']);

				$result['caption'] .= 'Dialogue: 0,';
				$result['caption'] .= vsprintf('%d:%02d:%02.2f', $start) . ',';
				$result['caption'] .= vsprintf('%d:%02d:%02.2f', $end) . ',Bot,,0000,0000,0000,,';
				$result['caption'] .= $captionLine['text'] . "\n";
			}
		}

		return ((object) $result);
	}
protected function formatCaption($captionLines, $format=null)
	{
		$result = array();
		$result['caption'] = '';
		$result['extension'] = 'txt';

		if ($format === null) $format = $this->captionFormat;

		if ($format == 'srt') {
			$result['extension'] = 'srt';

			$sequence = 1;
			foreach ($captionLines as $captionLine) {
				$start = $this->parseFloatTime($captionLine['start']);
				$end = $this->parseFloatTime($captionLine['end']);

				$result['caption'] .= ($sequence++) . "\n";
				$result['caption'] .= str_replace('.', ',', vsprintf('%02d:%02d:%02.3f', $start)) . ' --> ';
				$result['caption'] .= str_replace('.', ',', vsprintf('%02d:%02d:%02.3f', $end)) . "\n";
				$result['caption'] .= $captionLine['text'] . "\n\n";
			}
			$result['caption'] = trim($result['caption']);
		} elseif ($format == 'sub') {
			$result['extension'] = 'sub';

			foreach ($captionLines as $captionLine) {
				$result['caption'] .= '{' . intval($captionLine['start'] * $this->defaultFPS) . '}';
				$result['caption'] .= '{' . intval($captionLine['end'] * $this->defaultFPS) . '}';
				$result['caption'] .= $captionLine['text'] . "\n";
			}
			$result['caption'] = trim($result['caption']);
		} elseif ($format == 'ass') {
			$result['extension'] = 'ass';
			$result['caption'] = <<<EOF
[Script Info]
ScriptType: v4.00+
Collisions: Normal
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
WrapStyle: 0
ScaledBorderAndShadow: no

[V4+ Styles]
Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
Style: Default,Arial,16,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0
Style: Top,Arial,16,&H00F9FFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,8,10,10,10,0
Style: Mid,Arial,16,&H0000FFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,5,10,10,10,0
Style: Bot,Arial,16,&H00F9FFF9,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text

EOF;
			foreach ($captionLines as $captionLine) {
				$start = $this->parseFloatTime($captionLine['start']);
				$end = $this->parseFloatTime($captionLine['end']);

				$result['caption'] .= 'Dialogue: 0,';
				$result['caption'] .= vsprintf('%d:%02d:%02.2f', $start) . ',';
				$result['caption'] .= vsprintf('%d:%02d:%02.2f', $end) . ',Bot,,0000,0000,0000,,';
				$result['caption'] .= $captionLine['text'] . "\n";
			}
		}

		return ((object) $result);
	}
protected function formatCaption ( $ captionLines , $ format = null ) { $ result = array ( ) ; $ result [ 'caption' ] = '' ; $ result [ 'extension' ] = 'txt' ; if ( $ format === null ) $ format = $ this -> captionFormat ; if ( $ format == 'srt' ) { $ result [ 'extension' ] = 'srt' ; $ sequence = 1 ; foreach ( $ captionLines as $ captionLine ) { $ start = $ this -> parseFloatTime ( $ captionLine [ 'start' ] ) ; $ end = $ this -> parseFloatTime ( $ captionLine [ 'end' ] ) ; $ result [ 'caption' ] .= ( $ sequence ++ ) . "\n" ; $ result [ 'caption' ] .= str_replace ( '.' , ',' , vsprintf ( '%02d:%02d:%02.3f' , $ start ) ) . ' --> ' ; $ result [ 'caption' ] .= str_replace ( '.' , ',' , vsprintf ( '%02d:%02d:%02.3f' , $ end ) ) . "\n" ; $ result [ 'caption' ] .= $ captionLine [ 'text' ] . "\n\n" ; } $ result [ 'caption' ] = trim ( $ result [ 'caption' ] ) ; } elseif ( $ format == 'sub' ) { $ result [ 'extension' ] = 'sub' ; foreach ( $ captionLines as $ captionLine ) { $ result [ 'caption' ] .= '{' . intval ( $ captionLine [ 'start' ] * $ this -> defaultFPS ) . '}' ; $ result [ 'caption' ] .= '{' . intval ( $ captionLine [ 'end' ] * $ this -> defaultFPS ) . '}' ; $ result [ 'caption' ] .= $ captionLine [ 'text' ] . "\n" ; } $ result [ 'caption' ] = trim ( $ result [ 'caption' ] ) ; } elseif ( $ format == 'ass' ) { $ result [ 'extension' ] = 'ass' ; $ result [ 'caption' ] =  <<<EOF
[Script Info]
ScriptType: v4.00+
Collisions: Normal
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
WrapStyle: 0
ScaledBorderAndShadow: no

[V4+ Styles]
Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
Style: Default,Arial,16,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0
Style: Top,Arial,16,&H00F9FFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,8,10,10,10,0
Style: Mid,Arial,16,&H0000FFFF,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,5,10,10,10,0
Style: Bot,Arial,16,&H00F9FFF9,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text

EOF ; foreach ( $ captionLines as $ captionLine ) { $ start = $ this -> parseFloatTime ( $ captionLine [ 'start' ] ) ; $ end = $ this -> parseFloatTime ( $ captionLine [ 'end' ] ) ; $ result [ 'caption' ] .= 'Dialogue: 0,' ; $ result [ 'caption' ] .= vsprintf ( '%d:%02d:%02.2f' , $ start ) . ',' ; $ result [ 'caption' ] .= vsprintf ( '%d:%02d:%02.2f' , $ end ) . ',Bot,,0000,0000,0000,,' ; $ result [ 'caption' ] .= $ captionLine [ 'text' ] . "\n" ; } } return ( ( object ) $ result ) ; }
Converts parsed caption track to desired caption format

@param  array $captionLines Parsed caption
@param  string $format Caption format, including "srt" (default), "sub", "ass"
@return object           Converted caption and it's file extension
Converts parsed caption track to desired caption format