Index: applications/mp4box/filedump.c
===================================================================
RCS file: /cvsroot/gpac/gpac/applications/mp4box/filedump.c,v
retrieving revision 1.84
diff -u -r1.84 filedump.c
--- applications/mp4box/filedump.c	9 Apr 2010 15:36:43 -0000	1.84
+++ applications/mp4box/filedump.c	10 Apr 2010 14:29:38 -0000
@@ -806,36 +806,46 @@
 	has_error = 0;
 	for (i=0; i<gf_isom_get_track_count(file); i++) {	
 		Bool has_cts_offset = gf_isom_has_time_offset(file, i+1);
+		u64 *dts = NULL;
+		u64 *cts = NULL;
 
 		fprintf(dump, "#dumping track ID %d timing\n", gf_isom_get_track_id(file, i+1));
 		count = gf_isom_get_sample_count(file, i+1);
+
+		if( (dts = gf_malloc(sizeof(u64) * count)) == NULL ) {
+			fprintf(stdout, "\tMemory allocation for STTS table fails\n");
+			return ;
+		}
+		if( (cts = gf_malloc(sizeof(u64) * count)) == NULL ) {
+			fprintf(stdout, "\tMemory allocation for CTTS table fails\n");
+			return ;
+		}
+
 		for (j=0; j<count; j++) {
-			u64 dts, cts;
 			GF_ISOSample *samp = gf_isom_get_sample_info(file, i+1, j+1, NULL, NULL);
-			dts = samp->DTS;
-			cts = dts + (s32) samp->CTS_Offset;
+			dts[j] = samp->DTS;
+			cts[j] = dts[j] + (s32) samp->CTS_Offset;
 			gf_isom_sample_del(&samp);
-
-			fprintf(dump, "Sample %d - DTS "LLD" - CTS "LLD"", j+1, LLD_CAST dts, LLD_CAST cts);
-			if (cts<dts) { fprintf(dump, " #NEGATIVE CTS OFFSET!!!"); has_error = 1;}
+			gf_set_progress("Getting Track Timing", j+1, count);
+		}
 		
+		for (j=0; j<count; j++) {
+			fprintf(dump, "Sample %d - DTS "LLD" - CTS "LLD"", j+1, LLD_CAST dts[j], LLD_CAST cts[j]);
+			if (cts[j]<dts[j]) { fprintf(dump, " #NEGATIVE CTS OFFSET!!!"); has_error = 1;}
+
 			if (has_cts_offset) {
 				for (k=0; k<count; k++) {
-					u64 adts, acts;
 					if (k==j) continue;
-					samp = gf_isom_get_sample_info(file, i+1, k+1, NULL, NULL);
-					adts = samp->DTS;
-					acts = adts + (s32) samp->CTS_Offset;
-
-					if (adts==dts) { fprintf(dump, " #SAME DTS USED!!!"); has_error = 1; }
-					if (acts==cts) { fprintf(dump, " #SAME CTS USED!!! "); has_error = 1; }
-
-					gf_isom_sample_del(&samp);
+					if (dts[j]==dts[k]) { fprintf(dump, " #SAME DTS USED!!!"); has_error = 1; }
+					if (cts[j]==cts[k]) { fprintf(dump, " #SAME CTS USED!!!"); has_error = 1; }
 				}
 			}
 
 			fprintf(dump, "\n");
 			gf_set_progress("Analysing Track Timing", j+1, count);
+
+		if( !dts ) {gf_free(dts); dts = NULL;}
+		if( !cts ) {gf_free(cts); cts = NULL;}
 		}
 		fprintf(dump, "\n\n");
 		gf_set_progress("Analysing Track Timing", count, count);
@@ -1195,6 +1205,16 @@
 					else szName = "Unknown";
 					fprintf(stdout, "Ogg/%s video / GPAC Mux  - Visual Size %d x %d\n", szName, w, h);
 				}
+				else if (esd->decoderConfig->objectTypeIndication==0xA3) {
+					gf_isom_get_visual_info(file, trackNum, 1, &w, &h);
+					if (full_dump) fprintf(stdout, "\t");
+					fprintf(stdout, "VC-1 Video - Visual Size %d x %d\n", w, h);
+				}
+				else if (esd->decoderConfig->objectTypeIndication==0xA4) {
+                    gf_isom_get_visual_info(file, trackNum, 1, &w, &h);
+					if (full_dump) fprintf(stdout, "\t");
+					fprintf(stdout, "Dirac Video - Visual Size %d x %d\n", w, h);
+				}
 				if (!w || !h) {
 					gf_isom_get_visual_info(file, trackNum, 1, &w, &h);
 					if (full_dump) fprintf(stdout, "\t");
@@ -1220,6 +1240,7 @@
 					else {
 						fprintf(stdout, "MPEG-%d Audio %s - %d Channel(s) - SampleRate %d", is_mp2 ? 2 : 4, gf_m4a_object_type_name(a_cfg.base_object_type), a_cfg.nb_chan, a_cfg.base_sr);
 						if (a_cfg.has_sbr) fprintf(stdout, " - SBR SampleRate %d", a_cfg.sbr_sr);
+						if (a_cfg.has_ps) fprintf(stdout, " - PS");
 						fprintf(stdout, "\n");
 					}
 #else
@@ -1442,7 +1463,12 @@
 			if (mtype==GF_ISOM_MEDIA_VISUAL) {
 				fprintf(stdout, "Visual Track - Compressor \"%s\" - Resolution %d x %d\n", udesc->compressor_name, udesc->width, udesc->height);
 			} else if (mtype==GF_ISOM_MEDIA_AUDIO) {
-				fprintf(stdout, "Audio Track - Sample Rate %d - %d channel(s)\n", udesc->samplerate, udesc->nb_channels);
+				if (msub_type == GF_ISOM_SUBTYPE_SAC3) {
+					fprintf(stdout, "AC3 Track - Sample Rate %d - %d channel(s)\n", udesc->samplerate, udesc->nb_channels);
+				}
+				else {
+					fprintf(stdout, "Audio Track - Sample Rate %d - %d channel(s)\n", udesc->samplerate, udesc->nb_channels);
+				}
 			} else {
 				fprintf(stdout, "Unknown media type\n");
 			}
Index: applications/mp4box/fileimport.c
===================================================================
RCS file: /cvsroot/gpac/gpac/applications/mp4box/fileimport.c,v
retrieving revision 1.82
diff -u -r1.82 fileimport.c
--- applications/mp4box/fileimport.c	9 Apr 2010 15:36:43 -0000	1.82
+++ applications/mp4box/fileimport.c	10 Apr 2010 14:31:09 -0000
@@ -120,6 +120,7 @@
 		if (import.tk_info[i].flags & GF_IMPORT_FORCE_PACKED) fprintf(stdout, "\tCan force packed bitstream import\n");
 		if (import.tk_info[i].flags & GF_IMPORT_OVERRIDE_FPS) fprintf(stdout, "\tCan override source frame rate\n");
 		if (import.tk_info[i].flags & (GF_IMPORT_SBR_IMPLICIT|GF_IMPORT_SBR_EXPLICIT)) fprintf(stdout, "\tCan use AAC-SBR signaling\n");
+        if (import.tk_info[i].flags & (GF_IMPORT_PS_IMPLICIT|GF_IMPORT_PS_EXPLICIT)) fprintf(stdout, "\tCan use AAC-PS signaling\n"); 
 		if (import.tk_info[i].flags & GF_IMPORT_FORCE_MPEG4) fprintf(stdout, "\tCan force MPEG-4 Systems signaling\n");
 		if (import.tk_info[i].flags & GF_IMPORT_3GPP_AGGREGATION) fprintf(stdout, "\tCan use 3GPP frame aggregation\n");
 		if (import.tk_info[i].flags & GF_IMPORT_NO_DURATION) fprintf(stdout, "\tCannot use duration-based import\n");
@@ -131,11 +132,43 @@
 	if (!found && trackID) fprintf(stdout, "Cannot find track %d in file\n", trackID);
 }
 
+static const char * const gf_avc_vidformat_names[] = { "component", "pal", "ntsc", "secam", "mac", "undef", NULL };
+static const char * const gf_avc_colorprim_names[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "film", NULL };
+static const char * const gf_avc_transfer_names[]  = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100", "log316", NULL };
+static const char * const gf_avc_colmatrix_names[] = { "GBR", "bt709", "undef", "", "fcc", "bt470bg", "smpte170m", "smpte240m", "YCgCo", NULL };
+
+#if 0
+typedef struct __gf_default_handler {
+	u32 type;
+	const char * handler_name;
+} _gf_default_handler;
+
+static const _gf_default_handler const gf_default_handler[] = {
+	{GF_ISOM_MEDIA_VISUAL, "GPAC ISO Video Handler"},
+	{GF_ISOM_MEDIA_AUDIO,  "GPAC ISO Audio Handler"},
+	{GF_ISOM_MEDIA_HINT,   "GPAC ISO Hint Handler"},
+	{GF_ISOM_MEDIA_META,   "GPAC Timed MetaData Handler"},
+	{GF_ISOM_MEDIA_OD,     "GPAC MPEG-4 OD Handler"},
+	{GF_ISOM_MEDIA_OCR,    "GPAC MPEG-4 OCR Handler"},
+	{GF_ISOM_MEDIA_SCENE,  "GPAC MPEG-4 Scene Description Handler"},
+	{GF_ISOM_MEDIA_MPEG7,  "GPAC MPEG-4 MPEG-7 Handler"},
+	{GF_ISOM_MEDIA_OCI,    "GPAC MPEG-4 OCI Handler"},
+	{GF_ISOM_MEDIA_IPMP,   "GPAC MPEG-4 IPMP Handler"},
+	{GF_ISOM_MEDIA_MPEGJ,  "GPAC MPEG-4 MPEG-J Handler"},
+	{GF_ISOM_MEDIA_TEXT,   "GPAC Streaming Text Handler"},
+	{GF_ISOM_MEDIA_SUBT,   "GPAC Streaming Text Handler"},
+	{GF_ISOM_MEDIA_DIMS,   "GPAC DIMS Handler"},
+	{0, NULL},
+};
+#endif
+
 GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double force_fps, u32 frames_per_sample)
 {
-	u32 track_id, i, timescale, track, stype, profile, level;
+	u32 track_id, i, timescale, track, stype, profile, compat, level;
+	s32 fullrange, vidformat, colorprim, transfer, colmatrix;
 	s32 par_d, par_n, prog_id, delay;
 	s32 tw, th, tx, ty;
+    Bool do_ctdelay;
 	Bool do_audio, do_video, do_all, disable, track_layout, chap_ref, is_chap, keep_handler;
 	u32 group, handler;
 	const char *szLan;
@@ -159,12 +192,19 @@
 	track_layout = 0;
 	szLan = NULL;
 	delay = 0;
+	do_ctdelay = 0;
 	group = 0;
 	stype = 0;
-	profile = level = 0;
+	profile = level = compat = 0;
 
 	tw = th = tx = ty = 0;
 	par_d = par_n = -2;
+	fullrange = -1;
+	vidformat = -1;
+	colorprim = -1;
+	transfer  = -1;
+	colmatrix = -1;
+
 	/*use ':' as separator, but beware DOS paths...*/
 	ext = strchr(szName, ':');
 	if (ext && ext[1]=='\\') ext = strchr(szName+2, ':');
@@ -178,6 +218,7 @@
 
 		/*all extensions for track-based importing*/
 		if (!strnicmp(ext+1, "lang=", 5)) szLan = GetLanguageCode(ext+6);
+		else if (!stricmp(ext+1, "delay=ct")) do_ctdelay = 1;
 		else if (!strnicmp(ext+1, "delay=", 6)) delay = atoi(ext+7);
 		else if (!strnicmp(ext+1, "fps=", 4)) {
 			if (!strcmp(ext+5, "auto")) force_fps = 10000.0;
@@ -196,6 +237,8 @@
 		else if (!stricmp(ext+1, "packed")) import_flags |= GF_IMPORT_FORCE_PACKED;
 		else if (!stricmp(ext+1, "sbr")) import_flags |= GF_IMPORT_SBR_IMPLICIT;
 		else if (!stricmp(ext+1, "sbrx")) import_flags |= GF_IMPORT_SBR_EXPLICIT;
+		else if (!stricmp(ext+1, "ps")) import_flags |= GF_IMPORT_PS_IMPLICIT;
+		else if (!stricmp(ext+1, "psx")) import_flags |= GF_IMPORT_PS_EXPLICIT;        
 		else if (!stricmp(ext+1, "svc")) import_flags |= GF_IMPORT_SVC_EXPLICIT;
 		else if (!stricmp(ext+1, "nosvc")) import_flags |= GF_IMPORT_SVC_NONE;
 		else if (!stricmp(ext+1, "mpeg4")) import_flags |= GF_IMPORT_FORCE_MPEG4;
@@ -211,6 +254,50 @@
 				sscanf(ext+5, "%d:%d", &par_n, &par_d);
 			}
 		}
+		else if (!strnicmp(ext+1, "fullrange=", 10)) {
+			if (!stricmp(ext+11, "off")) fullrange = 0;
+			else if (!stricmp(ext+11, "on")) fullrange = 1;
+		}
+		else if (!strnicmp(ext+1, "vidformat=", 10)) {
+			int i;
+			for( i=0; gf_avc_vidformat_names[i]; i++ )
+			{
+				if(!strcmp(ext+11, gf_avc_vidformat_names[i])) {
+					vidformat = i;
+					break;
+				}
+			}
+		}
+		else if (!strnicmp(ext+1, "colorprim=", 10)) {
+			int i;
+			for( i=0; gf_avc_colorprim_names[i]; i++ )
+			{
+				if(!strcmp(ext+11, gf_avc_colorprim_names[i])) {
+					colorprim = i;
+					break;
+				}
+			}
+		}
+		else if (!strnicmp(ext+1, "transfer=", 9)) {
+			int i;
+			for( i=0; gf_avc_transfer_names[i]; i++ )
+			{
+				if(!strcmp(ext+10, gf_avc_transfer_names[i])) {
+					transfer = i;
+					break;
+				}
+			}
+		}
+		else if (!strnicmp(ext+1, "colmatrix=", 10)) {
+			int i;
+			for( i=0; gf_avc_colmatrix_names[i]; i++ )
+			{
+				if(!strcmp(ext+11, gf_avc_colmatrix_names[i])) {
+					colmatrix = i;
+					break;
+				}
+			}
+		}
 		else if (!strnicmp(ext+1, "name=", 5)) handler_name = gf_strdup(ext+6);
 		else if (!strnicmp(ext+1, "font=", 5)) import.fontName = gf_strdup(ext+6);
 		else if (!strnicmp(ext+1, "size=", 5)) import.fontSize = atoi(ext+6);
@@ -230,9 +317,23 @@
 		else if (!strnicmp(ext+1, "stype=", 6)) {
 			stype = GF_4CC(ext[7], ext[8], ext[9], ext[10]);
 		}
-		else if (!strnicmp(ext+1, "profile=", 8)) profile = atoi(ext+9);
-		else if (!strnicmp(ext+1, "level=", 6)) level = atoi(ext+7);
-
+		else if (!strnicmp(ext+1, "profile=", 8)) {
+			if (!stricmp(ext+9, "high444")) profile = 244;
+			else if (!stricmp(ext+9, "high")) profile = 100;
+			else if (!stricmp(ext+9, "extended")) profile = 88;
+			else if (!stricmp(ext+9, "main")) profile = 77;
+			else if (!stricmp(ext+9, "baseline")) profile = 66;
+			else profile = atoi(ext+9);
+		}
+		else if (!strnicmp(ext+1, "compat=", 7)) {
+				compat = atoi(ext+8);
+		}
+		else if (!strnicmp(ext+1, "level=", 6)) {
+			if( atof(ext+7) < 6 )
+				level = (int)(10*atof(ext+7)+.5);
+			else
+				level = atoi(ext+7);
+		}
 
 		/*unrecognized, assume name has colon in it*/
 		else {
@@ -325,7 +426,7 @@
 	import.flags = import_flags;
 
 	if (!import.nb_tracks) {
-		u32 count, o_count;
+		u32 count, o_count, media_ts;
 		o_count = gf_isom_get_track_count(import.dest);
 		e = gf_media_import(&import);
 		if (e) return e;
@@ -333,15 +434,31 @@
 		timescale = gf_isom_get_timescale(dest);
 		for (i=o_count; i<count; i++) {
 			if (szLan) gf_isom_set_media_language(import.dest, i+1, (char *) szLan);
+			if (do_ctdelay) {
+				GF_ISOSample *samp;
+				u64 tk_dur;
+				samp = gf_isom_get_sample_info(import.dest, i+1, 1, NULL, NULL);
+				if (!samp) {
+					fprintf(stdout, "Track ID %d ctdelay failed\n", i+1);
+					goto exit;
+				}
+				if (samp->CTS_Offset > 0) {
+					tk_dur = gf_isom_get_track_duration(import.dest, i+1);
+					gf_isom_remove_edit_segments(import.dest, i+1);
+					gf_isom_append_edit_segment(import.dest, i+1, tk_dur, samp->CTS_Offset, GF_ISOM_EDIT_NORMAL);
+				}
+				gf_isom_sample_del(&samp);
+			}
 			if (delay) {
 				u64 tk_dur;
 				gf_isom_remove_edit_segments(import.dest, i+1);
 				tk_dur = gf_isom_get_track_duration(import.dest, i+1);
+                media_ts = gf_isom_get_media_timescale(dest, i+1);
 				if (delay>0) {
-					gf_isom_append_edit_segment(import.dest, i+1, (timescale*delay)/1000, 0, GF_ISOM_EDIT_EMPTY);
+					gf_isom_append_edit_segment(import.dest, i+1, (timescale*delay)/media_ts, 0, GF_ISOM_EDIT_EMPTY);
 					gf_isom_append_edit_segment(import.dest, i+1, tk_dur, 0, GF_ISOM_EDIT_NORMAL);
 				} else {
-					u64 to_skip = (timescale*(-delay))/1000;
+					u64 to_skip = (timescale*(-delay))/media_ts;
 					if (to_skip<tk_dur) {
 						//u64 seg_dur = (-delay)*gf_isom_get_media_timescale(import.dest, i+1) / 1000;
 						gf_isom_append_edit_segment(import.dest, i+1, tk_dur-to_skip, to_skip, GF_ISOM_EDIT_NORMAL);
@@ -356,9 +473,12 @@
 			if (handler_name) gf_isom_set_handler_name(import.dest, i+1, handler_name);
 			else if (!keep_handler) {
 				char szHName[1024];
-				sprintf(szHName, "%s - Imported with GPAC %s", inName, GPAC_FULL_VERSION);
+				sprintf(szHName, "Imported with GPAC %s", GPAC_FULL_VERSION);
 				gf_isom_set_handler_name(import.dest, i+1, szHName);
 			}
+			if (fullrange>=0 || vidformat>=0 || colorprim>=0 || transfer>=0 || colmatrix>=0) {
+				e = gf_media_change_colorprop(import.dest, i+1, fullrange, vidformat, colorprim, transfer, colmatrix);
+			}
 			if (handler) gf_isom_set_media_type(import.dest, i+1, handler);
 			if (disable) gf_isom_set_track_enabled(import.dest, i+1, 0);
 
@@ -376,8 +496,8 @@
 				gf_isom_set_track_enabled(import.dest, i+1, 0);
 			}
 
-			if (profile || level) 
-				gf_media_change_pl(import.dest, i+1, profile, level);
+			if (profile || compat || level) 
+				gf_media_change_pl(import.dest, i+1, profile, compat, level);
 
 			if (gf_isom_get_media_subtype(import.dest, i+1, 1)== GF_4CC( 'm', 'p', '4', 's' ))
 				keep_sys_tracks = 1;
@@ -409,16 +529,30 @@
 			track = gf_isom_get_track_by_id(import.dest, import.final_trackID);
 			if (szLan) gf_isom_set_media_language(import.dest, track, (char *) szLan);
 			if (disable) gf_isom_set_track_enabled(import.dest, track, 0);
-
+			if (do_ctdelay) {
+				GF_ISOSample *samp;
+				u64 tk_dur;
+				samp = gf_isom_get_sample_info(import.dest, track, 1, NULL, NULL);
+				if (!samp) {
+					fprintf(stdout, "Track ID %d ctdelay failed\n", track);
+					goto exit;
+				}
+				if (samp->CTS_Offset > 0) {
+					tk_dur = gf_isom_get_track_duration(import.dest, track);
+					gf_isom_remove_edit_segments(import.dest, track);
+					gf_isom_append_edit_segment(import.dest, track, tk_dur, samp->CTS_Offset, GF_ISOM_EDIT_NORMAL);
+				}
+				gf_isom_sample_del(&samp);
+			}
 			if (delay) {
 				u64 tk_dur;
 				gf_isom_remove_edit_segments(import.dest, track);
 				tk_dur = gf_isom_get_track_duration(import.dest, track);
 				if (delay>0) {
-					gf_isom_append_edit_segment(import.dest, track, (timescale*delay)/1000, 0, GF_ISOM_EDIT_EMPTY);
+					gf_isom_append_edit_segment(import.dest, track, timescale*(delay/1000.0), -1, GF_ISOM_EDIT_EMPTY);
 					gf_isom_append_edit_segment(import.dest, track, tk_dur, 0, GF_ISOM_EDIT_NORMAL);
 				} else {
-					u64 to_skip = (timescale*(-delay))/1000;
+					u64 to_skip = timescale*(-delay/1000.0);
 					if (to_skip<tk_dur) {
 						//u64 seg_dur = (-delay)*gf_isom_get_media_timescale(import.dest, i+1) / 1000;
 						gf_isom_append_edit_segment(import.dest, i+1, tk_dur-to_skip, to_skip, GF_ISOM_EDIT_NORMAL);
@@ -433,9 +567,14 @@
 			if (handler_name) gf_isom_set_handler_name(import.dest, track, handler_name);
 			else if (!keep_handler) {
 				char szHName[1024];
-				sprintf(szHName, "%s - Imported with GPAC %s", inName, GPAC_FULL_VERSION);
+				sprintf(szHName, "Imported with GPAC %s", GPAC_FULL_VERSION);
 				gf_isom_set_handler_name(import.dest, track, szHName);
 			}
+			if ((import.tk_info[i].type==GF_ISOM_MEDIA_VISUAL)
+				&& (fullrange>=0 || vidformat>=0 || colorprim>=0 || transfer>=0 || colmatrix>=0))
+			{
+				e = gf_media_change_colorprop(import.dest, i+1, fullrange, vidformat, colorprim, transfer, colmatrix);
+			}
 			if (handler) gf_isom_set_media_type(import.dest, track, handler);
 
 			if (group) {
@@ -453,8 +592,8 @@
 				gf_isom_set_track_enabled(import.dest, track, 0);
 			}
 
-			if (profile || level) 
-				gf_media_change_pl(import.dest, track, profile, level);
+			if (profile || compat || level) 
+				gf_media_change_pl(import.dest, track, profile, compat, level);
 
 			if (gf_isom_get_mpeg4_subtype(import.dest, track, 1))
 				keep_sys_tracks = 1;
Index: applications/mp4box/main.c
===================================================================
RCS file: /cvsroot/gpac/gpac/applications/mp4box/main.c,v
retrieving revision 1.114
diff -u -r1.114 main.c
--- applications/mp4box/main.c	9 Apr 2010 16:09:54 -0000	1.114
+++ applications/mp4box/main.c	10 Apr 2010 14:34:32 -0000
@@ -131,7 +131,7 @@
 	{GF_ISOM_ITUNE_COMMENT, "comment", "usage: comment=any comment"},
 	{GF_ISOM_ITUNE_COMPILATION, "compilation", "usage: compilation=yes,no"},
 	{GF_ISOM_ITUNE_COMPOSER, "composer", "usage: composer=name"},
-	{GF_ISOM_ITUNE_CREATED, "created", ""},
+	{GF_ISOM_ITUNE_CREATED, "created", "usage: created=year"},
 	{GF_ISOM_ITUNE_DISK, "disk", "usage: disk=x/N"},
 	{GF_ISOM_ITUNE_TOOL, "tool", "usage: tool=name"},
 	{GF_ISOM_ITUNE_GENRE, "genre", "usage: genre=name"},
@@ -139,7 +139,7 @@
 	{GF_ISOM_ITUNE_TEMPO, "tempo", "usage: tempo=integer"},
 	{GF_ISOM_ITUNE_WRITER, "writer", "usage: writer=name"},
 	{GF_ISOM_ITUNE_GROUP, "group", "usage: group=name"},
-	{GF_ISOM_ITUNE_COVER_ART, "cover", "usage: covber=file.jpg,file.png"},
+	{GF_ISOM_ITUNE_COVER_ART, "cover", "usage: cover=file.jpg,file.png"},
 	{GF_ISOM_ITUNE_ENCODER, "encoder", "usage: encoder=name"},
 	{GF_ISOM_ITUNE_GAPELESS, "gapeless", "usage: artist=yes,no"},
 };
@@ -150,6 +150,7 @@
 void PrintVersion()
 {
 	fprintf(stdout, "MP4Box - GPAC version " GPAC_FULL_VERSION "\n"
+        "Compilation Date: "__DATE__" - by Kurtnoise\n"
 		"GPAC Copyright: (c) Jean Le Feuvre 2000-2005\n\t\t(c) ENST 2005-200X\n"
 		"GPAC Configuration: " GPAC_CONFIGURATION "\n"
 		"Features: %s\n", gpac_features());
@@ -181,6 +182,7 @@
 			"                       * Note 1: some tracks may be removed in the process\n"
 			"                       * Note 2: always on for *.3gp *.3g2 *.3gpp\n"
 			" -ipod                rewrites the file for iPod\n"
+            " -psp                 rewrites the file for PSP devices\n" 
 			" -brand ABCD[:v]      sets major brand of file, with optional version\n"
 			" -ab ABCD             adds given brand to file's alternate brand list\n"
 			" -rb ABCD             removes given brand from file's alternate brand list\n"
@@ -292,12 +294,33 @@
 			" \":packed\"            same as -packed option\n"
 			" \":sbr\"               same as -sbr option\n"
 			" \":sbrx\"              same as -sbrx option\n"
+			" \":ps\":               same as -ps option\n"
+			" \":psx\":              same as -psx option\n"
+            " \":ovsbr\":            same as -ovsbr option\n"  
 			" \":mpeg4\"             same as -mpeg4 option\n"
 			" \":font=name\"         specifies font name for text import (default \"Serif\")\n"
 			" \":size=s\"            specifies font size for text import (default 18)\n"
 			" \":stype=4CC\"         forces the sample description type to a different value\n"
 			"                         !! THIS MAY BREAK THE FILE WRITING !!\n"
 			" \":chap\"              specifies the track is a chapter track\n"
+			" \":profile\"           forces the profile for the H.264 content\n"
+			"                         - high444, high, extended, main, baseline\n"
+     		"                         *WARNING* wrong value may cause playback issue\n"
+			" \":compat\"            forces the profile compatibity flags for the H.264 content\n"
+			"                         *WARNING* wrong value may cause playback issue\n"
+			" \":level\"             forces the level for the H.264 content\n"
+			"                         *Note: If value < 6, interpreted as decimal expression\n"
+			" \":vidformat\"         forces the video_format flag in VUI for the H.264 content\n"
+			"                         - component, pal, ntsc, secam, mac, undef\n"
+			" \":fullrange\"         forces the video_full_range_flag in VUI for the H.264 content\n"
+			"                         - on, off\n"
+			" \":colorprim\"         forces the colour_primaries flag in VUI for the H.264 content\n"
+			"                         - bt709, undef, bt470m, bt470bg, smpte170m, smpte240m, film\n"
+			" \":transfer\"          forces the transfer_characteristics flag in VUI for the H.264 content\n"
+			"                         - bt709, undef, bt470m, bt470bg, smpte170m, smpte240m, linear\n"
+			"                           log100, log316\n"
+			" \":colmatrix\"         forces the matrix_coefficients flag in VUI for the H.264 content\n"
+			"                         - GBR, bt709, undef, fcc, bt470bg, smpte170m, smpte240m, YCgCo\n"
 			" \":layout=WxHxXxY\"    specifies the track layout\n"
 			"                         - if W (resp H) = 0, the max width (resp height) of\n"
 			"                         the tracks in the file are used.\n"
@@ -320,7 +343,10 @@
 			" -packed                forces packed bitstream when importing raw ASP\n"
 			" -sbr                   backward compatible signaling of AAC-SBR\n"
 			" -sbrx                  non-backward compatible signaling of AAC-SBR\n"
-			"                         * Note: SBR AAC cannot be detected at import time\n"
+			" -ps:                 backward compatible signaling of AAC-PS\n"
+			" -psx:                non-backward compatible signaling of AAC-PS\n"
+			" -ovsbr:              oversample SBR\n"
+			"                       * Note: SBR AAC, PS AAC and oversampled SBR cannot be detected at import time\n"
 			" -fps FPS               forces frame rate for video and SUB subtitles import\n"
 			"                         FPS is either a number or expressed as timescale-increment\n"
 			"                         * For raw H263 import, default FPS is 15\n"
@@ -946,7 +972,7 @@
 } MetaAction;
 
 /*for SDP_EX, AddTrack and RemTrack*/
-#define MAX_CUMUL_OPS	20
+#define MAX_CUMUL_OPS	100
 
 #ifndef GPAC_DISABLE_ISOM_WRITE
 static Bool parse_meta_args(MetaAction *meta, char *opts)
@@ -1140,6 +1166,12 @@
 	GF_ISOM_CONV_TYPE_PSP
 };
 
+int compare_u64(const u64 *a, const u64 *b)
+{
+	s64 delta = (s64)(*a - *b);
+	return (delta > 0 ? 1 : delta == 0 ? 0 : -1);
+}
+
 int main(int argc, char **argv)
 {
 	char outfile[5000];
@@ -1378,6 +1410,7 @@
 		else if (!stricmp(arg, "-isma")) { conv_type = GF_ISOM_CONV_TYPE_ISMA; open_edit = 1; }
 		else if (!stricmp(arg, "-3gp")) { conv_type = GF_ISOM_CONV_TYPE_3GPP; open_edit = 1; }
 		else if (!stricmp(arg, "-ipod")) { conv_type = GF_ISOM_CONV_TYPE_IPOD; open_edit = 1; }
+        else if (!stricmp(arg, "-psp")) { conv_type = GF_ISOM_CONV_TYPE_PSP; open_edit = 1; } 
 		else if (!stricmp(arg, "-ismax")) { conv_type = GF_ISOM_CONV_TYPE_ISMA_EX; open_edit = 1; }
 
 		else if (!stricmp(arg, "-no-sys") || !stricmp(arg, "-nosys")) { remove_sys_tracks = 1; open_edit = 1; }
@@ -1653,6 +1686,9 @@
 		else if (!stricmp(arg, "-packed")) import_flags |= GF_IMPORT_FORCE_PACKED;
 		else if (!stricmp(arg, "-sbr")) import_flags |= GF_IMPORT_SBR_IMPLICIT;
 		else if (!stricmp(arg, "-sbrx")) import_flags |= GF_IMPORT_SBR_EXPLICIT;
+		else if (!stricmp(arg, "-ps")) import_flags |= GF_IMPORT_PS_IMPLICIT;
+		else if (!stricmp(arg, "-psx")) import_flags |= GF_IMPORT_PS_EXPLICIT;
+		else if (!stricmp(arg, "-ovsbr")) import_flags |= GF_IMPORT_OVSBR;
 		else if (!stricmp(arg, "-fps")) { 
 			CHECK_NEXT_ARG 
 			if (!strcmp(argv[i+1], "auto")) import_fps = 10000.0;
@@ -2390,7 +2426,7 @@
 					fwrite(desc, 1, size, iodf);
 					gf_free(desc);
 				} else {
-					fprintf(stdout, "Error writing IOD\n", szName);
+					fprintf(stdout, "Error writing IOD\n");
 				}
 				fclose(iodf);
 			}
@@ -2964,6 +3000,40 @@
 		needSave = 1;
 	}
 
+	/* fix inappropriate duration for vfr */
+	u32 nb_tracks = gf_isom_get_track_count(file);
+	for (i=0; i<nb_tracks; i++) {
+		if (gf_isom_get_media_type(file, i+1) == GF_ISOM_MEDIA_VISUAL) {
+			u32 j, count;
+			u64 *CTS = NULL;
+			u64 max_CTS = 0;
+			u32 min_CTS_delta;
+			u64 media_dur, last_dts, last_dur;
+
+			count = gf_isom_get_sample_count(file, i+1);
+			CTS = (u64 *)gf_malloc(sizeof(u64)*count);
+			if (!CTS) goto err_exit;
+
+			for (j=0; j<count; j++) {
+				GF_ISOSample *samp = gf_isom_get_sample_info(file, i+1, j+1, NULL, NULL);
+				CTS[j] = samp->DTS + samp->CTS_Offset;
+				gf_isom_sample_del(&samp);
+				max_CTS = MAX(CTS[j], max_CTS);
+			}
+			qsort(CTS, count, sizeof(u64), (int (*)(const void *, const void *))compare_u64);
+			min_CTS_delta = max_CTS;
+			for (j=1; j<count; j++) {
+				u32 CTS_delta = CTS[j] - CTS[j-1];
+				min_CTS_delta = MIN(CTS_delta, min_CTS_delta);
+			}
+			media_dur = max_CTS - CTS[0] + min_CTS_delta;
+			gf_free(CTS);
+			last_dts = gf_isom_get_sample_dts(file, i+1, count);
+			last_dur = (u32)(((media_dur > last_dts) ? media_dur : max_CTS + min_CTS_delta) - last_dts);
+			gf_isom_set_last_sample_duration(file, i+1, last_dur);
+		}
+	}
+
 	if (!encode && !force_new) gf_isom_set_final_name(file, outfile);
 	if (needSave) {
 		if (outName) {
Index: configure
===================================================================
RCS file: /cvsroot/gpac/gpac/configure,v
retrieving revision 1.80
diff -u -r1.80 configure
--- configure	18 Mar 2010 16:00:18 -0000	1.80
+++ configure	10 Apr 2010 17:49:59 -0000
@@ -291,7 +291,7 @@
   x86_64|amd64)
     cpu="x86"
     is_64="yes"
-    canon_arch="`cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
+    canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
     if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
       if [ -z "`echo $CFLAGS | grep -- -m32`"  ]; then
         cpu="x86_64"
Index: include/gpac/avparse.h
===================================================================
RCS file: /cvsroot/gpac/gpac/include/gpac/avparse.h,v
retrieving revision 1.14
diff -u -r1.14 avparse.h
--- include/gpac/avparse.h	26 Aug 2009 16:29:38 -0000	1.14
+++ include/gpac/avparse.h	10 Apr 2010 14:35:44 -0000
@@ -157,7 +157,7 @@
     GF_M4A_ER_HILN = 26,
     GF_M4A_ER_PARAMETRIC = 27,
     GF_M4A_SSC = 28,
-    //GF_M4A_PS = 29,
+    GF_M4A_AAC_PS = 29,
     GF_M4A_LAYER1 = 32,
     GF_M4A_LAYER2 = 33,
     GF_M4A_LAYER3 = 34,
@@ -181,6 +181,8 @@
 	/*SBR*/
 	Bool has_sbr;
 	u32 sbr_object_type, sbr_sr, sbr_sr_index;
+	/*PS*/
+	Bool has_ps;
 	/*PL indication*/
 	u8 audioPL;
 } GF_M4ADecSpecInfo;
Index: include/gpac/isomedia.h
===================================================================
RCS file: /cvsroot/gpac/gpac/include/gpac/isomedia.h,v
retrieving revision 1.47
diff -u -r1.47 isomedia.h
--- include/gpac/isomedia.h	29 Mar 2010 08:35:43 -0000	1.47
+++ include/gpac/isomedia.h	30 Mar 2010 19:33:47 -0000
@@ -216,7 +216,7 @@
 	GF_ISOM_SUBTYPE_3GP_DIMS	= GF_4CC( 'd', 'i', 'm', 's' ),
 
 	GF_ISOM_SUBTYPE_AC3			= GF_4CC( 'a', 'c', '-', '3' ),
-
+    GF_ISOM_SUBTYPE_SAC3        = GF_4CC( 's', 'a', 'c', '3' ),
 	GF_ISOM_SUBTYPE_LSR1		= GF_4CC( 'l', 's', 'r', '1' ),
 };
 
Index: include/gpac/media_tools.h
===================================================================
RCS file: /cvsroot/gpac/gpac/include/gpac/media_tools.h,v
retrieving revision 1.26
diff -u -r1.26 media_tools.h
--- include/gpac/media_tools.h	18 Nov 2009 09:05:26 -0000	1.26
+++ include/gpac/media_tools.h	10 Apr 2010 14:37:47 -0000
@@ -81,6 +81,13 @@
 	GF_IMPORT_SVC_EXPLICIT = 1<<10,
 	/*for SVC video: removes all SVC extensions*/
 	GF_IMPORT_SVC_NONE = 1<<11,
+	/*for AAC audio: forces PS mode with implicit signaling (backward compatible)*/
+	GF_IMPORT_PS_IMPLICIT = 1<<12,
+	/*for AAC audio: forces PS mode with explicit signaling (non-backward compatible). 
+	Will override GF_IMPORT_PS_IMPLICIT flag when set*/
+	GF_IMPORT_PS_EXPLICIT = 1<<13,	
+	/* oversampled SBR */
+	GF_IMPORT_OVSBR = 1<<14,
 	
 	/*when set, only updates tracks info and return*/
 	GF_IMPORT_PROBE_ONLY	= 1<<20,
@@ -216,11 +223,18 @@
 */
 GF_Err gf_media_make_psp(GF_ISOFile *mp4file);
 
+/*changes color property of the media - only AVC/H264 supported for now.
+Negative values keep source settings for the corresponding flags.
+If source stream has no VUI info, create one and set corresponding flags to specified values.
+In this case, any other flags are set to prefered values (typically, flag=0 or value=undef).
+*/
+GF_Err gf_media_change_colorprop(GF_ISOFile *file, u32 track, s32 fullrange, s32 vidformat, s32 colorprim, s32 transfer, s32 colmatrix);
+
 /*changes pixel aspect ratio for visual tracks if supported. Negative values remove any PAR info*/
 GF_Err gf_media_change_par(GF_ISOFile *file, u32 track, s32 ar_num, s32 ar_den);
 
 /*changes the profile (if not 0) and level (if not 0) indication of the media - only AVC/H264 supported for now*/
-GF_Err gf_media_change_pl(GF_ISOFile *file, u32 track, u32 profile, u32 level);
+GF_Err gf_media_change_pl(GF_ISOFile *file, u32 track, u32 profile, u32 compat, u32 level);
 
 #endif /*GPAC_DISABLE_MEDIA_IMPORT*/
 
Index: include/gpac/internal/avilib.h
===================================================================
RCS file: /cvsroot/gpac/gpac/include/gpac/internal/avilib.h,v
retrieving revision 1.2
diff -u -r1.2 avilib.h
--- include/gpac/internal/avilib.h	31 Jul 2009 07:37:40 -0000	1.2
+++ include/gpac/internal/avilib.h	2 Aug 2009 09:24:43 -0000
@@ -300,9 +300,11 @@
 #define WAVE_FORMAT_YAMAHA_ADPCM        (0x0020)
 #define WAVE_FORMAT_DSP_TRUESPEECH      (0x0022)
 #define WAVE_FORMAT_GSM610              (0x0031)
+#define WAVE_FORMAT_MP3                 (0x0055)
 #define IBM_FORMAT_MULAW                (0x0101)
 #define IBM_FORMAT_ALAW                 (0x0102)
 #define IBM_FORMAT_ADPCM                (0x0103)
+#define WAVE_FORMAT_AC3                 (0x2000)
 #endif
 
 avi_t* AVI_open_output_file(char * filename);
Index: include/gpac/internal/media_dev.h
===================================================================
RCS file: /cvsroot/gpac/gpac/include/gpac/internal/media_dev.h,v
retrieving revision 1.8
diff -u -r1.8 media_dev.h
--- include/gpac/internal/media_dev.h	8 Feb 2010 17:40:22 -0000	1.8
+++ include/gpac/internal/media_dev.h	9 Apr 2010 20:06:27 -0000
@@ -146,6 +146,9 @@
 s32 AVC_ReadPictParamSet(GF_BitStream *bs, AVCState *avc);
 /*is slice a RAP*/
 Bool AVC_SliceIsIDR(AVCState *avc);
+/* decode & encode rbsp from input stream */
+s32 AVC_DecodeNAL(char *buf, u32 buf_size, char *rbsp_buf);
+s32 AVC_EncodeNAL(char *buf, u32 buf_size, char *rbsp_buf);
 /*parses NALU, updates avc state and returns:
 	1 if NALU part of new frame
 	0 if NALU part of prev frame
@@ -156,6 +159,10 @@
 u32 AVC_ReformatSEI_NALU(char *buffer, u32 nal_size, AVCState *avc);
 
 #ifndef GPAC_DISABLE_ISOM
+GF_Err AVC_ChangeColorProp(GF_AVCConfig *avcc, s32 fullrange, s32 vidformat, s32 colorprim, s32 transfer, s32 colmatrix);
+#endif
+
+#ifndef GPAC_DISABLE_ISOM
 GF_Err AVC_ChangePAR(GF_AVCConfig *avcc, s32 ar_n, s32 ar_d);
 #endif
 
Index: modules/aac_in/aac_in.c
===================================================================
RCS file: /cvsroot/gpac/gpac/modules/aac_in/aac_in.c,v
retrieving revision 1.17
diff -u -r1.17 aac_in.c
--- modules/aac_in/aac_in.c	23 Feb 2010 16:23:33 -0000	1.17
+++ modules/aac_in/aac_in.c	10 Apr 2010 14:38:49 -0000
@@ -121,6 +121,10 @@
 	gf_bs_write_int(dsi, 1, 1);
 	gf_bs_write_int(dsi, sbr_sr_idx, 4);
 
+	/* always signal implicit PS in case it's used ??? */
+	gf_bs_write_int(dsi, 0x548, 11);
+	gf_bs_write_int(dsi, 1, 1);
+	
 	gf_bs_align(dsi);
 	gf_bs_get_content(dsi, &esd->decoderConfig->decoderSpecificInfo->data, &esd->decoderConfig->decoderSpecificInfo->dataLength);
 	gf_bs_del(dsi);
Index: modules/mpegts_in/mpegts_in.c
===================================================================
RCS file: /cvsroot/gpac/gpac/modules/mpegts_in/mpegts_in.c,v
retrieving revision 1.57
diff -u -r1.57 mpegts_in.c
--- modules/mpegts_in/mpegts_in.c	23 Feb 2010 16:23:33 -0000	1.57
+++ modules/mpegts_in/mpegts_in.c	23 Feb 2010 19:25:29 -0000
@@ -389,6 +389,10 @@
 		esd->decoderConfig->streamType = GF_STREAM_VISUAL;
 		esd->decoderConfig->objectTypeIndication = GPAC_OTI_VIDEO_AVC;
 		break;
+	case GF_M2TS_VIDEO_VC1:
+		esd->decoderConfig->streamType = GF_STREAM_VISUAL;
+		esd->decoderConfig->objectTypeIndication = 0xA3;
+		break;
 	case GF_M2TS_AUDIO_MPEG1:
 		esd->decoderConfig->streamType = GF_STREAM_AUDIO;
 		esd->decoderConfig->objectTypeIndication = GPAC_OTI_AUDIO_MPEG1;
Index: src/isomedia/avc_ext.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/isomedia/avc_ext.c,v
retrieving revision 1.15
diff -u -r1.15 avc_ext.c
--- src/isomedia/avc_ext.c	23 Feb 2010 16:24:19 -0000	1.15
+++ src/isomedia/avc_ext.c	10 Apr 2010 13:34:13 -0000
@@ -269,6 +269,7 @@
 GF_Err gf_isom_set_ipod_compatible(GF_ISOFile *the_file, u32 trackNumber)
 {
 	static const u8 ipod_ext[][16] = { { 0x6B, 0x68, 0x40, 0xF2, 0x5F, 0x24, 0x4F, 0xC5, 0xBA, 0x39, 0xA5, 0x1B, 0xCF, 0x03, 0x23, 0xF3} };
+    static const u8 ipod_ext_data[][4] = { { 0x00, 0x00, 0x00, 0x00 } }; 
 	GF_TrackBox *trak;
 	GF_Err e;
 	GF_MPEGVisualSampleEntryBox *entry;
@@ -290,7 +291,9 @@
 
 	if (!entry->ipod_ext) entry->ipod_ext = (GF_UnknownUUIDBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_UUID);
 	memcpy(entry->ipod_ext->uuid, ipod_ext, sizeof(u8)*16);
-	entry->ipod_ext->dataSize = 0;
+	entry->ipod_ext->dataSize = 4;
+	entry->ipod_ext->data = (char *)gf_malloc(sizeof(u8)*4);
+	memcpy(entry->ipod_ext->data, ipod_ext_data, sizeof(u8)*4);
 	return GF_OK;
 }
 
Index: src/isomedia/isom_store.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/isomedia/isom_store.c,v
retrieving revision 1.19
diff -u -r1.19 isom_store.c
--- src/isomedia/isom_store.c	23 Feb 2010 16:24:19 -0000	1.19
+++ src/isomedia/isom_store.c	10 Apr 2010 10:28:31 -0000
@@ -29,6 +29,8 @@
 
 #define GPAC_ISOM_CPRT_NOTICE "IsoMedia File Produced with GPAC "GPAC_FULL_VERSION
 
+extern GF_Err stbl_ShiftOffset(GF_Box **a, u64 offset, u32 start, u32 end);
+
 static GF_Err gf_isom_insert_copyright(GF_ISOFile *movie)
 {
 	u32 i;
@@ -193,6 +195,48 @@
 	}
 }
 
+#if 1
+static GF_Err ShiftOffset(GF_ISOFile *file, GF_List *writers, u64 offset, u8 *converted)
+{
+	u32 i, j, end;
+	TrackWriter *writer;
+	GF_StscEntry *ent;
+	GF_Box *box;
+	GF_Err result;
+
+	*converted = 0;
+	if (file->meta) ShiftMetaOffset(file->meta, offset);
+	if (file->moov && file->moov->meta) ShiftMetaOffset(file->moov->meta, offset);
+
+	i = 0;
+	while ((writer = (TrackWriter *)gf_list_enum(writers, &i))) {
+		if (writer->mdia->mediaTrack->meta) ShiftMetaOffset(writer->mdia->mediaTrack->meta, offset);
+
+		//we have to proceed entry by entry in case a part of the media is not self-contained...
+		for (j=0; j<writer->stsc->nb_entries; j++) {
+			ent = &writer->stsc->entries[j];
+			if (!Media_IsSelfContained(writer->mdia, ent->sampleDescriptionIndex)) continue;
+
+			if (writer->stco->type == GF_ISOM_BOX_TYPE_STCO) {
+				end = ent->nextChunk ? ent->nextChunk : ((GF_ChunkOffsetBox *)writer->stco)->nb_entries + 1;
+			} else {
+				end = ent->nextChunk ? ent->nextChunk : ((GF_ChunkLargeOffsetBox *)writer->stco)->nb_entries + 1;
+			}
+
+			box = writer->stco;
+			if((result = stbl_ShiftOffset(&box, offset, ent->firstChunk, end))!=GF_OK) {
+				return result;
+			}
+			if(box!=writer->stco){
+				writer->stco = box;
+				*converted = 1;
+			}
+		}
+	}
+			
+	return GF_OK;
+}
+#else
 static GF_Err ShiftOffset(GF_ISOFile *file, GF_List *writers, u64 offset)
 {
 	u32 i, j, k, l, last;
@@ -224,8 +268,8 @@
 						//too bad, rewrite the table....
 						co64 = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
 						if (!co64) return GF_OUT_OF_MEM;
-						co64->nb_entries = stco->nb_entries;
-						co64->offsets = (u64*)gf_malloc(co64->nb_entries * sizeof(u64));
+						co64->nb_entries = co64->alloc_size = stco->nb_entries;
+						co64->offsets = (u64*)malloc(co64->alloc_size * sizeof(u64));
 						if (!co64) {
 							gf_isom_box_del((GF_Box *)co64);
 							return GF_OUT_OF_MEM;
@@ -237,7 +281,7 @@
 						}
 						//and replace our box
 						gf_isom_box_del(writer->stco);
-						writer->stco = (GF_Box *)co64;
+						stco = writer->stco = (GF_Box *)co64;
 					} else {
 						stco->offsets[k-1] += (u32) offset;
 					}
@@ -256,7 +300,7 @@
 	return GF_OK;
 
 }
-
+#endif
 
 //replace the chunk and offset tables...
 static GF_Err WriteMoovAndMeta(GF_ISOFile *movie, GF_List *writers, GF_BitStream *bs)
@@ -592,8 +636,9 @@
 GF_Err WriteFlat(MovieWriter *mw, u8 moovFirst, GF_BitStream *bs)
 {
 	GF_Err e;
+	u8 converted;
 	u32 i;
-	u64 offset, finalOffset, totSize, begin, firstSize, finalSize;
+	u64 offset, shift_offset, prev, totSize, begin;
 	GF_Box *a;
 	GF_List *writers = gf_list_new();
 	GF_ISOFile *movie = mw->movie;
@@ -741,23 +786,16 @@
 	e = DoWrite(mw, writers, bs, 1, gf_bs_get_position(bs));
 	if (e) goto exit;
 	
-	firstSize = GetMoovAndMetaSize(movie, writers);
-	//offset = (firstSize > 0xFFFFFFFF ? firstSize + 8 : firstSize) + 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
-	offset = firstSize + 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
-	e = ShiftOffset(movie, writers, offset);
-	if (e) goto exit;
-	//get the size and see if it has changed (eg, we moved to 64 bit offsets)
-	finalSize = GetMoovAndMetaSize(movie, writers);
-	if (firstSize != finalSize) {
-		//we need to remove our offsets
-		ResetWriters(writers);
-		//finalOffset = (finalSize > 0xFFFFFFFF ? finalSize + 8 : finalSize) + 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
-		finalOffset = finalSize + 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
-		//OK, now we're sure about the final size.
-		//we don't need to re-emulate, as the only thing that changed is the offset
-		//so just shift the offset
-		e = ShiftOffset(movie, writers, finalOffset - offset);
+	shift_offset = 0;
+	prev = 0;
+	for(;;){
+		offset = GetMoovAndMetaSize(movie, writers);
+		if(offset==prev) break;
+		prev = offset;
+		offset += 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
+		e = ShiftOffset(movie, writers, offset-shift_offset,&converted);
 		if (e) goto exit;
+        shift_offset = offset; 
 	}
 	//now write our stuff
 	e = WriteMoovAndMeta(movie, writers, bs);
@@ -1131,9 +1169,10 @@
 static GF_Err WriteInterleaved(MovieWriter *mw, GF_BitStream *bs, Bool drift_inter)
 {
 	GF_Err e;
+    u8 converted; 
 	u32 i;
 	GF_Box *a;
-	u64 firstSize, finalSize, offset, finalOffset;
+	u64 offset, shift_offset, prev;
 	GF_List *writers = gf_list_new();
 	GF_ISOFile *movie = mw->movie;
 
@@ -1163,23 +1202,16 @@
 	e = DoInterleave(mw, writers, bs, 1, (u32) gf_bs_get_position(bs), drift_inter);
 	if (e) goto exit;
 
-	firstSize = GetMoovAndMetaSize(movie, writers);
-	offset = firstSize;
-	if (movie->mdat && movie->mdat->dataSize) offset += 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
-	e = ShiftOffset(movie, writers, offset);
-	if (e) goto exit;
-	//get the size and see if it has changed (eg, we moved to 64 bit offsets)
-	finalSize = GetMoovAndMetaSize(movie, writers);
-	if (firstSize != finalSize) {
-		//we need to remove our offsets
-		ResetWriters(writers);
-		finalOffset = finalSize;
-		if (movie->mdat->dataSize) finalOffset += 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
-		//OK, now we're sure about the final size -> shift the offsets
-		//we don't need to re-emulate, as the only thing that changed is the offset
-		//so just shift the offset
-		e = ShiftOffset(movie, writers, finalOffset - offset);
+	shift_offset = 0;
+	prev = 0;
+	for(;;){
+		offset = GetMoovAndMetaSize(movie, writers);
+		if(offset==prev) break;
+		prev = offset;
+	    if (movie->mdat && movie->mdat->dataSize) offset += 8 + (movie->mdat->dataSize > 0xFFFFFFFF ? 8 : 0);
+        e = ShiftOffset(movie, writers, offset-shift_offset,&converted);
 		if (e) goto exit;
+        shift_offset = offset; 
 	}
 	//now write our stuff
 	e = WriteMoovAndMeta(movie, writers, bs);
Index: src/isomedia/isom_write.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/isomedia/isom_write.c,v
retrieving revision 1.52
diff -u -r1.52 isom_write.c
--- src/isomedia/isom_write.c	29 Mar 2010 08:35:43 -0000	1.52
+++ src/isomedia/isom_write.c	30 Mar 2010 19:33:55 -0000
@@ -1245,6 +1245,13 @@
 		((GF_AudioSampleEntryBox*)entry)->samplerate_lo = 0;
 		((GF_AudioSampleEntryBox*)entry)->channel_count = nbChannels;
 		((GF_AudioSampleEntryBox*)entry)->bitspersample = bitsPerSample;
+		return GF_OK;	
+	case GF_ISOM_SUBTYPE_AC3:
+	case GF_ISOM_SUBTYPE_SAC3:
+		((GF_AC3SampleEntryBox*)entry)->samplerate_hi = sampleRate;
+		((GF_AC3SampleEntryBox*)entry)->samplerate_lo = 0;
+		((GF_AC3SampleEntryBox*)entry)->channel_count = nbChannels;
+		((GF_AC3SampleEntryBox*)entry)->bitspersample = bitsPerSample;
 		return GF_OK;
 	/*check BIFS*/
 	default:
@@ -1451,7 +1458,7 @@
 		break;
 	default:
 		ent->mediaRate = 1;
-		ent->mediaTime = MediaTime;
+		ent->mediaTime = 3600; // required for QuickTime compatibility >.<
 		break;
 	}
 	gf_list_add(trak->editBox->editList->entryList, ent);
Index: src/isomedia/stbl_write.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/isomedia/stbl_write.c,v
retrieving revision 1.25
diff -u -r1.25 stbl_write.c
--- src/isomedia/stbl_write.c	9 Apr 2010 12:22:47 -0000	1.25
+++ src/isomedia/stbl_write.c	10 Apr 2010 13:36:47 -0000
@@ -18,7 +18,7 @@
  *   
  *  You should have received a copy of the GNU Lesser General Public
  *  License along with this library; see the file COPYING.  If not, write to
- *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 021839, USA. 
  *
  */
 
@@ -32,6 +32,60 @@
 
 #ifndef GPAC_DISABLE_ISOM_WRITE
 
+GF_ChunkLargeOffsetBox *stco_to_co64(GF_ChunkOffsetBox *stco, u32 alloc_size);
+GF_Err stbl_ShiftOffset(GF_Box **a, u64 offset, u32 start, u32 end);
+
+GF_ChunkLargeOffsetBox *stco_to_co64(GF_ChunkOffsetBox *stco, u32 alloc_size)
+{
+	u32 i;
+	GF_ChunkLargeOffsetBox *co64;
+	if (stco->nb_entries > alloc_size) alloc_size = stco->nb_entries;
+//	if (stco->alloc_size > alloc_size) alloc_size = stco->alloc_size;
+	co64 = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
+	if (co64==NULL) return NULL;
+	co64->offsets = (u64*)gf_malloc(alloc_size * sizeof(u64));
+	if (co64->offsets==NULL) {
+		gf_isom_box_del((GF_Box *)co64);
+		return NULL;
+	}
+	for (i=0;i<stco->nb_entries; i++) {
+//	for (i=0;i<stco->alloc_size; i++) {
+		co64->offsets[i] = (u64)stco->offsets[i];
+	}
+	co64->nb_entries = stco->nb_entries;
+    co64->alloc_size = alloc_size;
+	gf_isom_box_del((GF_Box *)stco);
+	return co64;
+}
+
+GF_Err stbl_ShiftOffset(GF_Box **a, u64 offset, u32 start, u32 end)
+{
+	u32 k;
+	GF_ChunkOffsetBox *stco;
+	GF_ChunkLargeOffsetBox *co64;
+restart:
+	if ((*a)->type == GF_ISOM_BOX_TYPE_STCO) {
+		stco = (GF_ChunkOffsetBox *) *a;
+		for (k = start; k < end; k++) {
+//			if (1){  // DEBUG
+			if (stco->offsets[k-1] + offset > 0xFFFFFFFF) {
+				co64 = stco_to_co64((GF_ChunkOffsetBox *) *a, 0);
+				if (!co64) return GF_OUT_OF_MEM;
+				*a = (GF_Box *)co64;
+				start = k;
+				goto restart;
+			}
+			stco->offsets[k-1] += (u32) offset;
+		}
+	} else {
+		co64 = (GF_ChunkLargeOffsetBox *) *a;
+		for (k = start; k < end; k++) {
+			co64->offsets[k-1] += offset;
+		}
+	}
+	return GF_OK;
+}
+
 //adds a DTS in the table and get the sample number of this new sample
 //we could return an error if a sample with the same DTS already exists
 //but this is not true for QT or MJ2K, only for MP4...
@@ -510,29 +564,18 @@
 
 	if (stsc->nb_entries + 1 < sampleNumber ) return GF_BAD_PARAM;
 
-	//add the offset to the chunk...
-	//and we change our offset
 	if (stbl->ChunkOffset->type == GF_ISOM_BOX_TYPE_STCO) {
-		stco = (GF_ChunkOffsetBox *)stbl->ChunkOffset;
-		//if the new offset is a large one, we have to rewrite our table entry by entry (32->64 bit conv)...
 		if (offset > 0xFFFFFFFF) {
-			co64 = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
-			co64->nb_entries = stco->nb_entries + 1;
-			co64->alloc_size = co64->nb_entries;
-			co64->offsets = (u64*)gf_malloc(sizeof(u64) * co64->nb_entries);
-			if (!co64->offsets) return GF_OUT_OF_MEM;
-			k = 0;
-			for (i=0;i<stco->nb_entries; i++) {
-				if (i + 1 == sampleNumber) {
-					co64->offsets[i] = offset;
-					k = 1;
+			co64 = stco_to_co64((GF_ChunkOffsetBox *)stbl->ChunkOffset, 0);
+			if (!co64) return GF_OUT_OF_MEM;
+			stbl->ChunkOffset = (GF_Box *)co64;
 				}
-				co64->offsets[i+k] = (u64) stco->offsets[i];
 			}
-			if (!k) co64->offsets[co64->nb_entries - 1] = offset;
-			gf_isom_box_del(stbl->ChunkOffset);
-			stbl->ChunkOffset = (GF_Box *) co64;
-		} else {
+
+	//add the offset to the chunk...
+	//and we change our offset
+	if (stbl->ChunkOffset->type == GF_ISOM_BOX_TYPE_STCO) {
+		stco = (GF_ChunkOffsetBox *)stbl->ChunkOffset;
 			//no, we can use this one.
 			if (sampleNumber > stco->nb_entries) {
 				if (!stco->alloc_size) stco->alloc_size = stco->nb_entries;
@@ -560,7 +603,6 @@
 				stco->nb_entries ++;
 				stco->alloc_size = stco->nb_entries;
 			}
-		}
 	} else {
 		//use large offset...
 		co64 = (GF_ChunkLargeOffsetBox *)stbl->ChunkOffset;
@@ -637,7 +679,6 @@
 GF_Err stbl_SetChunkOffset(GF_MediaBox *mdia, u32 sampleNumber, u64 offset)
 {
 	GF_StscEntry *ent;
-	u32 i;
 	GF_ChunkLargeOffsetBox *co64;
 	GF_SampleTableBox *stbl = mdia->information->sampleTable;
 
@@ -649,23 +690,16 @@
 	if (Media_IsSelfContained(mdia, ent->sampleDescriptionIndex))
 		ent->isEdited = 1;
 
-	//and we change our offset
 	if (stbl->ChunkOffset->type == GF_ISOM_BOX_TYPE_STCO) {
-		//if the new offset is a large one, we have to rewrite our table...
 		if (offset > 0xFFFFFFFF) {
-			co64 = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
-			co64->nb_entries = ((GF_ChunkOffsetBox *)stbl->ChunkOffset)->nb_entries;
-			co64->alloc_size = co64->nb_entries;
-			co64->offsets = (u64*)gf_malloc(sizeof(u64)*co64->nb_entries);
-			if (!co64->offsets) return GF_OUT_OF_MEM;
-			for (i=0;i<co64->nb_entries; i++) {
-				co64->offsets[i] = (u64) ((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets[i];
+			co64 = stco_to_co64((GF_ChunkOffsetBox *)stbl->ChunkOffset, 0);
+			if (!co64) return GF_OUT_OF_MEM;
+			stbl->ChunkOffset = (GF_Box *)co64;
 			}
-			co64->offsets[ent->firstChunk - 1] = offset;
-			gf_isom_box_del(stbl->ChunkOffset);
-			stbl->ChunkOffset = (GF_Box *) co64;
-			return GF_OK;
 		}
+
+	//and we change our offset
+	if (stbl->ChunkOffset->type == GF_ISOM_BOX_TYPE_STCO) {
 		((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets[ent->firstChunk - 1] = (u32) offset;
 	} else {
 		((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->offsets[ent->firstChunk - 1] = offset;
@@ -1284,22 +1318,18 @@
 	u32 *new_offsets, i;
 	u64 *off_64;
 
+	if (stbl->ChunkOffset->type == GF_ISOM_BOX_TYPE_STCO) {
+		if (offset > 0xFFFFFFFF) {
+			co64 = stco_to_co64((GF_ChunkOffsetBox *)stbl->ChunkOffset, 0);
+			if (!co64) return; // !!!!error!!!!
+			stbl->ChunkOffset = (GF_Box *)co64;
+		}
+	}
+
 	//we may have to convert the table...
 	if (stbl->ChunkOffset->type==GF_ISOM_BOX_TYPE_STCO) {
 		stco = (GF_ChunkOffsetBox *)stbl->ChunkOffset;
 
-		if (offset>0xFFFFFFFF) {
-			co64 = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
-			co64->nb_entries = stco->nb_entries + 1;
-			co64->alloc_size = co64->nb_entries;
-			co64->offsets = (u64*)gf_malloc(sizeof(u64) * co64->nb_entries);
-			if (!co64->offsets) return;
-			for (i=0; i<stco->nb_entries; i++) co64->offsets[i] = stco->offsets[i];
-			co64->offsets[i] = offset;
-			gf_isom_box_del(stbl->ChunkOffset);
-			stbl->ChunkOffset = (GF_Box *) co64;
-			return;
-		}
 		//we're fine
 		new_offsets = (u32*)gf_malloc(sizeof(u32)*(stco->nb_entries+1));
 		if (!new_offsets) return;
@@ -1491,13 +1521,12 @@
 		stco_tmp = NULL;
 		co64_tmp = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
 		if (!co64_tmp) return GF_OUT_OF_MEM;
-		co64_tmp->nb_entries = stbl->SampleSize->sampleCount;
-		co64_tmp->offsets = (u64*)gf_malloc(co64_tmp->nb_entries * sizeof(u64));
+		co64_tmp->nb_entries = co64_tmp->alloc_size = stbl->SampleSize->sampleCount;
+		co64_tmp->offsets = (u64*)gf_malloc(co64_tmp->alloc_size * sizeof(u64));
 		if (!co64_tmp->offsets) {
 			gf_isom_box_del((GF_Box*)co64_tmp);
 			return GF_OUT_OF_MEM;
 		}
-		co64_tmp->alloc_size = co64_tmp->nb_entries;
 	} else {
 		return GF_ISOM_INVALID_FILE;
 	}
@@ -1560,30 +1589,17 @@
 {
 	GF_ChunkOffsetBox *stco;
 	GF_ChunkLargeOffsetBox *co64;
-	u32 i;
 
 	if ((*a)->type == GF_ISOM_BOX_TYPE_STCO) {
-		stco = (GF_ChunkOffsetBox *) *a;
-		//if dataOffset is bigger than 0xFFFFFFFF, move to LARGE offset
 		if (offset > 0xFFFFFFFF) {
-			co64 = (GF_ChunkLargeOffsetBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_CO64);
+			co64 = stco_to_co64((GF_ChunkOffsetBox *)*a, 0);
 			if (!co64) return GF_OUT_OF_MEM;
-			co64->nb_entries = stco->nb_entries + 1;
-			co64->alloc_size = co64->nb_entries;
-			co64->offsets = (u64*)gf_malloc(co64->nb_entries * sizeof(u64));
-			if (!co64->offsets) {
-				gf_isom_box_del((GF_Box *)co64);
-				return GF_OUT_OF_MEM;
-			}
-			for (i = 0; i< co64->nb_entries - 1; i++) {
-				co64->offsets[i] = (u64) stco->offsets[i];
-			}
-			co64->offsets[i] = offset;
-			//delete the box...
-			gf_isom_box_del(*a);
 			*a = (GF_Box *)co64;
-			return GF_OK;
 		}
+	}
+
+	if ((*a)->type == GF_ISOM_BOX_TYPE_STCO) {
+		stco = (GF_ChunkOffsetBox *) *a;
 		//OK, stick with regular...
 		if (stco->nb_entries==stco->alloc_size) {
 			ALLOC_INC(stco->alloc_size);
Index: src/media_tools/av_parsers.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/media_tools/av_parsers.c,v
retrieving revision 1.47
diff -u -r1.47 av_parsers.c
--- src/media_tools/av_parsers.c	23 Feb 2010 16:24:19 -0000	1.47
+++ src/media_tools/av_parsers.c	10 Apr 2010 14:44:00 -0000
@@ -775,6 +775,7 @@
 	case 34: return "Layer-3";
 	case 35: return "DST";
 	case 36: return "ALS";
+	case 37: return "SLS";
 	default: return "Unknown";
 	}
 }
@@ -831,6 +832,8 @@
 	case 0x2D: return "High Efficiency AAC Profile @ Level 3";
 	case 0x2E: return "High Efficiency AAC Profile @ Level 4";
 	case 0x2F: return "High Efficiency AAC Profile @ Level 5";
+	case 0x3B: return "High Definition AAC Profile @ Level 1";
+	case 0x3C: return "ALS Simple Profile @ Level 1";
 	case 0xFE: return "Not part of MPEG-4 audio profiles";
 	case 0xFF: return "No audio capability required";
 	default: return "ISO Reserved / User Private";
@@ -845,7 +848,8 @@
 	case 2: /*AAC LC*/
 		if (cfg->nb_chan<=2) return (cfg->base_sr<=24000) ? 0x28 : 0x29; /*LC@L1 or LC@L2*/
 		return (cfg->base_sr<=48000) ? 0x2A : 0x2B; /*LC@L4 or LC@L5*/
-	case 5: /*HE-AAC*/
+	case 5: /*HE-AAC - SBR*/
+	case 29: /*HE-AAC - SBR+PS*/
 		if (cfg->nb_chan<=2) return (cfg->base_sr<=24000) ? 0x2C : 0x2D; /*HE@L2 or HE@L3*/
 		return (cfg->base_sr<=48000) ? 0x2E : 0x2F; /*HE@L4 or HE@L5*/
 	/*default to HQ*/
@@ -872,11 +876,19 @@
 	} else {
 		cfg->base_sr = GF_M4ASampleRates[cfg->base_sr_index];
 	}
-	cfg->nb_chan = gf_bs_read_int(bs, 4);
+	if (cfg->base_object_type==36) { // ALS
+		cfg->nb_chan = gf_bs_read_int(bs, 12);
+	} else {
+		cfg->nb_chan = gf_bs_read_int(bs, 4);
+	}
 	/*this is 7+1 channels*/
 	if (cfg->nb_chan==7) cfg->nb_chan=8;
 
-	if (cfg->base_object_type==5) {
+	if (cfg->base_object_type==5 || cfg->base_object_type==29) {
+		if (cfg->base_object_type==29) {
+			cfg->has_ps = 1;
+			cfg->nb_chan = 1;
+		}
 		cfg->has_sbr = 1;
 		cfg->sbr_sr_index = gf_bs_read_int(bs, 4);
 		if (cfg->sbr_sr_index == 0x0F) {
@@ -958,20 +970,29 @@
 		break;
 	}
 
-	if (size_known && (cfg->base_object_type != 5) && gf_bs_available(bs)>=2) {
+	if (size_known && (cfg->base_object_type != 5) && (cfg->base_object_type != 29)) {
+		while (gf_bs_available(bs)>=2) {
 		u32 sync = gf_bs_peek_bits(bs, 11, 0);
 		if (sync==0x2b7) {
 			gf_bs_read_int(bs, 11);
 			cfg->sbr_object_type = gf_bs_read_int(bs, 5);
 			cfg->has_sbr = gf_bs_read_int(bs, 1);
 			if (cfg->has_sbr) {
-				cfg->sbr_sr_index = gf_bs_read_int(bs, 4);
+					cfg->sbr_sr_index =	gf_bs_read_int(bs, 4);
 				if (cfg->sbr_sr_index == 0x0F) {
 					cfg->sbr_sr = gf_bs_read_int(bs, 24);
 				} else {
 					cfg->sbr_sr = GF_M4ASampleRates[cfg->sbr_sr_index];
 				}
 			}
+			} else if (sync == 0x548) {
+				gf_bs_read_int(bs, 11);
+				cfg->has_ps = gf_bs_read_int(bs, 1);
+				if (cfg->has_ps)
+					cfg->nb_chan = 1;
+			} else {
+				break;
+			}
 		}
 	}
 	cfg->audioPL = gf_m4a_get_profile(cfg);
@@ -1027,7 +1048,11 @@
 		gf_bs_write_int(bs, cfg->nb_chan, 4);
 	}
 
-	if (cfg->base_object_type==5) {
+	if (cfg->base_object_type==5 || cfg->base_object_type==29) {
+		if (cfg->base_object_type == 29) {
+			cfg->has_ps = 1;
+			cfg->nb_chan = 1;
+		}
 		cfg->has_sbr = 1;
 		gf_bs_write_int(bs, cfg->sbr_sr_index, 4);
 		if (cfg->sbr_sr_index == 0x0F) {
@@ -1066,7 +1091,7 @@
 	/*ER cfg - not supported*/
 
 	/*implicit sbr - not used yet*/
-	if (0 && (cfg->base_object_type != 5) ) {
+	if (0 && (cfg->base_object_type != 5 && cfg->base_object_type != 29) ) {
 		gf_bs_write_int(bs, 0x2b7, 11);
 		cfg->sbr_object_type = gf_bs_read_int(bs, 5);
 		cfg->has_sbr = gf_bs_read_int(bs, 1);
@@ -1946,6 +1971,91 @@
 		si->poc = field_poc[1];
 }
 
+s32 AVC_DecodeNAL(char *buf, u32 buf_size, char *rbsp_buf)
+{
+	int i;
+	u32 size;
+	char *tmp=gf_malloc(sizeof(char)*buf_size);
+
+	if(!tmp) return -1;
+
+	tmp[0] = buf[0];
+	size=1;
+	for(i=1;i<buf_size; i++ ) {
+		if(i+2<buf_size && (buf[i] == 0x00 && buf[i+1] == 0x00 && buf[i+2] == 0x03)) {
+			tmp[size++] = buf[i];
+			tmp[size++] = buf[i+1];
+			i += 2;
+		} else {
+			tmp[size++] = buf[i];
+		}
+	}
+
+	if(!rbsp_buf) {
+		gf_free(tmp);
+		return size;
+	}
+
+	memcpy(rbsp_buf, tmp, size);
+	gf_free(tmp);
+	return size;
+}
+
+s32 AVC_EncodeNAL(char *buf, u32 buf_size, char *rbsp_buf)
+{
+	int i;
+	u32 size, index;
+	char *tmp;
+
+	size = 0;
+	i = 0;
+	while(i<buf_size) {
+		if(i+2<buf_size && (buf[i] == 0x00 && buf[i+1] == 0x00 && buf[i+2] <= 0x03)) {
+			size += 3;
+			i += 2;
+			continue;
+		}
+		if((i == buf_size-1) && (buf[i-1] == 0x00 && buf[i] == 0x00)) {
+			size += 2;
+			i++;
+			continue;
+		}
+		size++;
+		i++;
+	}
+
+	if(!rbsp_buf)
+		return size;
+
+	tmp = gf_malloc(sizeof(char)*(size));
+	if(!tmp) return -1;
+
+	index = 0;
+	i = 0;
+	while(i<buf_size) {
+		assert(size>=index);
+		if(i+2<buf_size && (buf[i] == 0x00 && buf[i+1] == 0x00 && buf[i+2] <= 0x03)) {
+			tmp[index++] = buf[i];
+			tmp[index++] = buf[i+1];
+			tmp[index++] = 0x03;
+			i += 2;
+			continue;
+		}
+		if((i == buf_size-1) && (buf[i-1] == 0x00 && buf[i] == 0x00)) {
+			tmp[index++] = buf[i];
+			tmp[index++] = 0x03;
+			i++;
+			continue;
+		}
+		tmp[index++] = buf[i];
+		i++;
+	}
+
+	memcpy(rbsp_buf, tmp, size);
+	gf_free(tmp);
+	return size;
+}
+
 s32 AVC_ParseNALU(GF_BitStream *bs, u32 nal_hdr, AVCState *avc)
 {
 	u8 temp, idr_flag;
@@ -2184,6 +2294,164 @@
 }
 
 #ifndef GPAC_DISABLE_ISOM
+GF_Err AVC_ChangeColorProp(GF_AVCConfig *avcc, s32 fullrange, s32 vidformat, s32 colorprim, s32 transfer, s32 colmatrix)
+{
+	GF_BitStream *orig, *mod;
+	AVCState avc;
+	u32 i, bit_offset, flag;
+	s32 idx;
+	GF_AVCConfigSlot *slc;
+
+	memset(&avc, 0, sizeof(AVCState));
+
+	i=0;
+	while ((slc = (GF_AVCConfigSlot *)gf_list_enum(avcc->sequenceParameterSets, &i))) {
+		s32 rbsp_size, nal_size;
+		char *rbsp_buf = gf_malloc(sizeof(char)*slc->size);
+		/* SODB -> RBSP */
+		rbsp_size = AVC_DecodeNAL(slc->data, slc->size, rbsp_buf);
+		if(rbsp_size<=0) return GF_BAD_PARAM;
+		orig = gf_bs_new(rbsp_buf, rbsp_size, GF_BITSTREAM_READ);
+		/*skip NALU type*/
+		gf_bs_read_int(orig, 8);
+		idx = AVC_ReadSeqInfo(orig, &avc, 0, &bit_offset);
+		if (idx<0) {
+			gf_bs_del(orig);
+			continue;
+		}
+		mod = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
+		gf_bs_seek(orig, 0);
+
+		/*copy over till vui flag*/
+		while (bit_offset) {
+			flag = gf_bs_read_int(orig, 1);
+			gf_bs_write_int(mod, flag, 1);
+			bit_offset--;
+		}
+		/*check VUI*/
+		flag = gf_bs_read_int(orig, 1);
+		gf_bs_write_int(mod, 1, 1);
+		if (flag) { /* VUI found in input bitstream */
+			u32 flag2 = gf_bs_read_int(orig, 1); /*aspect_ratio_info_present_flag*/
+			gf_bs_write_int(mod, flag2, 1);      /*just copy*/
+			if (flag2) {
+				s32 aspect_ratio_idc = gf_bs_read_int(orig, 8); /*aspect_ratio_idc*/
+				gf_bs_write_int(mod, aspect_ratio_idc, 8);      /*just copy*/
+				if (aspect_ratio_idc == 255) {
+					u32 ar_n, ar_d;
+					ar_n = gf_bs_read_int(orig, 16); /*sar_width*/
+					gf_bs_write_int(mod, ar_n, 16);  /*just copy*/
+					ar_d = gf_bs_read_int(orig, 16); /*sar_height*/
+					gf_bs_write_int(mod, ar_d, 16);  /*just copy*/
+				}
+			}
+
+			/*overscan_info_present_flag */
+			flag2 = gf_bs_read_int(orig, 1);
+			gf_bs_write_int(mod, flag2, 1);
+			if(flag2) {
+				u32 flag3 = gf_bs_read_int(orig, 1);
+				gf_bs_write_int(mod, flag3, 1);
+			}
+		} else { /* no VUI in input bitstream, create one */
+			gf_bs_write_int(mod, 0, 1);     /*aspect_ratio_present_flag*/
+			gf_bs_write_int(mod, 0, 1);     /*overscan_info_present_flag*/
+		}
+
+		/*video signal type related flags */
+		{
+			u32 video_signal_type_present_flag  = 0;
+			u32 video_format                    = 5;
+			u32 video_full_range_flag           = 0;
+			u32 colour_description_present_flag = 0;
+			u32 colour_primaries                = 2;
+			u32 transfer_characteristics        = 2;
+			u32 matrix_coefficients             = 2;
+
+			/* read all video signal related flags first */
+			video_signal_type_present_flag = gf_bs_read_int(orig, 1);
+			if(video_signal_type_present_flag) {
+				video_format                    = gf_bs_read_int(orig, 3);
+				video_full_range_flag           = gf_bs_read_int(orig, 1);
+				colour_description_present_flag = gf_bs_read_int(orig, 1);
+				if(colour_description_present_flag) {
+					colour_primaries            = gf_bs_read_int(orig, 8);
+					transfer_characteristics    = gf_bs_read_int(orig, 8);
+					matrix_coefficients         = gf_bs_read_int(orig, 8);
+				}
+			}
+
+			/* correct the values of each flags, depending on those from input stream */
+			/* and those specified in command line                                     */
+			if(fullrange==0 && vidformat==5 && colorprim==2 && transfer==2 && colmatrix==2) {
+				video_signal_type_present_flag = 0; /* no signal */
+			} else {
+				video_signal_type_present_flag = 1;
+				video_format                   = (vidformat < 0 ? video_format          : vidformat);
+				video_full_range_flag          = (fullrange < 0 ? video_full_range_flag : fullrange);
+				if(colorprim==2 && transfer==2 && colmatrix==2) {
+					colour_description_present_flag = 0;
+				} else {
+					colour_description_present_flag = 1;
+					colour_primaries                = (colorprim < 0 ? colour_primaries         : colorprim);
+					transfer_characteristics        = (transfer  < 0 ? transfer_characteristics : transfer );
+					matrix_coefficients             = (colmatrix < 0 ? matrix_coefficients      : colmatrix);
+				}
+				if(colour_primaries==2 && transfer_characteristics==2 && matrix_coefficients==2) {
+					colour_description_present_flag = 0;
+					if(video_format==5 && video_full_range_flag==0)
+						video_signal_type_present_flag = 0;
+				}
+			}
+
+			/* write to output bitstream */
+			gf_bs_write_int(mod, video_signal_type_present_flag, 1);
+			if(video_signal_type_present_flag) {
+				gf_bs_write_int(mod, video_format, 3);
+				gf_bs_write_int(mod, video_full_range_flag, 1);
+				gf_bs_write_int(mod, colour_description_present_flag, 1);
+				if(colour_description_present_flag) {
+					gf_bs_write_int(mod, colour_primaries, 8);
+					gf_bs_write_int(mod, transfer_characteristics, 8);
+					gf_bs_write_int(mod, matrix_coefficients, 8);
+				}
+			}
+		}
+
+		if(!flag) {
+			/* no VUI in input bitstream, set all other flags to 0 */
+			gf_bs_write_int(mod, 0, 1);     /*chroma_location_info_present_flag */
+			gf_bs_write_int(mod, 0, 1);     /*timing_info_present_flag*/
+			gf_bs_write_int(mod, 0, 1);     /*nal_hrd_parameters_present*/
+			gf_bs_write_int(mod, 0, 1);     /*vcl_hrd_parameters_present*/
+			gf_bs_write_int(mod, 0, 1);     /*pic_struct_present*/
+			gf_bs_write_int(mod, 0, 1);     /*bitstream_restriction*/
+		}
+
+		/*finally copy over remaining*/
+		while (gf_bs_bits_available(orig)) {
+			flag = gf_bs_read_int(orig, 1);
+			gf_bs_write_int(mod, flag, 1);
+		}
+		gf_bs_align(mod);
+		gf_bs_del(orig);
+		gf_free(rbsp_buf);
+		rbsp_buf = NULL;
+		gf_free(slc->data);
+		slc->data = NULL;
+		gf_bs_get_content(mod, &rbsp_buf, &rbsp_size);
+		/* RBSP -> SODB */
+		nal_size = AVC_EncodeNAL(rbsp_buf, rbsp_size, NULL);
+		if(nal_size<=0) return GF_BAD_PARAM;
+		slc->data = (char*)gf_malloc(sizeof(char)*nal_size);
+		slc->size = AVC_EncodeNAL(rbsp_buf, rbsp_size, slc->data);
+		gf_bs_del(mod);
+	}
+	return GF_OK;
+}
+#endif
+
+#ifndef GPAC_DISABLE_ISOM
 GF_Err AVC_ChangePAR(GF_AVCConfig *avcc, s32 ar_n, s32 ar_d)
 {
 	GF_BitStream *orig, *mod;
@@ -2196,7 +2464,12 @@
 
 	i=0;
 	while ((slc = (GF_AVCConfigSlot *)gf_list_enum(avcc->sequenceParameterSets, &i))) {
-		orig = gf_bs_new(slc->data, slc->size, GF_BITSTREAM_READ);
+		s32 rbsp_size, nal_size;
+		char *rbsp_buf = gf_malloc(sizeof(char)*slc->size);
+		/* SODB -> RBSP */
+		rbsp_size = AVC_DecodeNAL(slc->data, slc->size, rbsp_buf);
+		if(rbsp_size<=0) return GF_BAD_PARAM;
+		orig = gf_bs_new(rbsp_buf, rbsp_size, GF_BITSTREAM_READ);
 		/*skip NALU type*/
 		gf_bs_read_int(orig, 8);
 		idx = AVC_ReadSeqInfo(orig, &avc, 0, &bit_offset);
@@ -2256,11 +2529,18 @@
 			flag = gf_bs_read_int(orig, 1);
 			gf_bs_write_int(mod, flag, 1);
 		}
+		gf_bs_align(mod);
 		gf_bs_del(orig);
+		gf_free(rbsp_buf);
+		rbsp_buf = NULL;
 		gf_free(slc->data);
 		slc->data = NULL;
-		gf_bs_get_content(mod, (char **) &slc->data, &flag);
-		slc->size = flag;
+		gf_bs_get_content(mod, &rbsp_buf, &rbsp_size);
+		/* RBSP -> SODB */
+		nal_size = AVC_EncodeNAL(rbsp_buf, rbsp_size, NULL);
+		if(nal_size<=0) return GF_BAD_PARAM;
+		slc->data = (char*)gf_malloc(sizeof(char)*nal_size);
+		slc->size = AVC_EncodeNAL(rbsp_buf, rbsp_size, slc->data);
 		gf_bs_del(mod);
 	}
 	return GF_OK;
Index: src/media_tools/isom_hinter.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/media_tools/isom_hinter.c,v
retrieving revision 1.34
diff -u -r1.34 isom_hinter.c
--- src/media_tools/isom_hinter.c	23 Feb 2010 16:24:19 -0000	1.34
+++ src/media_tools/isom_hinter.c	10 Apr 2010 14:44:41 -0000
@@ -333,6 +333,7 @@
 							break;
 						}
 					case GF_M4A_AAC_SBR:
+                    case GF_M4A_AAC_PS: 
 					case GF_M4A_AAC_LTP:
 					case GF_M4A_AAC_SCALABLE:
 					case GF_M4A_ER_AAC_LC:
Index: src/media_tools/isom_tools.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/media_tools/isom_tools.c,v
retrieving revision 1.32
diff -u -r1.32 isom_tools.c
--- src/media_tools/isom_tools.c	9 Apr 2010 15:36:43 -0000	1.32
+++ src/media_tools/isom_tools.c	9 Apr 2010 17:36:57 -0000
@@ -1075,7 +1075,7 @@
 		return esd;
 	}
 
-	if (subtype == GF_ISOM_SUBTYPE_AC3) {
+	if ((subtype == GF_ISOM_SUBTYPE_AC3) || (subtype == GF_ISOM_SUBTYPE_SAC3)) {
 		esd = gf_odf_desc_esd_new(0);
 		esd->slConfig->timestampResolution = gf_isom_get_media_timescale(mp4, track);
 		esd->ESID = gf_isom_get_track_id(mp4, track);
Index: src/media_tools/media_export.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/media_tools/media_export.c,v
retrieving revision 1.36
diff -u -r1.36 media_export.c
--- src/media_tools/media_export.c	23 Feb 2010 16:24:20 -0000	1.36
+++ src/media_tools/media_export.c	9 Apr 2010 19:24:00 -0000
@@ -287,6 +287,14 @@
 				strcpy(szEXT, ".theo");
 				gf_export_message(dumper, GF_OK, "Dumping Theora video sample%s", szNum);
 				break;
+			case 0xA3:
+				strcpy(szEXT, ".vc1");
+				gf_export_message(dumper, GF_OK, "Dumping VC-1 video sample%s", szNum);
+				break;
+			case 0xA4:
+				strcpy(szEXT, ".drc");
+				gf_export_message(dumper, GF_OK, "Dumping Dirac video sample%s", szNum);
+				break;
 			default:
 				strcpy(szEXT, ".raw");
 				gf_export_message(dumper, GF_OK, "Dumping Unknown video sample%s (OTI %d)", szNum, dcfg->objectTypeIndication);
@@ -308,9 +316,23 @@
 				gf_export_message(dumper, GF_OK, "Dumping MPEG-1/2 Audio (MP3) sample%s", szNum);
 				break;
 			case GPAC_OTI_MEDIA_OGG:
-				strcpy(szEXT, ".vorb");
+				strcpy(szEXT, ".ogg");
 				gf_export_message(dumper, GF_OK, "Dumping Vorbis audio sample%s", szNum);
 				break;
+			case 0xA5:
+				strcpy(szEXT, ".ac3");
+				gf_export_message(dumper, GF_OK, "Dumping AC-3 audio sample%s", szNum);
+				break;
+			case 0xA6:
+				strcpy(szEXT, ".eac3");
+				gf_export_message(dumper, GF_OK, "Dumping E-AC-3 audio sample%s", szNum);
+				break;
+			case 0xA9:
+            case 0xAA:
+            case 0xAB:
+				strcpy(szEXT, ".dts");
+				gf_export_message(dumper, GF_OK, "Dumping %s audio sample%s", (dcfg->objectTypeIndication==0xA9) ? "DTS" : (dcfg->objectTypeIndication==0xAA) ? "DTS-HD High Resolution" : "DTS-HD Master", szNum);
+				break;
 			default:
 				strcpy(szEXT, ".raw");
 				gf_export_message(dumper, GF_OK, "Dumping Unknown audio sample%s (OTI %d)", szNum, dcfg->objectTypeIndication);
@@ -352,10 +374,10 @@
 	} else if (m_stype==GF_ISOM_SUBTYPE_3GP_DIMS) {
 		gf_export_message(dumper, GF_OK, "Extracting DIMS sample%s", szNum);
 		strcpy(szEXT, ".dims");
-	} else if (m_stype==GF_ISOM_SUBTYPE_AC3) {
+	} else if ((m_stype==GF_ISOM_SUBTYPE_AC3) || (m_stype==GF_ISOM_SUBTYPE_SAC3)) {
 		gf_export_message(dumper, GF_OK, "Extracting AC3 sample%s", szNum);
 		strcpy(szEXT, ".ac3");
-	} else if ((m_stype==GF_ISOM_SUBTYPE_AVC_H264) || (m_stype==GF_ISOM_SUBTYPE_AVC2_H264) || (m_stype==GF_ISOM_SUBTYPE_SVC_H264) ) {
+	} else if ((m_stype==GF_ISOM_SUBTYPE_AVC_H264) || (m_stype==GF_ISOM_SUBTYPE_AVC2_H264) || (m_stype==GF_ISOM_SUBTYPE_SVC_H264)) {
 		strcpy(szEXT, ".h264");
 		gf_export_message(dumper, GF_OK, "Dumping MPEG-4 AVC-H264 Visual sample%s", szNum);
 	} else if (m_type==GF_ISOM_MEDIA_FLASH) {
@@ -636,6 +658,14 @@
 				gf_export_message(dumper, GF_OK, "Extracting Ogg video");
 				is_ogg = 1;
 				break;
+            case 0xA3:
+				strcpy(szEXT, ".vc1");
+				gf_export_message(dumper, GF_OK, "Extracting SMPTE VC-1 stream to vc1");
+				break;
+			case 0xA4:
+				strcpy(szEXT, ".drc");
+				gf_export_message(dumper, GF_OK, "Extracting Dirac stream to drc");
+				break;
 			default:
 				gf_odf_desc_del((GF_Descriptor *) dcfg);
 				return gf_export_message(dumper, GF_NOT_SUPPORTED, "Unknown media in track ID %d - use NHNT instead", dumper->trackID);
@@ -652,7 +682,7 @@
 				strcat(szName, ".aac");
 				is_aac = 1;
 				aac_type = dcfg->objectTypeIndication - GPAC_OTI_AUDIO_AAC_MPEG2_MP;
-				gf_export_message(dumper, GF_OK, "Extracting MPEG-2 AAC");
+				gf_export_message(dumper, GF_OK, "Extracting MPEG-2 AAC stream to aac");
 				break;
 			case GPAC_OTI_AUDIO_AAC_MPEG4:
 				dsi = dcfg->decoderSpecificInfo->data;
@@ -660,22 +690,22 @@
 				dsi_size = dcfg->decoderSpecificInfo->dataLength;
 				is_aac = 2;
 				strcat(szName, ".aac");
-				gf_export_message(dumper, GF_OK, "Extracting MPEG-4 AAC");
+				gf_export_message(dumper, GF_OK, "Extracting MPEG-4 AAC stream to aac");
 				break;
 			case GPAC_OTI_AUDIO_MPEG2_PART3:
 			case GPAC_OTI_AUDIO_MPEG1:
 				strcat(szName, ".mp3");
-				gf_export_message(dumper, GF_OK, "Extracting MPEG-1/2 Audio (MP3)");
+				gf_export_message(dumper, GF_OK, "Extracting MPEG-1/2 Audio stream to mp3");
 				break;
 			case GPAC_OTI_MEDIA_OGG:
 				strcat(szName, ".ogg");
 				is_ogg = 1;
-				gf_export_message(dumper, GF_OK, "Extracting Ogg audio");
+				gf_export_message(dumper, GF_OK, "Extracting Ogg audio stream to ogg");
 				break;
 			case GPAC_OTI_AUDIO_13K_VOICE:
 				strcat(szName, ".qcp"); qcp_type = 1;
 				memcpy(GUID, QCP_QCELP_GUID_1, sizeof(char)*16);
-				gf_export_message(dumper, GF_OK, "Extracting QCELP-13K (QCP file)");
+				gf_export_message(dumper, GF_OK, "Extracting QCELP-13K to qcp");
 				break;
 			case GPAC_OTI_AUDIO_EVRC_VOICE:
 				memcpy(GUID, QCP_EVRC_GUID, sizeof(char)*16);
@@ -687,6 +717,20 @@
 				memcpy(GUID, QCP_SMV_GUID, sizeof(char)*16);
 				if (dumper->flags & GF_EXPORT_PROBE_ONLY) dumper->flags |= GF_EXPORT_USE_QCP;
 				break;
+			case 0xA5:
+				strcpy(szEXT, ".ac3");
+				gf_export_message(dumper, GF_OK, "Extracting AC-3 stream to ac3");
+				break;
+			case 0xA6:
+				strcpy(szEXT, ".eac3");
+				gf_export_message(dumper, GF_OK, "Extracting E-AC-3 stream to eac3");
+				break;
+			case 0xA9:
+            case 0xAA:
+            case 0xAB:
+				strcpy(szEXT, ".dts");
+				gf_export_message(dumper, GF_OK, "Extracting %s stream to dts", (dcfg->objectTypeIndication==0xA9) ? "DTS" : (dcfg->objectTypeIndication==0xAA) ? "DTS-HD High Resolution" : "DTS-HD Master");
+				break;
 			case 0xD1: 
 				if (dcfg->decoderSpecificInfo && (dcfg->decoderSpecificInfo->dataLength==8)
 					&& !strnicmp(dcfg->decoderSpecificInfo->data, "pvmm", 4)) {
@@ -753,7 +797,7 @@
 		} else if (m_type==GF_ISOM_MEDIA_FLASH) {
 			gf_export_message(dumper, GF_OK, "Extracting Macromedia Flash Movie");
 			strcat(szName, ".swf");
-		} else if (m_stype==GF_ISOM_SUBTYPE_AC3) {
+		} else if ((m_stype==GF_ISOM_SUBTYPE_AC3) || (m_stype==GF_ISOM_SUBTYPE_SAC3)) {
 			gf_export_message(dumper, GF_OK, "Extracting AC3 Audio");
 			strcat(szName, ".ac3");
 		} else {
@@ -1090,7 +1134,8 @@
 	case IBM_FORMAT_MULAW: comp = "ibm_mulaw"; break;
 	case IBM_FORMAT_ALAW: comp = "ibm_alaw"; break;
 	case IBM_FORMAT_ADPCM: comp = "ibm_adpcm"; break;
-	case 0x55: comp = "mp3"; break;
+	case WAVE_FORMAT_MP3: comp = "mp3"; break;
+	case WAVE_FORMAT_AC3: comp = "ac3"; break;
 	default: comp = "raw"; break;
 	}
 	sprintf(szOutFile, "%s.%s", dumper->out_name, comp);
@@ -1396,7 +1441,7 @@
 	}
 	ext = (char *) gf_isom_get_filename(dumper->file);
 	if (ext) ext = strrchr(ext, '.');
-	sprintf(szName, "%s%s", dumper->out_name, ext ? ext : ".mp4");
+	sprintf(szName, "%s%s", dumper->out_name, ".mp4");
 
 	add_to_iod = 1;
 	mode = GF_ISOM_WRITE_EDIT;
@@ -1978,6 +2023,10 @@
 	case GF_M2TS_VIDEO_H264:
 		strcat(szFile, ".264");
 		gf_export_message(dumper, GF_OK, "Extracting MPEG-4 AVC/H264 Visual stream to h264");
+   	    break;
+	case GF_M2TS_VIDEO_VC1:
+		strcat(szFile, ".vc1");
+		gf_export_message(dumper, GF_OK, "Extracting SMPTE VC-1 Visual stream to vc1");
 		break;
 	default:
 		strcat(szFile, ".raw");
Index: src/media_tools/media_import.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/media_tools/media_import.c,v
retrieving revision 1.139
diff -u -r1.139 media_import.c
--- src/media_tools/media_import.c	9 Apr 2010 16:09:16 -0000	1.139
+++ src/media_tools/media_import.c	10 Apr 2010 15:05:24 -0000
@@ -487,6 +487,7 @@
 	GF_Err e;
 	Bool sync_frame;
 	u16 sr, sbr_sr, sbr_sr_idx, dts_inc;
+    u16 timescale; 
 	GF_BitStream *bs, *dsi;
 	ADTSHeader hdr;
 	GF_M4ADecSpecInfo acfg;
@@ -510,12 +511,13 @@
 
 	/*keep MPEG-2 AAC OTI even for HE-SBR (that's correct according to latest MPEG-4 audio spec)*/
 	oti = hdr.is_mp2 ? hdr.profile+GPAC_OTI_AUDIO_AAC_MPEG2_MP-1 : GPAC_OTI_AUDIO_AAC_MPEG4;
-	sr = GF_M4ASampleRates[hdr.sr_idx];
+	timescale = sr = GF_M4ASampleRates[hdr.sr_idx];
 
 	if (import->flags & GF_IMPORT_PROBE_ONLY) {
 		import->tk_info[0].track_num = 1;
 		import->tk_info[0].type = GF_ISOM_MEDIA_AUDIO;
-		import->tk_info[0].flags = GF_IMPORT_USE_DATAREF | GF_IMPORT_SBR_IMPLICIT | GF_IMPORT_SBR_EXPLICIT | GF_IMPORT_FORCE_MPEG4;
+		import->tk_info[0].flags = GF_IMPORT_USE_DATAREF | GF_IMPORT_SBR_IMPLICIT | GF_IMPORT_SBR_EXPLICIT | GF_IMPORT_PS_IMPLICIT | GF_IMPORT_PS_EXPLICIT | GF_IMPORT_FORCE_MPEG4;
+ 		import->nb_tracks = 1;
 		import->nb_tracks = 1;
 		import->tk_info[0].audio_info.sample_rate = sr;
 		import->tk_info[0].audio_info.nb_channels = hdr.nb_ch;
@@ -528,19 +530,35 @@
 
 	sbr_sr = sr;
 	sbr_sr_idx = hdr.sr_idx;
-	for (i=0; i<16; i++) {
-		if (GF_M4ASampleRates[i] == (u32) 2*sr) {
-			sbr_sr_idx = i;
-			sbr_sr = 2*sr;
-			break;
+	if ((import->flags & GF_IMPORT_OVSBR) == 0) {
+		for (i=0; i<16; i++) {
+			if (GF_M4ASampleRates[i] == (u32) 2*sr) {
+				sbr_sr_idx = i;
+				sbr_sr = 2*sr;
+				break;
+			}
 		}
 	}
+
+	if (import->flags & GF_IMPORT_OVSBR) 
+		timescale = 2*sr;
+
+	if (import->flags & GF_IMPORT_PS_EXPLICIT) {
+		import->flags &= ~GF_IMPORT_PS_IMPLICIT;
+		import->flags |= GF_IMPORT_SBR_EXPLICIT;
+		import->flags &= ~GF_IMPORT_SBR_IMPLICIT;
+	}
+
 	/*no provision for explicit indication of MPEG-2 AAC through MPEG-4 PLs, so force implicit*/
 	if (hdr.is_mp2) {
 		if (import->flags & GF_IMPORT_SBR_EXPLICIT) {
 			import->flags &= ~GF_IMPORT_SBR_EXPLICIT;
 			import->flags |= GF_IMPORT_SBR_IMPLICIT;
 		}
+		if (import->flags & GF_IMPORT_PS_EXPLICIT) {
+			import->flags &= ~GF_IMPORT_PS_EXPLICIT;
+			import->flags |= GF_IMPORT_PS_IMPLICIT;
+		}
 	}
 
 	dts_inc = 1024;
@@ -561,9 +579,21 @@
 	} else if (import->flags & GF_IMPORT_SBR_IMPLICIT) {
 		acfg.has_sbr = 1;
 	}
+	if (import->flags & GF_IMPORT_PS_EXPLICIT) {
+		acfg.has_ps = 1;
+		acfg.base_object_type = 29;
+	} else if (import->flags & GF_IMPORT_PS_IMPLICIT) {
+		acfg.has_ps = 1;
+	}
 	acfg.audioPL = gf_m4a_get_profile(&acfg);
-	/*explicit SBR signal (non backward-compatible)*/
-	if (import->flags & GF_IMPORT_SBR_EXPLICIT) {
+	/*explicit SBR or PS signal (non backward-compatible)*/
+	if (import->flags & GF_IMPORT_PS_EXPLICIT) {
+		gf_bs_write_int(dsi, 29, 5);
+		gf_bs_write_int(dsi, hdr.sr_idx, 4);
+		gf_bs_write_int(dsi, hdr.nb_ch, 4);
+		gf_bs_write_int(dsi, sbr_sr ? sbr_sr_idx : hdr.sr_idx, 4);
+		gf_bs_write_int(dsi, hdr.profile, 5);
+	} else if (import->flags & GF_IMPORT_SBR_EXPLICIT) {
 		gf_bs_write_int(dsi, 5, 5);
 		gf_bs_write_int(dsi, hdr.sr_idx, 4);
 		gf_bs_write_int(dsi, hdr.nb_ch, 4);
@@ -582,6 +612,10 @@
 			gf_bs_write_int(dsi, 1, 1);	/*SBR present flag*/
 			gf_bs_write_int(dsi, sbr_sr_idx, 4);
 		}
+		if (import->flags & GF_IMPORT_PS_IMPLICIT) {
+			gf_bs_write_int(dsi, 0x548, 11); /*sync extension type*/
+			gf_bs_write_int(dsi, 1, 1);	/* PS present flag */
+		}
 	}
 	/*not MPEG4 tool*/
 	if (0 && hdr.is_mp2) acfg.audioPL = 0xFE;
@@ -600,16 +634,23 @@
 	import->esd->decoderConfig->streamType = GF_STREAM_AUDIO;
 	import->esd->decoderConfig->objectTypeIndication = oti;
 	import->esd->decoderConfig->bufferSizeDB = 20;
-	import->esd->slConfig->timestampResolution = sr;
+	import->esd->slConfig->timestampResolution = timescale;
 	if (!import->esd->decoderConfig->decoderSpecificInfo) import->esd->decoderConfig->decoderSpecificInfo = (GF_DefaultDescriptor *) gf_odf_desc_new(GF_ODF_DSI_TAG);
 	if (import->esd->decoderConfig->decoderSpecificInfo->data) gf_free(import->esd->decoderConfig->decoderSpecificInfo->data);
 	gf_bs_get_content(dsi, &import->esd->decoderConfig->decoderSpecificInfo->data, &import->esd->decoderConfig->decoderSpecificInfo->dataLength);
 	gf_bs_del(dsi);
 
 	samp = NULL;
-	gf_import_message(import, GF_OK, "AAC import %s- sample rate %d - %s audio - %d channel%s", (import->flags & GF_IMPORT_SBR_IMPLICIT) ? "SBR (implicit) " : ((import->flags & GF_IMPORT_SBR_EXPLICIT) ? "SBR (explicit) " : ""), sr, (oti==GPAC_OTI_AUDIO_AAC_MPEG4) ? "MPEG-4" : "MPEG-2", hdr.nb_ch, (hdr.nb_ch>1) ? "s" : "");
+	gf_import_message(import, GF_OK, "AAC import %s%s%s- sample rate %d - %s audio - %d channel%s",
+		(import->flags & (GF_IMPORT_SBR_IMPLICIT|GF_IMPORT_SBR_EXPLICIT)) ? "SBR" : "",
+		(import->flags & (GF_IMPORT_PS_IMPLICIT|GF_IMPORT_PS_EXPLICIT)) ? "+PS" : "",
+		((import->flags & (GF_IMPORT_SBR_EXPLICIT|GF_IMPORT_PS_EXPLICIT)) ? " (explicit) " : " "),
+		sr,
+		(oti==0x40) ? "MPEG-4" : "MPEG-2",
+		hdr.nb_ch,
+		(hdr.nb_ch>1) ? "s" : "");
 
-	track = gf_isom_new_track(import->dest, import->esd->ESID, GF_ISOM_MEDIA_AUDIO, sr);
+	track = gf_isom_new_track(import->dest, import->esd->ESID, GF_ISOM_MEDIA_AUDIO, timescale);
 	if (!track) {
 		e = gf_isom_last_error(import->dest);
 		goto exit;
@@ -618,7 +659,7 @@
 	if (!import->esd->ESID) import->esd->ESID = gf_isom_get_track_id(import->dest, track);
 	import->final_trackID = import->esd->ESID;
 	gf_isom_new_mpeg4_description(import->dest, track, import->esd, (import->flags & GF_IMPORT_USE_DATAREF) ? import->in_name : NULL, NULL, &di);
-	gf_isom_set_audio_info(import->dest, track, di, sr, (hdr.nb_ch>2) ? 2 : hdr.nb_ch, 16);
+	gf_isom_set_audio_info(import->dest, track, di, timescale, (hdr.nb_ch>2) ? 2 : hdr.nb_ch, 16);
 
 	e = GF_OK;
 	/*add first sample*/
@@ -893,7 +934,12 @@
 		}
 		samp->DTS += dts_inc;
 		nb_samp++;
+		if (mpeg12) {
+			gf_set_progress("Importing M2V", done_size/1024, tot_size/1024);
+		}
+		else {
 		gf_set_progress("Importing M4V", done_size/1024, tot_size/1024);
+		}
 		done_size += samp->dataLength;
 		if (e) break;
 		if (duration && (samp->DTS > duration)) break;
@@ -903,8 +949,12 @@
 	/*final flush*/
 	if (ref_frame && has_cts_offset)
 		gf_isom_modify_cts_offset(import->dest, track, ref_frame, (1+b_frames)*dts_inc);
-
+	if (mpeg12) {
+		gf_set_progress("Importing M2V", nb_samp, nb_samp);
+	}
+	else {
 	gf_set_progress("Importing M4V", nb_samp, nb_samp);
+	}
 	if (has_cts_offset) {
 		gf_import_message(import, GF_OK, "Has B-Frames (%d max consecutive B-VOPs)", max_b);
 		gf_isom_set_cts_packing(import->dest, track, 0);
@@ -1031,6 +1081,7 @@
 		|| !stricmp(comp, "RMP4") /*Sigma - not tested*/
 		|| !stricmp(comp, "MP43") /*not tested*/
 		|| !stricmp(comp, "FMP4") /*not tested*/
+        || !stricmp(comp, "VP6F")  
 		) {
 		e = GF_OK;
 	}
@@ -1482,7 +1533,7 @@
 	u8 bps;
 	char lang[4];
 	const char *url, *urn;
-	Bool sbr, is_clone;
+	Bool sbr, ps, is_clone;
 	GF_ISOSample *samp;
 	GF_ESD *origin_esd;
 	GF_InitialObjectDescriptor *iod;
@@ -1522,6 +1573,7 @@
 	}
 	sbr = 0;
 	sbr_sr = 0;
+	ps = 0;
 	iod = (GF_InitialObjectDescriptor *) gf_isom_get_root_od(import->orig);
 	if (iod && (iod->tag != GF_ODF_IOD_TAG)) {
 		gf_odf_desc_del((GF_Descriptor *) iod);
@@ -1549,6 +1601,7 @@
 		bps = 16;
 		sr = ch = sbr_sr = 0;
 		sbr = 0;
+		ps = 0;
 		gf_isom_get_audio_info(import->orig, track_in, 1, &sr, &ch, &bps);
 #ifndef GPAC_DISABLE_AV_PARSERS
 		if (origin_esd && (origin_esd->decoderConfig->objectTypeIndication==GPAC_OTI_AUDIO_AAC_MPEG4)) {
@@ -1558,7 +1611,8 @@
 			if (dsi.has_sbr) sbr_sr = dsi.sbr_sr;
 			ch = dsi.nb_chan;
 			PL = dsi.audioPL;
-			sbr = dsi.has_sbr ? ((dsi.base_object_type==GF_M4A_AAC_SBR) ? 2 : 1) : 0;
+			sbr = dsi.has_sbr ? ((dsi.base_object_type==GF_M4A_AAC_SBR || dsi.base_object_type==GF_M4A_AAC_PS) ? 2 : 1) : 0;
+			ps = dsi.has_ps;
 		}
 #endif
 		gf_isom_set_pl_indication(import->dest, GF_ISOM_PL_AUDIO, PL);
@@ -1616,6 +1670,8 @@
 			case GF_ISOM_SUBTYPE_3GP_EVRC:
 			case GF_ISOM_SUBTYPE_3GP_QCELP:
 			case GF_ISOM_SUBTYPE_3GP_SMV:
+			case GF_ISOM_SUBTYPE_AC3: 
+			case GF_ISOM_SUBTYPE_SAC3:
 				break;
 			default:
 				switch (mtype) {
@@ -1653,7 +1709,9 @@
 	case GF_ISOM_MEDIA_AUDIO:
 	{
 		if (!is_clone) gf_isom_set_audio_info(import->dest, track, di, (sbr==2) ? sbr_sr : sr, (ch>1) ? 2 : 1, bps);
-		if (sbr) {
+		if (ps) {
+			gf_import_message(import, GF_OK, "IsoMedia import - track ID %d - HE-AACv2 (SR %d - SBR-SR %d - %d channels)", trackID, sr, sbr_sr, ch);
+		} else if (sbr) {
 			gf_import_message(import, GF_OK, "IsoMedia import - track ID %d - HE-AAC (SR %d - SBR-SR %d - %d channels)", trackID, sr, sbr_sr, ch);
 		} else {
 			gf_import_message(import, GF_OK, "IsoMedia import - track ID %d - Audio (SR %d - %d channels)", trackID, sr, ch);
@@ -3735,6 +3793,9 @@
 
 	while (gf_bs_available(bs)) {
 		u8 nal_hdr, skip_nal, is_subseq, add_sps;
+		char *rbsp_buf;
+		GF_BitStream *rbsp;
+		s32 rbsp_size;
 		nal_size = AVC_NextStartCode(bs);
 
 		if (nal_size>max_size) {
@@ -3770,7 +3831,12 @@
 			if (import->flags & GF_IMPORT_SVC_NONE) break;
 			is_subseq = 1;
 		case GF_AVC_NALU_SEQ_PARAM:
-			idx = AVC_ReadSeqInfo(bs, &avc, is_subseq, NULL);
+			rbsp_buf = gf_malloc(sizeof(char)*nal_size);
+			rbsp_size = AVC_DecodeNAL(buffer, nal_size, rbsp_buf);
+			if(rbsp_size<=0) return GF_BAD_PARAM;
+			rbsp = gf_bs_new(rbsp_buf, rbsp_size, GF_BITSTREAM_READ);
+			gf_bs_seek(rbsp, 1);
+			idx = AVC_ReadSeqInfo(rbsp, &avc, is_subseq, NULL);
 			if (idx<0) {
 				if (avc.sps[0].profile_idc) {
 					GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("Error parsing SeqInfo"));
@@ -3816,6 +3882,10 @@
 					if (sample_data) gf_bs_del(sample_data);
 					gf_odf_avc_cfg_del(avccfg);
 					avccfg = NULL;
+					gf_free(rbsp_buf);
+					rbsp_buf = NULL;
+					gf_bs_del(rbsp);
+					rbsp = NULL;
 					gf_odf_avc_cfg_del(svccfg);
 					svccfg = NULL;
 					gf_free(buffer);
@@ -5209,6 +5279,12 @@
 					import->tk_info[idx].lang = pes->lang;
 					import->nb_tracks++;
 					break;
+				case GF_M2TS_VIDEO_VC1:
+					import->tk_info[idx].media_type = GF_4CC('V','C','-','1');
+					import->tk_info[idx].type = GF_ISOM_MEDIA_VISUAL;
+					import->tk_info[idx].lang = pes->lang;
+					import->nb_tracks++;
+					break;
 				case GF_M2TS_AUDIO_MPEG1:
 					import->tk_info[idx].media_type = GF_4CC('M','P','G','1');
 					import->tk_info[idx].type = GF_ISOM_MEDIA_AUDIO;
@@ -5320,6 +5396,10 @@
 				oti = GPAC_OTI_VIDEO_AVC;
 				tsimp->avccfg = gf_odf_avc_cfg_new();
 				break;
+			case GF_M2TS_VIDEO_VC1:
+				mtype = GF_ISOM_MEDIA_VISUAL;
+				stype = GF_STREAM_VISUAL; oti = 0xA3;
+				break;
 			case GF_M2TS_AUDIO_MPEG1:
 				mtype = GF_ISOM_MEDIA_AUDIO;
 				stype = GF_STREAM_AUDIO; 
@@ -5504,10 +5584,11 @@
 				case GF_M2TS_VIDEO_MPEG1: gf_import_message(import, GF_OK, "MPEG-1 Video import (TS PID %d)", pck->stream->pid); break;
 				case GF_M2TS_VIDEO_MPEG2: gf_import_message(import, GF_OK, "MPEG-2 Video import (TS PID %d)", pck->stream->pid); break;
 				case GF_M2TS_VIDEO_MPEG4: gf_import_message(import, GF_OK, "MPEG-4 Video import (TS PID %d)", pck->stream->pid); break;
-				case GF_M2TS_VIDEO_H264: gf_import_message(import, GF_OK, "MPEG-4 AVC/H264 Video import (TS PID %d)", pck->stream->pid); break;
+				case GF_M2TS_VIDEO_H264:  gf_import_message(import, GF_OK, "MPEG-4 AVC/H264 Video import (TS PID %d)", pck->stream->pid); break;
+				case GF_M2TS_VIDEO_VC1:   gf_import_message(import, GF_OK, "SMPTE VC-1 Video import (TS PID %d)", pck->stream->pid); break;
 				case GF_M2TS_AUDIO_MPEG1: gf_import_message(import, GF_OK, "MPEG-1 Audio import - SampleRate %d Channels %d Language %s (TS PID %d)", pck->stream->aud_sr, pck->stream->aud_nb_ch, gf_4cc_to_str(pck->stream->lang), pck->stream->pid); break;
 				case GF_M2TS_AUDIO_MPEG2: gf_import_message(import, GF_OK, "MPEG-2 Audio import - SampleRate %d Channels %d Language %s (TS PID %d)", pck->stream->aud_sr, pck->stream->aud_nb_ch, gf_4cc_to_str(pck->stream->lang), pck->stream->pid); break;
-				case GF_M2TS_AUDIO_AAC: gf_import_message(import, GF_OK, "MPEG-4 AAC Audio import - SampleRate %d Channels %d Language %s (TS PID %d)", pck->stream->aud_sr, pck->stream->aud_nb_ch, gf_4cc_to_str(pck->stream->lang), pck->stream->pid); break;
+				case GF_M2TS_AUDIO_AAC:   gf_import_message(import, GF_OK, "MPEG-4 AAC Audio import - SampleRate %d Channels %d Language %s (TS PID %d)", pck->stream->aud_sr, pck->stream->aud_nb_ch, gf_4cc_to_str(pck->stream->lang), pck->stream->pid); break;
 				}
 
 				gf_isom_set_media_language(import->dest, tsimp->track, (char *) gf_4cc_to_str(pck->stream->lang)+1);
@@ -6137,7 +6218,6 @@
 	while (gf_ac3_parser_bs(bs, &hdr, 0)) {
 		samp->dataLength = hdr.framesize;
 
-
 		if (import->flags & GF_IMPORT_USE_DATAREF) {
 			e = gf_isom_add_sample_reference(import->dest, track, di, samp, gf_bs_get_position(bs) );
 			gf_bs_skip_bytes(bs, samp->dataLength);
@@ -6157,6 +6237,7 @@
 		done += samp->dataLength;
 		if (duration && (samp->DTS > duration)) break;
 		if (import->flags & GF_IMPORT_DO_ABORT) break;
+        if (done > tot_size) break;  
 	}
 	MP4T_RecomputeBitRate(import->dest, track);
 	gf_set_progress("Importing AC3", tot_size, tot_size);
@@ -6325,6 +6406,31 @@
 }
 
 GF_EXPORT
+GF_Err gf_media_change_colorprop(GF_ISOFile *file, u32 track, s32 fullrange, s32 vidformat, s32 colorprim, s32 transfer, s32 colmatrix)
+{
+	u32 tk_w, tk_h, stype;
+	GF_Err e;
+
+	e = gf_isom_get_visual_info(file, track, 1, &tk_w, &tk_h);
+	if (e) return e;
+
+	stype = gf_isom_get_media_subtype(file, track, 1);
+	if (stype==GF_ISOM_SUBTYPE_AVC_H264) {
+#ifndef GPAC_DISABLE_AV_PARSERS
+		GF_AVCConfig *avcc = gf_isom_avc_config_get(file, track, 1);
+		AVC_ChangeColorProp(avcc, fullrange, vidformat, colorprim, transfer, colmatrix);
+		e = gf_isom_avc_config_update(file, track, 1, avcc);
+		gf_odf_avc_cfg_del(avcc);
+		if (e) return e;
+#endif
+	} else {
+		return GF_BAD_PARAM;
+	}
+
+	return e;
+}
+
+GF_EXPORT
 GF_Err gf_media_change_par(GF_ISOFile *file, u32 track, s32 ar_num, s32 ar_den)
 {
 	u32 tk_w, tk_h, stype;
@@ -6375,7 +6481,7 @@
 
 
 GF_EXPORT
-GF_Err gf_media_change_pl(GF_ISOFile *file, u32 track, u32 profile, u32 level)
+GF_Err gf_media_change_pl(GF_ISOFile *file, u32 track, u32 profile, u32 compat, u32 level)
 {
 	u32 i, count, stype;
 	GF_Err e;
@@ -6392,11 +6498,13 @@
 
 	avcc = gf_isom_avc_config_get(file, track, 1);
 	if (level) avcc->AVCLevelIndication = level;
+	if (compat) avcc->profile_compatibility = compat;
 	if (profile) avcc->AVCProfileIndication = profile;
 	count = gf_list_count(avcc->sequenceParameterSets);
 	for (i=0; i<count; i++) {
 		GF_AVCConfigSlot *slc = gf_list_get(avcc->sequenceParameterSets, i);
 		if (profile) slc->data[1] = profile;
+		if (compat) slc->data[2]  = compat;
 		if (level) slc->data[3] = level;
 	}
 	e = gf_isom_avc_config_update(file, track, 1, avcc);
Index: src/utils/os_divers.c
===================================================================
RCS file: /cvsroot/gpac/gpac/src/utils/os_divers.c,v
retrieving revision 1.36
diff -u -r1.36 os_divers.c
--- src/utils/os_divers.c	1 Mar 2010 15:00:38 -0000	1.36
+++ src/utils/os_divers.c	9 Mar 2010 18:57:23 -0000
@@ -557,7 +557,7 @@
 {
 #if defined(_WIN32_WCE)
 	return (u64) ftell(fp);
-#elif defined(WIN32)
+#elif (defined(WIN32) || defined(__MINGW32__))
 	fpos_t pos;
 	if (fgetpos(fp, &pos))
 		return (u64) -1;
@@ -576,7 +576,7 @@
 {
 #if defined(_WIN32_WCE)
 	return (u64) fseek(fp, (s32) offset, whence);
-#elif defined(WIN32)
+#elif (defined(WIN32) || defined(__MINGW32__))
 	fpos_t pos;
 	if (whence == SEEK_CUR) {
 		fgetpos(fp, &pos);

