static GF_Err gf_isom_dump_srt_track(GF_ISOFile *the_file, u32 track, FILE *dump)
{
	u32 i, j, k, count, di, len, ts, cur_frame;
	u64 start, end;
	GF_Tx3gSampleEntryBox *txtd;
	char szDur[100];
	Bool is_wvtt = GF_FALSE;
	GF_TrackBox *trak = gf_isom_get_track_from_file(the_file, track);
	u32 subtype = gf_isom_get_media_subtype(the_file, track, 1);
	if (!trak) return GF_BAD_PARAM;
	switch (trak->Media->handler->handlerType) {
	case GF_ISOM_MEDIA_TEXT:
	case GF_ISOM_MEDIA_SUBT:
		break;
	default:
		return GF_BAD_PARAM;
	}

	ts = trak->Media->mediaHeader->timeScale;
	cur_frame = 0;
	end = 0;

	switch (subtype) {
	case GF_ISOM_SUBTYPE_TX3G:
	case GF_ISOM_SUBTYPE_TEXT:
	case GF_ISOM_SUBTYPE_STXT:
		break;
	case GF_ISOM_SUBTYPE_WVTT:
		is_wvtt = GF_TRUE;
		break;
	default:
		return GF_NOT_SUPPORTED;
	}

	count = gf_isom_get_sample_count(the_file, track);
	for (i=0; i<count; i++) {
		GF_BitStream *bs;
		GF_TextSample *txt;
		GF_ISOSample *s = gf_isom_get_sample(the_file, track, i+1, &di);
		if (!s) continue;

		start = s->DTS;
		if (s->dataLength==2) {
			gf_isom_sample_del(&s);
			continue;
		}
		if (i+1<count) {
			GF_ISOSample *next = gf_isom_get_sample_info(the_file, track, i+2, NULL, NULL);
			if (next) {
				end = next->DTS;
				gf_isom_sample_del(&next);
			}
		} else {
			end = gf_isom_get_media_duration(the_file, track) ;
		}
		if (!is_wvtt) {
			cur_frame++;
			gf_fprintf(dump, "%d\n", cur_frame);
			tx3g_format_time(start, ts, szDur, GF_TRUE);
			gf_fprintf(dump, "%s --> ", szDur);
			tx3g_format_time(end, ts, szDur, GF_TRUE);
			gf_fprintf(dump, "%s\n", szDur);
		}


		if (is_wvtt) {
			u64 start_ts, end_ts;
			void webvtt_write_cue(GF_BitStream *bs, GF_WebVTTCue *cue, Bool write_srt);
			GF_List *cues;
			u32 nb_cues;
			u8 *data;
			u32 data_len;

			start_ts = s->DTS * 1000;
			start_ts /= trak->Media->mediaHeader->timeScale;
			end_ts = end * 1000;
			end_ts /= trak->Media->mediaHeader->timeScale;
			cues = gf_webvtt_parse_cues_from_data(s->data, s->dataLength, start_ts, end_ts);
			gf_isom_sample_del(&s);
			nb_cues = gf_list_count(cues);

			if (!nb_cues) {
				gf_list_del(cues);
				continue;
			}

			cur_frame++;
			gf_fprintf(dump, "%d\n", cur_frame);

			bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
			for (j = 0; j < gf_list_count(cues); j++) {
				GF_WebVTTCue *cue = (GF_WebVTTCue *)gf_list_get(cues, j);
				webvtt_write_cue(bs, cue, GF_TRUE);
				gf_webvtt_cue_del(cue);
			}
			gf_list_del(cues);
			gf_bs_write_u16(bs, 0);
			gf_bs_get_content(bs, &data, &data_len);
			gf_bs_del(bs);

			if (data) {
				gf_fprintf(dump, "%s\n", data);
				gf_free(data);
			} else {
				gf_fprintf(dump, "\n");
			}
			continue;
		} else if (subtype == GF_ISOM_SUBTYPE_STXT) {
			if (s->dataLength)
				gf_fprintf(dump, "%s\n", s->data);
			gf_isom_sample_del(&s);
			continue;
		}
		else if ((subtype!=GF_ISOM_SUBTYPE_TX3G) && (subtype!=GF_ISOM_SUBTYPE_TEXT)) {
			gf_fprintf(dump, "unknwon\n");
			gf_isom_sample_del(&s);
			continue;
		}
		bs = gf_bs_new(s->data, s->dataLength, GF_BITSTREAM_READ);
		txt = gf_isom_parse_text_sample(bs);
		gf_bs_del(bs);

		txtd = (GF_Tx3gSampleEntryBox *)gf_list_get(trak->Media->information->sampleTable->SampleDescription->child_boxes, di-1);

		if (!txt || !txt->len) {
			gf_fprintf(dump, "\n");
		} else {
			u32 styles, char_num, new_styles, color, new_color;
			u16 utf16Line[10000];

			/*UTF16*/
			if ((txt->len>2) && ((unsigned char) txt->text[0] == (unsigned char) 0xFE) && ((unsigned char) txt->text[1] == (unsigned char) 0xFF)) {
				memcpy(utf16Line, txt->text+2, sizeof(char)*txt->len);
				( ((char *)utf16Line)[txt->len] ) = 0;
				len = txt->len;
			} else {
				u8 *str = (u8 *) (txt->text);
				len = gf_utf8_mbstowcs(utf16Line, 10000, (const char **) &str);
				if (len == GF_UTF8_FAIL) return GF_NON_COMPLIANT_BITSTREAM;
				utf16Line[len] = 0;
			}
			char_num = 0;
			styles = 0;
			new_styles = txtd->default_style.style_flags;
			color = new_color = txtd->default_style.text_color;

			for (j=0; j<len; j++) {
				Bool is_new_line;

				if (txt->styles) {
					new_styles = txtd->default_style.style_flags;
					new_color = txtd->default_style.text_color;
					for (k=0; k<txt->styles->entry_count; k++) {
						if (txt->styles->styles[k].startCharOffset>char_num) continue;
						if (txt->styles->styles[k].endCharOffset<char_num+1) continue;

						if (txt->styles->styles[k].style_flags & (GF_TXT_STYLE_ITALIC | GF_TXT_STYLE_BOLD | GF_TXT_STYLE_UNDERLINED | GF_TXT_STYLE_STRIKETHROUGH)) {
							new_styles = txt->styles->styles[k].style_flags;
							new_color = txt->styles->styles[k].text_color;
							break;
						}
					}
				}
				if (new_styles != styles) {
					if ((new_styles & GF_TXT_STYLE_BOLD) && !(styles & GF_TXT_STYLE_BOLD)) gf_fprintf(dump, "<b>");
					if ((new_styles & GF_TXT_STYLE_ITALIC) && !(styles & GF_TXT_STYLE_ITALIC)) gf_fprintf(dump, "<i>");
					if ((new_styles & GF_TXT_STYLE_UNDERLINED) && !(styles & GF_TXT_STYLE_UNDERLINED)) gf_fprintf(dump, "<u>");
					if ((new_styles & GF_TXT_STYLE_STRIKETHROUGH) && !(styles & GF_TXT_STYLE_STRIKETHROUGH)) gf_fprintf(dump, "<strike>");

					if ((styles & GF_TXT_STYLE_STRIKETHROUGH) && !(new_styles & GF_TXT_STYLE_STRIKETHROUGH)) gf_fprintf(dump, "</strike>");
					if ((styles & GF_TXT_STYLE_UNDERLINED) && !(new_styles & GF_TXT_STYLE_UNDERLINED)) gf_fprintf(dump, "</u>");
					if ((styles & GF_TXT_STYLE_ITALIC) && !(new_styles & GF_TXT_STYLE_ITALIC)) gf_fprintf(dump, "</i>");
					if ((styles & GF_TXT_STYLE_BOLD) && !(new_styles & GF_TXT_STYLE_BOLD)) gf_fprintf(dump, "</b>");

					styles = new_styles;
				}
				if (new_color != color) {
					if (new_color ==txtd->default_style.text_color) {
						gf_fprintf(dump, "</font>");
					} else {
						gf_fprintf(dump, "<font color=\"%s\">", gf_color_get_name(new_color) );
					}
					color = new_color;
				}

				/*not sure if styles must be reseted at line breaks in srt...*/
				is_new_line = GF_FALSE;
				if ((utf16Line[j]=='\n') || (utf16Line[j]=='\r') ) {
					if ((utf16Line[j]=='\r') && (utf16Line[j+1]=='\n')) j++;
					gf_fprintf(dump, "\n");
					is_new_line = GF_TRUE;
				}

				if (!is_new_line) {
					u32 sl;
					char szChar[30];
					s16 swT[2], *swz;
					swT[0] = utf16Line[j];
					swT[1] = 0;
					swz= (s16 *)swT;
					sl = gf_utf8_wcstombs(szChar, 30, (const unsigned short **) &swz);
					if (sl == GF_UTF8_FAIL) sl=0;
					szChar[sl]=0;
					gf_fprintf(dump, "%s", szChar);
				}
				char_num++;
			}
			new_styles = 0;
			if (new_styles != styles) {
				if (styles & GF_TXT_STYLE_STRIKETHROUGH) gf_fprintf(dump, "</strike>");
				if (styles & GF_TXT_STYLE_UNDERLINED) gf_fprintf(dump, "</u>");
				if (styles & GF_TXT_STYLE_ITALIC) gf_fprintf(dump, "</i>");
				if (styles & GF_TXT_STYLE_BOLD) gf_fprintf(dump, "</b>");

//				styles = 0;
			}

			if (color != txtd->default_style.text_color) {
				gf_fprintf(dump, "</font>");
//				color = txtd->default_style.text_color;
			}
			gf_fprintf(dump, "\n");
		}
		gf_isom_sample_del(&s);
		gf_isom_delete_text_sample(txt);
		gf_fprintf(dump, "\n");
		gf_set_progress("SRT Extract", i, count);
	}
	if (count) gf_set_progress("SRT Extract", i, count);
	return GF_OK;
}