1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
|
///////////////////////////////////////////////////////////////////////////////
//
// 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.
// Portions created by David Byron are Copyright (C) 2010.
// All Rights Reserved.
//
// Contributors:
// Kona Blend, kona8lend@@gmail.com
// David Byron, dbyron@dbyron.com
//
///////////////////////////////////////////////////////////////////////////////
#include "util/impl.h"
namespace mp4v2 { namespace util {
///////////////////////////////////////////////////////////////////////////////
class TrackUtility : public Utility
{
private:
enum TrackLongAction {
LC_TRACK_WILDCARD = _LC_MAX,
LC_TRACK_ID,
LC_TRACK_INDEX,
LC_SAMPLE_WILDCARD,
LC_SAMPLE_ID,
LC_SAMPLE_INDEX,
LC_LIST,
LC_ENABLED,
LC_INMOVIE,
LC_INPREVIEW,
LC_LAYER,
LC_ALTGROUP,
LC_VOLUME,
LC_WIDTH,
LC_HEIGHT,
LC_LANGUAGE,
LC_HDLRNAME,
LC_UDTANAME,
LC_UDTANAME_R,
LC_COLR_PARMS,
LC_COLR_PARM_HD,
LC_COLR_PARM_SD,
LC_COLR_LIST,
LC_COLR_ADD,
LC_COLR_SET,
LC_COLR_REMOVE,
LC_PASP_PARMS,
LC_PASP_LIST,
LC_PASP_ADD,
LC_PASP_SET,
LC_PASP_REMOVE,
};
public:
TrackUtility( int, char** );
protected:
// delegates implementation
bool utility_option( int, bool& );
bool utility_job( JobContext& );
private:
bool actionList( JobContext& );
bool actionListSingle( JobContext&, uint16_t );
bool actionColorParameterList ( JobContext& );
bool actionColorParameterAdd ( JobContext& );
bool actionColorParameterSet ( JobContext& );
bool actionColorParameterRemove ( JobContext& );
bool actionPictureAspectRatioList ( JobContext& );
bool actionPictureAspectRatioAdd ( JobContext& );
bool actionPictureAspectRatioSet ( JobContext& );
bool actionPictureAspectRatioRemove ( JobContext& );
bool actionTrackModifierSet ( JobContext& );
bool actionTrackModifierRemove ( JobContext& );
private:
enum TrackMode {
TM_UNDEFINED,
TM_INDEX,
TM_ID,
TM_WILDCARD,
};
enum SampleMode {
SM_UNDEFINED,
SM_INDEX,
SM_ID,
SM_WILDCARD,
};
Group _actionGroup;
Group _parmGroup;
bool (TrackUtility::*_action)( JobContext& );
TrackMode _trackMode;
uint16_t _trackIndex;
uint32_t _trackId;
SampleMode _sampleMode;
uint16_t _sampleIndex;
uint32_t _sampleId;
qtff::ColorParameterBox::Item _colorParameterItem;
qtff::PictureAspectRatioBox::Item _pictureAspectRatioItem;
void (TrackModifier::*_actionTrackModifierSet_function)( const string& );
string _actionTrackModifierSet_name;
string _actionTrackModifierSet_value;
void (TrackModifier::*_actionTrackModifierRemove_function)();
string _actionTrackModifierRemove_name;
};
///////////////////////////////////////////////////////////////////////////////
string toStringTrackType( string );
///////////////////////////////////////////////////////////////////////////////
TrackUtility::TrackUtility( int argc, char** argv )
: Utility ( "mp4track", argc, argv )
, _actionGroup ( "ACTIONS" )
, _parmGroup ( "PARAMETERS" )
, _action ( NULL )
, _trackMode ( TM_UNDEFINED )
, _trackIndex ( 0 )
, _trackId ( MP4_INVALID_TRACK_ID )
, _sampleMode ( SM_UNDEFINED )
, _sampleIndex ( 0 )
, _sampleId ( MP4_INVALID_SAMPLE_ID )
{
// add standard options which make sense for this utility
_group.add( STD_OPTIMIZE );
_group.add( STD_DRYRUN );
_group.add( STD_KEEPGOING );
_group.add( STD_OVERWRITE );
_group.add( STD_FORCE );
_group.add( STD_QUIET );
_group.add( STD_DEBUG );
_group.add( STD_VERBOSE );
_group.add( STD_HELP );
_group.add( STD_VERSION );
_group.add( STD_VERSIONX );
_parmGroup.add( "track-any", false, LC_TRACK_WILDCARD, "act on any/all tracks" );
_parmGroup.add( "track-index", true, LC_TRACK_INDEX, "act on track index IDX", "IDX" );
_parmGroup.add( "track-id", true, LC_TRACK_ID, "act on track id ID", "ID" );
/*
_parmGroup.add( "sample-any", false, LC_SAMPLE_WILDCARD, "act on any sample (default)" );
_parmGroup.add( "sample-index", true, LC_SAMPLE_INDEX, "act on sample index IDX" );
_parmGroup.add( "sample-id", true, LC_SAMPLE_ID, "act on sample id ID" );
*/
_parmGroup.add( "colr-parms", true, LC_COLR_PARMS, "where CSV is IDX1,IDX2,IDX3", "CSV" );
_parmGroup.add( "colr-parm-hd", false, LC_COLR_PARM_HD, "equivalent to --colr-parms=1,1,1" );
_parmGroup.add( "colr-parm-sd", false, LC_COLR_PARM_SD, "equivalent to --colr-parms=6,1,6" );
_parmGroup.add( "pasp-parms", true, LC_PASP_PARMS, "where CSV is hSPACING,vSPACING", "CSV" );
_groups.push_back( &_parmGroup );
_actionGroup.add( "list", false, LC_LIST, "list all tracks in mp4" );
_actionGroup.add( "enabled", true, LC_ENABLED, "set trak.tkhd.flags (enabled bit)", "BOOL" );
_actionGroup.add( "inmovie", true, LC_INMOVIE, "set trak.tkhd.flags (inMovie bit)", "BOOL" );
_actionGroup.add( "inpreview", true, LC_INPREVIEW, "set trak.tkhd.flags (inPreview bit)", "BOOL" );
_actionGroup.add( "layer", true, LC_LAYER, "set trak.tkhd.layer", "NUM" );
_actionGroup.add( "altgroup", true, LC_ALTGROUP, "set trak.tkhd.alternate_group", "NUM" );
_actionGroup.add( "volume", true, LC_VOLUME, "set trak.tkhd.volume", "FLOAT" );
_actionGroup.add( "width", true, LC_WIDTH, "set trak.tkhd.width", "FLOAT" );
_actionGroup.add( "height", true, LC_HEIGHT, "set trak.tkhd.height", "FLOAT" );
_actionGroup.add( "language", true, LC_LANGUAGE, "set trak.mdia.mdhd.language", "CODE" );
_actionGroup.add( "hdlrname", true, LC_HDLRNAME, "set trak.mdia.hdlr.name", "STR" );
_actionGroup.add( "udtaname", true, LC_UDTANAME, "set trak.udta.name.value", "STR" );
_actionGroup.add( "udtaname-remove", false, LC_UDTANAME_R, "remove trak.udta.name atom" );
_actionGroup.add( "colr-list", false, LC_COLR_LIST, "list all colr-boxes in mp4" );
_actionGroup.add( "colr-add", false, LC_COLR_ADD, "add colr-box to a video track" );
_actionGroup.add( "colr-set", false, LC_COLR_SET, "set colr-box parms" );
_actionGroup.add( "colr-remove", false, LC_COLR_REMOVE, "remove colr-box from track" );
_actionGroup.add( "pasp-list", false, LC_PASP_LIST, "list all pasp-boxes in mp4" );
_actionGroup.add( "pasp-add", false, LC_PASP_ADD, "add pasp-box to a video track" );
_actionGroup.add( "pasp-set", false, LC_PASP_SET, "set pasp-box parms" );
_actionGroup.add( "pasp-remove", false, LC_PASP_REMOVE, "remove pasp-box from track" );
_groups.push_back( &_actionGroup );
_usage = "[OPTION]... [PARAMETERS]... ACTION file...";
_description =
// 79-cols, inclusive, max desired width
// |----------------------------------------------------------------------------|
"\nFor each mp4 file specified, perform the specified ACTION. An action must be"
"\nspecified. Some options are not applicable to some actions.";
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionColorParameterAdd( JobContext& job )
{
ostringstream oss;
oss << "adding colr-box(" << _colorParameterItem.convertToCSV() << ") -> " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
return herrf( "track not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
switch( _trackMode ) {
default:
case TM_INDEX:
if( qtff::ColorParameterBox::add( job.fileHandle, _trackIndex, _colorParameterItem ))
return herrf( "unable to add colr-box\n" );
break;
case TM_ID:
if( qtff::ColorParameterBox::add( job.fileHandle, _trackId, _colorParameterItem ))
return herrf( "unable to add colr-box\n" );
break;
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionColorParameterList( JobContext& job )
{
job.fileHandle = MP4Read( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for read: %s\n", job.file.c_str() );
ostringstream report;
const int widx = 3;
const int wid = 3;
const int wtype = 8;
const int wparm = 6;
const string sep = " ";
if( _jobCount == 0 ) {
report << setw(widx) << right << "IDX"
<< sep << setw(wid) << "ID"
<< sep << setw(wtype) << left << "TYPE"
<< sep << setw(wparm) << right << "PRIMRY"
<< sep << setw(wparm) << right << "XFERFN"
<< sep << setw(wparm) << right << "MATRIX"
<< sep << setw(0) << "FILE"
<< '\n';
report << setfill('-') << setw(70) << "" << setfill(' ') << '\n';
}
qtff::ColorParameterBox::ItemList itemList;
if( qtff::ColorParameterBox::list( job.fileHandle, itemList ))
return herrf( "unable to fetch list of colr-boxes" );
const qtff::ColorParameterBox::ItemList::size_type max = itemList.size();
for( qtff::ColorParameterBox::ItemList::size_type i = 0; i < max; i++ ) {
const qtff::ColorParameterBox::IndexedItem& xitem = itemList[i];
const char* type = MP4GetTrackType( job.fileHandle, xitem.trackId );
if( !type)
type = "unknown";
report << right << setw(widx) << xitem.trackIndex
<< sep << setw(wid) << xitem.trackId
<< sep << setw(wtype) << left << toStringTrackType( type )
<< sep << setw(wparm) << right << xitem.item.primariesIndex
<< sep << setw(wparm) << right << xitem.item.transferFunctionIndex
<< sep << setw(wparm) << right << xitem.item.matrixIndex;
if( i == 0 )
report << sep << setw(0) << job.file;
report << '\n';
}
verbose1f( "%s", report.str().c_str() );
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionColorParameterRemove( JobContext& job )
{
ostringstream oss;
oss << "removing colr-box from " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
case TM_WILDCARD:
oss << " (all tracks)";
break;
default:
return herrf( "track(s) not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
switch( _trackMode ) {
case TM_INDEX:
if( qtff::ColorParameterBox::remove( job.fileHandle, _trackIndex ))
return herrf( "unable to remove colr-box\n" );
break;
case TM_ID:
if( qtff::ColorParameterBox::remove( job.fileHandle, _trackId ))
return herrf( "unable to remove colr-box\n" );
break;
default:
case TM_WILDCARD:
{
qtff::ColorParameterBox::ItemList itemList;
if( qtff::ColorParameterBox::list( job.fileHandle, itemList ))
return herrf( "unable to fetch list of colr-boxes" );
_trackMode = TM_INDEX;
const qtff::ColorParameterBox::ItemList::size_type max = itemList.size();
for( qtff::ColorParameterBox::ItemList::size_type i = 0; i < max; i++ ) {
const qtff::ColorParameterBox::IndexedItem& xitem = itemList[i];
_trackIndex = xitem.trackIndex;
actionColorParameterRemove( job );
}
break;
}
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionColorParameterSet( JobContext& job )
{
ostringstream oss;
oss << "setting colr-box(" << _colorParameterItem.convertToCSV() << ") -> " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
return herrf( "track not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
switch( _trackMode ) {
default:
case TM_INDEX:
if( qtff::ColorParameterBox::set( job.fileHandle, _trackIndex, _colorParameterItem ))
return herrf( "unable to set colr-box\n" );
break;
case TM_ID:
if( qtff::ColorParameterBox::set( job.fileHandle, _trackId, _colorParameterItem ))
return herrf( "unable to set colr-box\n" );
break;
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionList( JobContext& job )
{
if( _jobTotal > 1 )
verbose1f( "file %u of %u: %s\n", _jobCount+1, _jobTotal, job.file.c_str() );
ostringstream report;
job.fileHandle = MP4Read( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for read: %s\n", job.file.c_str() );
switch( _trackMode ) {
case TM_INDEX:
return actionListSingle( job, _trackIndex );
case TM_ID:
return actionListSingle( job, MP4FindTrackIndex( job.fileHandle, _trackId ));
case TM_WILDCARD:
default:
{
bool result = SUCCESS;
const uint16_t trackc = static_cast<uint16_t>( MP4GetNumberOfTracks( job.fileHandle ));
for( uint16_t i = 0; i < trackc; i++ ) {
if( actionListSingle( job, i ))
result = FAILURE;
}
return result;
}
}
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionListSingle( JobContext& job, uint16_t index )
{
TrackModifier tm( job.fileHandle, index );
ostringstream report;
tm.dump( report, ( _jobTotal > 1 ? " " : "" ));
verbose1f( "%s", report.str().c_str() );
return false;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionPictureAspectRatioAdd( JobContext& job )
{
ostringstream oss;
oss << "adding pasp-box(" << _pictureAspectRatioItem.convertToCSV() << ") -> " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
return herrf( "track not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
switch( _trackMode ) {
default:
case TM_INDEX:
if( qtff::PictureAspectRatioBox::add( job.fileHandle, _trackIndex, _pictureAspectRatioItem ))
return herrf( "unable to add pasp-box\n" );
break;
case TM_ID:
if( qtff::PictureAspectRatioBox::add( job.fileHandle, _trackId, _pictureAspectRatioItem ))
return herrf( "unable to add pasp-box\n" );
break;
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionPictureAspectRatioList( JobContext& job )
{
job.fileHandle = MP4Read( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for read: %s\n", job.file.c_str() );
ostringstream report;
const int widx = 3;
const int wid = 3;
const int wtype = 8;
const int wparm = 6;
const string sep = " ";
if( _jobCount == 0 ) {
report << setw(widx) << right << "IDX"
<< sep << setw(wid) << "ID"
<< sep << setw(wtype) << left << "TYPE"
<< sep << setw(wparm) << right << "hSPACE"
<< sep << setw(wparm) << right << "vSPACE"
<< sep << setw(0) << "FILE"
<< '\n';
report << setfill('-') << setw(70) << "" << setfill(' ') << '\n';
}
qtff::PictureAspectRatioBox::ItemList itemList;
if( qtff::PictureAspectRatioBox::list( job.fileHandle, itemList ))
return herrf( "unable to fetch list of pasp-boxes" );
const qtff::PictureAspectRatioBox::ItemList::size_type max = itemList.size();
for( qtff::PictureAspectRatioBox::ItemList::size_type i = 0; i < max; i++ ) {
const qtff::PictureAspectRatioBox::IndexedItem& xitem = itemList[i];
const char* type = MP4GetTrackType( job.fileHandle, xitem.trackId );
if( !type)
type = "unknown";
report << right << setw(widx) << xitem.trackIndex
<< sep << setw(wid) << xitem.trackId
<< sep << setw(wtype) << left << toStringTrackType( type )
<< sep << setw(wparm) << right << xitem.item.hSpacing
<< sep << setw(wparm) << right << xitem.item.vSpacing;
if( i == 0 )
report << sep << setw(0) << job.file;
report << '\n';
}
verbose1f( "%s", report.str().c_str() );
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionPictureAspectRatioRemove( JobContext& job )
{
ostringstream oss;
oss << "removing pasp-box from " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
oss << " (all tracks)";
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
switch( _trackMode ) {
case TM_INDEX:
if( qtff::PictureAspectRatioBox::remove( job.fileHandle, _trackIndex ))
return herrf( "unable to remove pasp-box\n" );
break;
case TM_ID:
if( qtff::PictureAspectRatioBox::remove( job.fileHandle, _trackId ))
return herrf( "unable to remove pasp-box\n" );
break;
default:
case TM_WILDCARD:
{
qtff::PictureAspectRatioBox::ItemList itemList;
if( qtff::PictureAspectRatioBox::list( job.fileHandle, itemList ))
return herrf( "unable to fetch list of pasp-boxes" );
_trackMode = TM_INDEX;
const qtff::PictureAspectRatioBox::ItemList::size_type max = itemList.size();
for( qtff::PictureAspectRatioBox::ItemList::size_type i = 0; i < max; i++ ) {
const qtff::PictureAspectRatioBox::IndexedItem& xitem = itemList[i];
_trackIndex = xitem.trackIndex;
actionPictureAspectRatioRemove( job );
}
break;
}
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionPictureAspectRatioSet( JobContext& job )
{
ostringstream oss;
oss << "setting pasp-box(" << _pictureAspectRatioItem.convertToCSV() << ") -> " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
return herrf( "track not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
switch( _trackMode ) {
default:
case TM_INDEX:
if( qtff::PictureAspectRatioBox::set( job.fileHandle, _trackIndex, _pictureAspectRatioItem ))
return herrf( "unable to set pasp-box\n" );
break;
case TM_ID:
if( qtff::PictureAspectRatioBox::set( job.fileHandle, _trackId, _pictureAspectRatioItem ))
return herrf( "unable to set pasp-box\n" );
break;
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionTrackModifierRemove( JobContext& job )
{
ostringstream oss;
oss << "removing " << _actionTrackModifierRemove_name << " -> " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
return herrf( "track not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
if( _trackMode == TM_ID )
_trackIndex = MP4FindTrackIndex( job.fileHandle, _trackId );
TrackModifier tm( job.fileHandle, _trackIndex );
(tm.*_actionTrackModifierRemove_function)();
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::actionTrackModifierSet( JobContext& job )
{
ostringstream oss;
oss << "setting " << _actionTrackModifierSet_name << "=" << _actionTrackModifierSet_value << " -> " << job.file;
switch( _trackMode ) {
case TM_INDEX:
oss << " (track index=" << _trackIndex << ')';
break;
case TM_ID:
oss << " (track id=" << _trackId << ')';
break;
default:
case TM_WILDCARD:
return herrf( "track not specified\n" );
}
verbose1f( "%s\n", oss.str().c_str() );
if( dryrunAbort() )
return SUCCESS;
job.fileHandle = MP4Modify( job.file.c_str() );
if( job.fileHandle == MP4_INVALID_FILE_HANDLE )
return herrf( "unable to open for write: %s\n", job.file.c_str() );
if( _trackMode == TM_ID )
_trackIndex = MP4FindTrackIndex( job.fileHandle, _trackId );
TrackModifier tm( job.fileHandle, _trackIndex );
(tm.*_actionTrackModifierSet_function)( _actionTrackModifierSet_value );
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::utility_job( JobContext& job )
{
if( !_action )
return herrf( "no action specified\n" );
return (this->*_action)( job );
}
///////////////////////////////////////////////////////////////////////////////
bool
TrackUtility::utility_option( int code, bool& handled )
{
handled = true;
switch( code ) {
case LC_TRACK_WILDCARD:
_trackMode = TM_WILDCARD;
break;
case LC_TRACK_INDEX:
{
_trackMode = TM_INDEX;
istringstream iss( prog::optarg );
iss >> _trackIndex;
if( iss.rdstate() != ios::eofbit )
return herrf( "invalid track index: %s\n", prog::optarg );
break;
}
case LC_TRACK_ID:
{
_trackMode = TM_ID;
istringstream iss( prog::optarg );
iss >> _trackId;
if( iss.rdstate() != ios::eofbit )
return herrf( "invalid track id: %s\n", prog::optarg );
break;
}
case LC_LIST:
_action = &TrackUtility::actionList;
break;
case LC_COLR_PARMS:
_colorParameterItem.convertFromCSV( prog::optarg );
break;
case LC_COLR_PARM_HD:
_colorParameterItem.primariesIndex = 1;
_colorParameterItem.transferFunctionIndex = 1;
_colorParameterItem.matrixIndex = 1;
break;
case LC_COLR_PARM_SD:
_colorParameterItem.primariesIndex = 6;
_colorParameterItem.transferFunctionIndex = 1;
_colorParameterItem.matrixIndex = 6;
break;
case LC_COLR_LIST:
_action = &TrackUtility::actionColorParameterList;
break;
case LC_ENABLED:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setEnabled;
_actionTrackModifierSet_name = "enabled";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_INMOVIE:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setInMovie;
_actionTrackModifierSet_name = "inMovie";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_INPREVIEW:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setInPreview;
_actionTrackModifierSet_name = "inPreview";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_LAYER:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setLayer;
_actionTrackModifierSet_name = "layer";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_ALTGROUP:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setAlternateGroup;
_actionTrackModifierSet_name = "alternateGroup";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_VOLUME:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setVolume;
_actionTrackModifierSet_name = "volume";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_WIDTH:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setWidth;
_actionTrackModifierSet_name = "width";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_HEIGHT:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setHeight;
_actionTrackModifierSet_name = "height";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_LANGUAGE:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setLanguage;
_actionTrackModifierSet_name = "language";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_HDLRNAME:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setHandlerName;
_actionTrackModifierSet_name = "handlerName";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_UDTANAME:
_action = &TrackUtility::actionTrackModifierSet;
_actionTrackModifierSet_function = &TrackModifier::setUserDataName;
_actionTrackModifierSet_name = "userDataName";
_actionTrackModifierSet_value = prog::optarg;
break;
case LC_UDTANAME_R:
_action = &TrackUtility::actionTrackModifierRemove;
_actionTrackModifierRemove_function = &TrackModifier::removeUserDataName;
_actionTrackModifierRemove_name = "userDataName";
break;
case LC_COLR_ADD:
_action = &TrackUtility::actionColorParameterAdd;
break;
case LC_COLR_SET:
_action = &TrackUtility::actionColorParameterSet;
break;
case LC_COLR_REMOVE:
_action = &TrackUtility::actionColorParameterRemove;
break;
case LC_PASP_PARMS:
_pictureAspectRatioItem.convertFromCSV( prog::optarg );
break;
case LC_PASP_LIST:
_action = &TrackUtility::actionPictureAspectRatioList;
break;
case LC_PASP_ADD:
_action = &TrackUtility::actionPictureAspectRatioAdd;
break;
case LC_PASP_SET:
_action = &TrackUtility::actionPictureAspectRatioSet;
break;
case LC_PASP_REMOVE:
_action = &TrackUtility::actionPictureAspectRatioRemove;
break;
default:
handled = false;
break;
}
return SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
string
toStringTrackType( string code )
{
if( !code.compare( "vide" )) // 14496-12
return "video";
if( !code.compare( "soun" )) // 14496-12
return "audio";
if( !code.compare( "hint" )) // 14496-12
return "hint";
if( !code.compare( "text" )) // QTFF
return "text";
if( !code.compare( "tmcd" )) // QTFF
return "timecode";
if( !code.compare( "subt" )) // QTFF
return "subtitle";
return string( "(" ) + code + ")";
}
///////////////////////////////////////////////////////////////////////////////
}} // namespace mp4v2::util
///////////////////////////////////////////////////////////////////////////////
extern "C"
int main( int argc, char** argv )
{
mp4v2::util::TrackUtility util( argc, argv );
return util.process();
}
|