MP4v2
example/itmf/generic.c
/* This is an example of iTMF Generic API.
* WARNING: this program will change/destroy certain tags in an mp4 file.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mp4v2/mp4v2.h>
int main( int argc, char** argv )
{
if( argc != 2 ) {
printf( "usage: %s file.mp4\n", argv[0] );
return 1;
}
/* open file for modification */
MP4FileHandle file = MP4Modify( argv[1], 0 );
if( file == MP4_INVALID_FILE_HANDLE ) {
printf( "MP4Modify failed\n" );
return 1;
}
/* show existing iTMF items */
printf( "list=%p\n", list );
if( list ) {
printf( "list size=%u\n", list->size );
uint32_t i;
for( i = 0; i < list->size; i++ ) {
MP4ItmfItem* item = &list->elements[i];
printf( "item[%u] type=%s\n", i, item->code );
if( item->mean )
printf( " mean=%s\n", item->mean );
if( item->name )
printf( " name=%s\n", item->name );
int j;
for( j = 0; j < item->dataList.size; j++ ) {
MP4ItmfData* data = &item->dataList.elements[j];
printf( " data[%u] typeCode=%u valueSize=%u\n", j, data->typeCode, data->valueSize );
}
}
/* caller responsiblity to free */
}
/* add bogus item to file */
{
/* allocate item with 1 data element */
MP4ItmfItem* bogus = MP4ItmfItemAlloc( "bogu", 1 );
const char* const hello = "hello one";
MP4ItmfData* data = &bogus->dataList.elements[0];
data->valueSize = strlen( hello );
data->value = (uint8_t*)malloc( data->valueSize );
memcpy( data->value, hello, data->valueSize );
/* add to mp4 file */
MP4ItmfAddItem( file, bogus );
/* caller responsibility to free */
MP4ItmfItemFree( bogus );
}
/* add bogus item with meaning and name to file */
{
/* allocate item with 1 data element */
MP4ItmfItem* bogus = MP4ItmfItemAlloc( "----", 1 );
bogus->mean = strdup( "com.garden.Tomato" );
bogus->name = strdup( "weight" );
const char* const hello = "hello two";
MP4ItmfData* data = &bogus->dataList.elements[0];
data->valueSize = strlen( hello );
data->value = (uint8_t*)malloc( data->valueSize );
memcpy( data->value, hello, data->valueSize );
/* add to mp4 file */
MP4ItmfAddItem( file, bogus );
/* caller responsibility to free */
MP4ItmfItemFree( bogus );
}
/* free memory associated with structure and close */
MP4Close( file, 0 );
return 0;
}
MP4ItmfData_s::typeCode
MP4ItmfBasicType typeCode
iTMF basic type.
Definition: itmf_generic.h:103
MP4ItmfItemList_s::size
uint32_t size
number of elements.
Definition: itmf_generic.h:133
MP4ItmfItem_s::code
char * code
four-char code identifing atom type.
Definition: itmf_generic.h:123
MP4_ITMF_BT_UTF8
@ MP4_ITMF_BT_UTF8
without any count or null terminator
Definition: itmf_generic.h:74
MP4ItmfItemList_s
List of items.
Definition: itmf_generic.h:130
MP4ItmfData_s
Data structure.
Definition: itmf_generic.h:100
MP4Close
void MP4Close(MP4FileHandle hFile, uint32_t flags=0)
Close an mp4 file.
MP4ItmfItemList_s::elements
MP4ItmfItem * elements
flat array.
Definition: itmf_generic.h:132
MP4ItmfItemAlloc
MP4ItmfItem * MP4ItmfItemAlloc(const char *code, uint32_t numData)
Allocate an item on the heap.
MP4ItmfDataList_s::elements
MP4ItmfData * elements
flat array.
Definition: itmf_generic.h:112
MP4ItmfData_s::value
uint8_t * value
may be NULL.
Definition: itmf_generic.h:105
MP4_INVALID_FILE_HANDLE
#define MP4_INVALID_FILE_HANDLE
Constant: invalid MP4FileHandle.
Definition: general.h:48
MP4ItmfItem_s
Item structure.
Definition: itmf_generic.h:119
MP4ItmfItemFree
void MP4ItmfItemFree(MP4ItmfItem *item)
Free an item (deep free).
MP4ItmfData_s::valueSize
uint32_t valueSize
value size in bytes.
Definition: itmf_generic.h:106
MP4ItmfAddItem
bool MP4ItmfAddItem(MP4FileHandle hFile, const MP4ItmfItem *item)
Add an item to file.
MP4ItmfItem_s::mean
char * mean
may be NULL.
Definition: itmf_generic.h:124
MP4ItmfDataList_s::size
uint32_t size
number of elements.
Definition: itmf_generic.h:113
MP4ItmfGetItems
MP4ItmfItemList * MP4ItmfGetItems(MP4FileHandle hFile)
Get list of all items from file.
MP4Modify
MP4FileHandle MP4Modify(const char *fileName, uint32_t flags=0)
Modify an existing mp4 file.
MP4ItmfItemListFree
void MP4ItmfItemListFree(MP4ItmfItemList *itemList)
Free an item list (deep free).
MP4ItmfItem_s::name
char * name
may be NULL.
Definition: itmf_generic.h:125
MP4ItmfItem_s::dataList
MP4ItmfDataList dataList
list of data.
Definition: itmf_generic.h:126