Skip to content

Commit

Permalink
isobmf single track import now removes references by default - see #874
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Jul 17, 2017
1 parent e86edeb commit 867f5fa
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion applications/mp4box/fileimport.c
Expand Up @@ -368,6 +368,7 @@ GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double forc
else if (!stricmp(ext+1, "trailing")) import_flags |= GF_IMPORT_KEEP_TRAILING;
else if (!strnicmp(ext+1, "agg=", 4)) frames_per_sample = atoi(ext+5);
else if (!stricmp(ext+1, "dref")) import_flags |= GF_IMPORT_USE_DATAREF;
else if (!stricmp(ext+1, "keep_refs")) import_flags |= GF_IMPORT_KEEP_REFS;
else if (!stricmp(ext+1, "nodrop")) import_flags |= GF_IMPORT_NO_FRAME_DROP;
else if (!stricmp(ext+1, "packed")) import_flags |= GF_IMPORT_FORCE_PACKED;
else if (!stricmp(ext+1, "sbr")) import_flags |= GF_IMPORT_SBR_IMPLICIT;
Expand Down Expand Up @@ -741,6 +742,9 @@ GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double forc
}
}
} else {
if (do_all)
import.flags |= GF_IMPORT_KEEP_REFS;

for (i=0; i<import.nb_tracks; i++) {
import.trackID = import.tk_info[i].track_num;
if (prog_id) {
Expand Down Expand Up @@ -926,7 +930,7 @@ GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, Double forc
{
e = gf_isom_rewrite_track_dependencies(import.dest, i);
if (e) {
fprintf(stderr, "Warning: track ID %d has references to a track not imported\n", gf_isom_get_track_id(import.dest, i));
GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("Warning: track ID %d has references to a track not imported\n", gf_isom_get_track_id(import.dest, i) ));
e = GF_OK;
}
}
Expand Down
1 change: 1 addition & 0 deletions applications/mp4box/main.c
Expand Up @@ -493,6 +493,7 @@ void PrintImportUsage()
" \":trailing\" keeps trailing 0-bytes in AVC/HEVC samples\n"
" \":agg=VAL\" same as -agg option\n"
" \":dref\" same as -dref option\n"
" \":keep_refs\" keeps track reference when importing a single track\n"
" \":nodrop\" same as -nodrop option\n"
" \":packed\" same as -packed option\n"
" \":sbr\" same as -sbr option\n"
Expand Down
3 changes: 3 additions & 0 deletions include/gpac/isomedia.h
Expand Up @@ -1108,6 +1108,9 @@ GF_Err gf_isom_set_track_reference(GF_ISOFile *the_file, u32 trackNumber, u32 re
/*removes a track reference*/
GF_Err gf_isom_remove_track_reference(GF_ISOFile *the_file, u32 trackNumber, u32 referenceType, u32 ReferenceIndex);

/*removes all track references*/
GF_Err gf_isom_remove_track_references(GF_ISOFile *the_file, u32 trackNumber);

/*sets track handler name. name is either NULL (reset), a UTF-8 formatted string or a UTF8 file
resource in the form "file://path/to/file_utf8" */
GF_Err gf_isom_set_handler_name(GF_ISOFile *the_file, u32 trackNumber, const char *nameUTF8);
Expand Down
2 changes: 2 additions & 0 deletions include/gpac/media_tools.h
Expand Up @@ -192,6 +192,8 @@ enum
GF_IMPORT_NO_VPS_EXTENSIONS = 1<<25,
/*! when set no SEI messages are imported*/
GF_IMPORT_NO_SEI = 1<<26,
/*! keeps track references when importing a single track*/
GF_IMPORT_KEEP_REFS = 1<<27,

/*! when set by user during import, will abort*/
GF_IMPORT_DO_ABORT = 1<<31
Expand Down
1 change: 1 addition & 0 deletions src/export.cpp
Expand Up @@ -899,6 +899,7 @@
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_set_last_sample_duration) )
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_set_track_reference) )
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_remove_track_reference) )
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_remove_track_references) )
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_update_sample) )
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_update_sample_reference) )
#pragma comment (linker, EXPORT_SYMBOL(gf_isom_remove_sample) )
Expand Down
19 changes: 18 additions & 1 deletion src/isomedia/isom_write.c
Expand Up @@ -3214,7 +3214,6 @@ GF_Err gf_isom_remove_sample_description(GF_ISOFile *movie, u32 trackNumber, u32
return GF_OK;
}


//sets a track reference
GF_EXPORT
GF_Err gf_isom_set_track_reference(GF_ISOFile *the_file, u32 trackNumber, u32 referenceType, u32 ReferencedTrackID)
Expand Down Expand Up @@ -3294,6 +3293,24 @@ GF_Err gf_isom_remove_track_reference(GF_ISOFile *the_file, u32 trackNumber, u32
}


//sets a track reference
GF_EXPORT
GF_Err gf_isom_remove_track_references(GF_ISOFile *the_file, u32 trackNumber)
{
GF_TrackBox *trak;

trak = gf_isom_get_track_from_file(the_file, trackNumber);
if (!trak) return GF_BAD_PARAM;

if (trak->References) {
gf_isom_box_del((GF_Box *)trak->References);
trak->References = NULL;
}
return GF_OK;
}



//changes track ID
GF_EXPORT
GF_Err gf_isom_set_track_id(GF_ISOFile *movie, u32 trackNumber, u32 trackID)
Expand Down
3 changes: 3 additions & 0 deletions src/media_tools/media_import.c
Expand Up @@ -2147,6 +2147,9 @@ GF_Err gf_import_isomedia(GF_MediaImporter *import)
if (import->esd && import->esd->dependsOnESID) {
gf_isom_set_track_reference(import->dest, track, GF_ISOM_REF_DECODE, import->esd->dependsOnESID);
}
if (import->trackID && !(import->flags & GF_IMPORT_KEEP_REFS)) {
gf_isom_remove_track_references(import->dest, track);
}

mstype = gf_isom_get_media_subtype(import->orig, track_in, di);

Expand Down

1 comment on commit 867f5fa

@bilditup1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, thank you for this!

Please sign in to comment.