Changeset 311
- Timestamp:
- 01/28/07 00:44:15 (2 years ago)
- Files:
-
- trunk/MatroskaImportPrivate.cpp (modified) (1 diff)
- trunk/SSADocument.m (modified) (6 diffs)
- trunk/SubImport.c (modified) (5 diffs)
- trunk/SubImport.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/MatroskaImportPrivate.cpp
r310 r311 456 456 457 457 } else if ((*imgDesc)->cType == kSubFormatUTF8) { 458 mkvTrack.theTrack = CreatePlaintextSubTrack(theMovie, imgDesc, GetMovieTimeScale(theMovie), dataRef, dataRefType, kSubFormatUTF8); 458 Rect movieBox; 459 GetMovieBox(theMovie,&movieBox); 460 mkvTrack.theTrack = CreatePlaintextSubTrack(theMovie, imgDesc, GetMovieTimeScale(theMovie), dataRef, dataRefType, kSubFormatUTF8, NULL, movieBox); 459 461 if (mkvTrack.theTrack == NULL) 460 462 return GetMoviesError(); trunk/SSADocument.m
r310 r311 473 473 @end 474 474 475 //based on Apple sample code http://developer.apple.com/samplecode/QTKitCreateMovie/listing5.html 476 477 static Movie CreateQuicktimeMovieFromTempFile(DataHandler * outDataHandler, OSErr *outErr, NSString **movieName) 478 { 479 *outErr = -1; 480 char *c_tempName = tempnam(NULL,"perian-subtitle-"); 481 482 // generate a name for our movie file 483 NSString *tempName = [NSString stringWithCString:c_tempName 484 encoding:[NSString defaultCStringEncoding]]; 485 if (nil == tempName) goto nostring; 486 free(c_tempName); 487 488 Handle dataRefH = nil; 489 OSType dataRefType; 490 491 // create a file data reference for our movie 492 *outErr = QTNewDataReferenceFromFullPathCFString((CFStringRef)tempName, 493 kQTNativeDefaultPathStyle, 494 0, 495 &dataRefH, 496 &dataRefType); 497 if (*outErr != noErr) goto nodataref; 498 499 // create a QuickTime movie from our file data reference 500 Movie qtMovie = nil; 501 CreateMovieStorage (dataRefH, 502 dataRefType, 503 'TVOD', 504 smSystemScript, 505 newMovieActive, 506 outDataHandler, 507 &qtMovie); 508 *outErr = GetMoviesError(); 509 if (*outErr != noErr) goto cantcreatemovstorage; 510 511 return qtMovie; 512 513 // error handling 514 cantcreatemovstorage: 515 DisposeHandle(dataRefH); 516 nodataref: 517 nostring: 518 519 return nil; 520 } 521 522 /* 523 We import SSA by creating a temporary movie, adding samples to it, and copying it to the current movie, which can't have samples added to it as it's read-only. 524 525 I tried to use an in-memory temporary, but it completely failed to work. 526 527 This works except for saving reference movies, which include a dependency on the temporary file. They will break when it's deleted upon restart. 528 I don't see any apparent workaround. 529 */ 475 530 ComponentResult LoadSubStationAlphaSubtitles(const FSRef *theDirectory, CFStringRef filename, Movie theMovie, Track *firstSubTrack) 476 531 { 477 532 ComponentResult err = noErr; 478 Handle dataRef = NULL; 479 OSType dataRefType = rAliasType; 480 HFSUniStr255 hfsFilename; 481 CFRange filenameLen; 482 Track theTrack = NULL; 483 Media theMedia = NULL; 533 Track theTrack = NULL, track2 = NULL; 534 Media theMedia = NULL, media2 = NULL; 484 535 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 485 536 SSADocument *ssa = [[SSADocument alloc] init]; 486 537 static UInt8 path[PATH_MAX]; 487 Handle sampleHndl = NULL, headerHndl=NULL, drefHndl = NewHandle(sizeof(Handle)), drefDataH = NewHandle(0); 488 ComponentInstance dataHandler = NULL; 489 long filePos = 0; 490 long fileSize; 538 Handle sampleHndl = NULL, headerHndl=NULL; 491 539 char *data = NULL; const char *header; 492 540 int i, packetCount, sampleLen; 493 541 ImageDescriptionHandle textDesc; 542 DataHandler tempStor; 543 Movie tempMovie; 544 OSErr oErr; 545 NSString *movieName; 546 Rect movieBox; 494 547 495 548 FSRefMakePath(theDirectory, path, PATH_MAX); … … 505 558 PtrToHand(header, &headerHndl, sampleLen); 506 559 507 *((Handle*)*drefHndl) = drefDataH; 508 509 theTrack = CreatePlaintextSubTrack(theMovie, textDesc, 100, drefHndl, HandleDataHandlerSubType, (ssa->version==S_ASS) ? kSubFormatASS : kSubFormatSSA); 560 tempMovie = CreateQuicktimeMovieFromTempFile(&tempStor,&oErr,&movieName); 561 562 GetMovieBox(theMovie, &movieBox); 563 564 theTrack = CreatePlaintextSubTrack(tempMovie, textDesc, 100, NULL, 0, kSubFormatSSA, headerHndl, movieBox); 510 565 if (theTrack == NULL) { 511 566 err = GetMoviesError(); 512 567 goto bail; 513 568 } 514 515 AddImageDescriptionExtension(textDesc,headerHndl, (ssa->version==S_ASS) ? kSubFormatASS : kSubFormatSSA); 516 569 517 570 theMedia = GetTrackMedia(theTrack); 518 571 if (theMedia == NULL) { … … 522 575 523 576 BeginMediaEdits(theMedia); 524 577 525 578 for (i = 0; i < packetCount; i++) { 526 579 SSAEvent *p = [ssa movPacket:i]; 580 TimeRecord movieStartTime = { SInt64ToWide(p->begin_time), 100, 0 }; 527 581 const char *str = [p->line UTF8String]; 528 582 sampleLen = strlen(str); … … 531 585 532 586 err=AddMediaSample(theMedia,sampleHndl,0,sampleLen, p->end_time - p->begin_time,(SampleDescriptionHandle)textDesc, 1, 0, NULL); 533 if (err != noErr) {NSLog(@"a %d",GetMoviesError()); goto bail;} 534 //note on -1: we sorted the subtitles already, so we know they can be added to the end of the track. 535 InsertMediaIntoTrack(theTrack,-1,p->begin_time,p->end_time - p->begin_time,fixed1); 536 if (err != noErr) NSLog(@"i %d",GetMoviesError()); 587 if (err != noErr) {goto bail;} 537 588 538 589 DisposeHandle(sampleHndl); … … 541 592 EndMediaEdits(theMedia); 542 593 594 InsertMediaIntoTrack(theTrack,0,0,GetMediaDuration(theMedia),fixed1); 595 if (err != noErr) {goto bail;} 596 597 track2 = CreatePlaintextSubTrack(theMovie, textDesc, 100, NULL, 0, kSubFormatSSA, headerHndl, movieBox); 598 599 media2 = GetTrackMedia(track2); 600 601 BeginMediaEdits(media2); 602 err=InsertTrackSegment(theTrack,track2,0,GetTrackDuration(theTrack),0); 603 EndMediaEdits(media2); 604 605 543 606 if (*firstSubTrack == NULL) 544 *firstSubTrack = t heTrack;607 *firstSubTrack = track2; 545 608 else 546 SetTrackAlternate(*firstSubTrack, t heTrack);547 548 SetMediaLanguage( theMedia, GetFilenameLanguage(filename));609 SetTrackAlternate(*firstSubTrack, track2); 610 611 SetMediaLanguage(media2, GetFilenameLanguage(filename)); 549 612 550 613 bail: 551 552 [ssa release];553 [pool release];554 614 555 615 if (err) { … … 565 625 566 626 if (headerHndl) DisposeHandle((Handle)headerHndl); 567 //DisposeHandle((Handle)drefDataH); 568 DisposeHandle((Handle)drefHndl); 627 CloseMovieStorage(tempStor); 628 DisposeMovieTrack(theTrack); 629 DisposeMovie(tempMovie); 630 //unlink([movieName UTF8String]); 631 632 [ssa release]; 633 [pool release]; 569 634 570 635 return err; trunk/SubImport.c
r310 r311 58 58 59 59 Track CreatePlaintextSubTrack(Movie theMovie, ImageDescriptionHandle imgDesc, 60 TimeScale timescale, Handle dataRef, OSType dataRefType, FourCharCode subType) 61 { 62 Rect movieBox; 60 TimeScale timescale, Handle dataRef, OSType dataRefType, FourCharCode subType, Handle imageExtension, Rect movieBox) 61 { 63 62 Fixed trackWidth, trackHeight; 64 63 Track theTrack; … … 66 65 67 66 // plain text subs have no size on their own 68 GetMovieBox(theMovie, &movieBox);69 67 trackWidth = IntToFixed(movieBox.right - movieBox.left); 70 68 trackHeight = IntToFixed(movieBox.bottom - movieBox.top); … … 78 76 (*imgDesc)->clutID = -1; 79 77 78 if (imageExtension) AddImageDescriptionExtension(imgDesc, imageExtension, subType); 79 80 80 theTrack = NewMovieTrack(theMovie, trackWidth, trackHeight, kNoVolume); 81 81 if (theTrack != NULL) { … … 103 103 Track theTrack = NULL; 104 104 Media theMedia = NULL; 105 Rect movieBox; 105 106 106 107 ComponentInstance dataHandler = NULL; … … 139 140 data[fileSize] = '\0'; 140 141 142 GetMovieBox(theMovie, &movieBox); 143 141 144 // millisecond accuracy 142 theTrack = CreatePlaintextSubTrack(theMovie, textDesc, 1000, dataRef, dataRefType, kSubFormatUTF8 );145 theTrack = CreatePlaintextSubTrack(theMovie, textDesc, 1000, dataRef, dataRefType, kSubFormatUTF8, NULL, movieBox); 143 146 if (theTrack == NULL) { 144 147 err = GetMoviesError(); trunk/SubImport.h
r310 r311 22 22 23 23 Track CreatePlaintextSubTrack(Movie theMovie, ImageDescriptionHandle imgDesc, 24 TimeScale timescale, Handle dataRef, OSType dataRefType, FourCharCode subType); 24 TimeScale timescale, Handle dataRef, OSType dataRefType, FourCharCode subType, Handle imageExtension, Rect movieBox); 25 26 short GetFilenameLanguage(CFStringRef filename); 25 27 26 28 #ifdef __cplusplus
