+struct hb_text_sample_s
+{
+ uint8_t sample[1280];
+ uint32_t length;
+ MP4Duration duration;
+};
+
+/**********************************************************************
+ * MP4CreateTextSample
+ **********************************************************************
+ * Creates a buffer for a text track sample
+ *********************************************************************/
+static struct hb_text_sample_s *MP4CreateTextSample( char *textString, uint64_t duration )
+{
+ struct hb_text_sample_s *sample = NULL;
+ int stringLength = strlen(textString);
+ int x;
+
+ if( stringLength < 1024 )
+ {
+ sample = malloc( sizeof( struct hb_text_sample_s ) );
+
+ //textLength = (stringLength; // Account for BOM
+ sample->length = stringLength + 2 + 12; // Account for text length code and other marker
+ sample->duration = (MP4Duration)duration;
+
+ // 2-byte length marker
+ sample->sample[0] = (stringLength >> 8) & 0xff;
+ sample->sample[1] = stringLength & 0xff;
+
+ strncpy( (char *)&(sample->sample[2]), textString, stringLength );
+
+ x = 2 + stringLength;
+
+ // Modifier Length Marker
+ sample->sample[x] = 0x00;
+ sample->sample[x+1] = 0x00;
+ sample->sample[x+2] = 0x00;
+ sample->sample[x+3] = 0x0C;
+
+ // Modifier Type Code
+ sample->sample[x+4] = 'e';
+ sample->sample[x+5] = 'n';
+ sample->sample[x+6] = 'c';
+ sample->sample[x+7] = 'd';
+
+ // Modifier Value
+ sample->sample[x+8] = 0x00;
+ sample->sample[x+9] = 0x00;
+ sample->sample[x+10] = (256 >> 8) & 0xff;
+ sample->sample[x+11] = 256 & 0xff;
+ }
+
+ return sample;
+}
+
+/**********************************************************************
+ * MP4GenerateChapterSample
+ **********************************************************************
+ * Creates a buffer for a text track sample
+ *********************************************************************/
+static struct hb_text_sample_s *MP4GenerateChapterSample( hb_mux_object_t * m, uint64_t duration )
+{
+ int chapter = m->current_chapter;
+ hb_chapter_t *chapter_data = hb_list_item( m->job->title->list_chapter, chapter - 1 );
+ char tmp_buffer[1024];
+ char *string = tmp_buffer;
+
+ tmp_buffer[0] = '\0';
+
+ if( chapter_data != NULL )
+ {
+ string = chapter_data->title;
+ }
+
+ if( strlen(string) == 0 || strlen(string) >= 1024 )
+ {
+ snprintf( tmp_buffer, 1023, "Chapter %03i", chapter );
+ string = tmp_buffer;
+ }
+
+ return MP4CreateTextSample( string, duration );
+}
+
+