Beispiel #1
0
GF_EXPORT
GF_Err gf_beng_save_context(GF_BifsEngine *codec, char *  ctxFileName)
{
	u32	d_mode, do_enc;
	char szF[GF_MAX_PATH], *ext;
	GF_Err	e;

	/*check if we dump to BT, XMT or encode to MP4*/
	strcpy(szF, ctxFileName);
	ext = strrchr(szF, '.');
	d_mode = GF_SM_DUMP_BT;
	do_enc = 0;
	if (ext) {
		if (!stricmp(ext, ".xmt") || !stricmp(ext, ".xmta")) d_mode = GF_SM_DUMP_XMTA;
		else if (!stricmp(ext, ".mp4")) do_enc = 1;
		ext[0] = 0;
	}

	if (do_enc) {
		GF_ISOFile *mp4;
		strcat(szF, ".mp4");
		mp4 = gf_isom_open(szF, GF_ISOM_OPEN_WRITE, NULL);
		e = gf_sm_encode_to_file(codec->ctx, mp4, NULL);
		if (e) gf_isom_delete(mp4);
		else gf_isom_close(mp4);
	} else {
		e = gf_sm_dump(codec->ctx, szF, d_mode);
	}
	return e;
}
Beispiel #2
0
void V4SceneManager::SaveFile(const char *path) 
{
	GF_SMEncodeOptions opts;
	char rad_name[5000];

	/* First dump the scene in a BT file */
	strcpy(rad_name, "dump");
	m_pSm->scene_graph->RootNode = NULL;
	gf_sm_dump(m_pSm, rad_name, 0);

	/* Then reload properly (overriding the current SceneManager)*/
	GF_SceneLoader load;
	memset(&load, 0, sizeof(GF_SceneLoader));
	load.fileName = "dump.bt";
	load.ctx = m_pSm;
	gf_sm_load_init(&load);
	gf_sm_load_run(&load);
	gf_sm_load_done(&load);

	/* Finally encode the file */
	GF_ISOFile *mp4 = gf_isom_open(path, GF_ISOM_WRITE_EDIT, NULL);
	m_pSm->max_node_id = gf_sg_get_max_node_id(m_pSm->scene_graph);
	memset(&opts, 0, sizeof(opts));
	opts.flags = GF_SM_LOAD_MPEG4_STRICT;
	gf_sm_encode_to_file(m_pSm, mp4, &opts);
	gf_isom_set_brand_info(mp4, GF_ISOM_BRAND_MP42, 1);
	gf_isom_modify_alternate_brand(mp4, GF_ISOM_BRAND_ISOM, 1);
	gf_isom_close(mp4);
}
Beispiel #3
0
void V4SceneGraph::SaveFile(const char *path) 
{
	char rad_name[5000];
	strcpy(rad_name, "dump");
	gf_sm_dump(m_pSm, rad_name, 0);
	GF_ISOFile *mp4 = gf_isom_open(path, GF_ISOM_WRITE_EDIT, NULL);
	m_pSm->max_node_id = gf_sg_get_max_node_id(m_pSm->scene_graph);
	gf_sm_encode_to_file(m_pSm, mp4, "c:\\log.txt", NULL, GF_SM_LOAD_MPEG4_STRICT, 0);
	gf_isom_close(mp4);
}
Beispiel #4
0
GF_EXPORT
GF_Err gf_seng_save_context(GF_SceneEngine *seng, char *ctxFileName)
{
#ifdef GPAC_DISABLE_SCENE_DUMP
	return GF_NOT_SUPPORTED;
#else
	u32	d_mode, do_enc;
	char szF[GF_MAX_PATH], *ext;
	GF_Err	e;

	/*check if we dump to BT, XMT or encode to MP4*/
	ext = NULL;
	if (ctxFileName) {
		strcpy(szF, ctxFileName);
		ext = strrchr(szF, '.');
	}
	d_mode = GF_SM_DUMP_BT;
	do_enc = 0;
	if (ext) {
		if (!stricmp(ext, ".xmt") || !stricmp(ext, ".xmta")) d_mode = GF_SM_DUMP_XMTA;
		else if (!stricmp(ext, ".mp4")) do_enc = 1;
		ext[0] = 0;
	}

	if (do_enc) {
#ifndef GPAC_DISABLE_SCENE_ENCODER
		GF_ISOFile *mp4;
		strcat(szF, ".mp4");
		mp4 = gf_isom_open(szF, GF_ISOM_OPEN_WRITE, NULL);
		e = gf_sm_encode_to_file(seng->ctx, mp4, NULL);
		if (e) gf_isom_delete(mp4);
		else gf_isom_close(mp4);
#else
		return GF_NOT_SUPPORTED;
#endif
	} else {
		e = gf_sm_dump(seng->ctx, ctxFileName ? szF : NULL, d_mode);
	}
	return e;
#endif
}
Beispiel #5
0
GF_Err encode_laser(GF_LoadCompare *lc, char *item_path, GF_ISOFile *mp4, GF_SMEncodeOptions *opts) 
{
	GF_Err e = GF_OK;
	GF_SceneLoader load;
	GF_SceneManager *ctx;
	GF_SceneGraph *sg;
	GF_StatManager *statsman = NULL;

	memset(&load, 0, sizeof(GF_SceneLoader));
	sg = gf_sg_new();
	ctx = gf_sm_new(sg);
	load.ctx = ctx;
	load.fileName = item_path;

	e = gf_sm_load_init(&load);
	if (e) {
		fprintf(stderr, "Error loading file %s\n", item_path);
	} else {
		e = gf_sm_load_run(&load);
		if (e) {
			fprintf(stderr, "Error loading file %s\n", item_path);
		} else {
			if (opts->auto_qant) {
				if (lc->verbose) fprintf(stdout, "Analysing Scene for Automatic Quantization\n");
				statsman = gf_sm_stats_new();
				e = gf_sm_stats_for_scene(statsman, ctx);
				if (!e) {
					GF_SceneStatistics *stats = gf_sm_stats_get(statsman);
					if (opts->resolution > (s32)stats->frac_res_2d) {
						if (lc->verbose) fprintf(stdout, " Given resolution %d is (unnecessarily) too high, using %d instead.\n", opts->resolution, stats->frac_res_2d);
						opts->resolution = stats->frac_res_2d;
					} else if (stats->int_res_2d + opts->resolution <= 0) {
						if (lc->verbose) fprintf(stdout, " Given resolution %d is too low, using %d instead.\n", opts->resolution, stats->int_res_2d - 1);
						opts->resolution = 1 - stats->int_res_2d;
					}				
					opts->coord_bits = stats->int_res_2d + opts->resolution;
					if (lc->verbose) fprintf(stdout, " Coordinates & Lengths encoded using ");
					if (opts->resolution < 0) {
						if (lc->verbose) fprintf(stdout, "only the %d most significant bits (of %d).\n", opts->coord_bits, stats->int_res_2d);
					} else {
						if (lc->verbose) fprintf(stdout, "a %d.%d representation\n", stats->int_res_2d, opts->resolution);
					}

					if (lc->verbose) fprintf(stdout, " Matrix Scale & Skew Coefficients ");
					if (opts->coord_bits < stats->scale_int_res_2d) {
						opts->scale_bits = stats->scale_int_res_2d - opts->coord_bits;
						if (lc->verbose) fprintf(stdout, "encoded using a %d.8 representation\n", stats->scale_int_res_2d);
					} else  {
						opts->scale_bits = 0;
						if (lc->verbose) fprintf(stdout, "not encoded.\n");
					}
				}
				gf_sm_stats_del(statsman);
			}
			
			e = gf_sm_encode_to_file(ctx, mp4, opts);
			if (e) {
				fprintf(stderr, "Error while encoding mp4 file\n");
			} else {
				e = gf_isom_set_brand_info(mp4, GF_ISOM_BRAND_MP42, 1);
				if (!e) e = gf_isom_modify_alternate_brand(mp4, GF_ISOM_BRAND_ISOM, 1);
			}

			gf_sm_load_done(&load);
		}		
	}
	gf_sm_del(ctx);
	gf_sg_del(sg);

	return e;
}