0

多くのビデオをトリミングしてから、それらの編集のプレビューを表示する必要があります。ユーザーはすべてのビデオの開始時間と終了時間を編集できます。現在のビデオのプレビューを (ユーザーがトリムしている間) コードで表示します。

AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:video.fileURL]];
int32_t timeScale = player.currentItem.asset.duration.timescale;
float startTime = video.startTime;
float endTime = video.endTime > 0 ? video.endTime : video.duration;
player.currentItem.forwardPlaybackEndTime = CMTimeMakeWithSeconds(endTime, timeScale);
[player seekToTime:CMTimeMakeWithSeconds(startTime, timeScale)
   toleranceBefore:kCMTimeZero
    toleranceAfter:kCMTimeZero
 completionHandler:^(BOOL finished) {
     if (finished) {
         [self.player play];
     }
 }];

GPUImage には単一の AVPlayerItem が必要なので、コンパイル プレビューには AVMutableComposition を使用します。私のコード:

AVMutableComposition *composition = [[AVMutableComposition alloc] init];
for (Video *video in videos) {
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:video.fileURL] options:nil];
    int32_t timeScale = asset.duration.timescale;
    CMTime startTime = CMTimeMakeWithSeconds(video.startTime, timeScale);
    CMTime duration = CMTimeMakeWithSeconds(
            (video.endTime > 0 ? video.endTime : video.duration) - video.startTime,
            timeScale);

    [composition insertTimeRange:CMTimeRangeMake(startTime, duration)
                         ofAsset:asset
                          atTime:composition.duration error:nil];
}

AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:[composition copy]];

画面にさまざまな範囲のビデオが表示されます。どこが間違っていますか?

4

2 に答える 2

1

これにより、画面に間違った時間が表示される問題が解決されます。以前の時点で停止したい場合は、終了時間を変更できます。お役に立てれば。

CMTime startTime = CMTimeMake((int)(floor([@(video.startTime) floatValue] * 100)), 100);
CMTime stopTime = CMTimeMake((int)(ceil([@(video.duration) floatValue] * 100)), 100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime);

    // grab the portion of interest from the master asset WHOLE MASTER TRACK
    [audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, masterAsset.duration)
                        ofTrack:[[masterAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                         atTime:kCMTimeZero
                          error:&error];
于 2015-09-10T11:02:41.397 に答える