blob: aad58cb1768f7b17c5f35d3131388933706a5db4 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is MP4v2.
//
// The Initial Developer of the Original Code is Kona Blend.
// Portions created by Kona Blend are Copyright (C) 2008.
// All Rights Reserved.
//
// Contributors:
// Kona Blend, kona8lend@@gmail.com
//
///////////////////////////////////////////////////////////////////////////////
/* 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], MP4_DETAILS_ERROR, 0 );
if( file == MP4_INVALID_FILE_HANDLE ) {
printf( "MP4Modify failed\n" );
return 1;
}
/* show existing iTMF items */
MP4ItmfItemList* list = MP4ItmfGetItems( file );
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 */
MP4ItmfItemListFree( list );
}
/* 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->typeCode = MP4_ITMF_BT_UTF8;
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->typeCode = MP4_ITMF_BT_UTF8;
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 );
return 0;
}