我想通过函数将过滤器应用于AVVideoComposition:
init(asset: AVAsset, applyingCIFiltersWithHandler: (AVAsynchronousCIImageFilteringRequest) -> Void)
其中asset
为AVComposition
。当AVPlayerItem
使用videoComposition播放此合成时,应用程序崩溃并显示错误:
reason: '*** -[AVCoreImageFilterCustomVideoCompositor startVideoCompositionRequest:] Expecting video composition to contain only AVCoreImageFilterVideoCompositionInstruction'
我想知道如何修复崩溃。
PS:我有两个videoTracks,每个timeRange都有它的指令
答案 0 :(得分:1)
我猜你试图将AVVideoCompositionLayerInstruction添加到AVVideoComposition。
首先尝试简单方法,看看是否需要进行任何更改:
AVURLAsset *asset = [AVURLAsset assetWithURL:videoURL];
CIFilter *filter = [CIFilter filterWithName:@"CIHueAdjust"]; // the filter you want to add: https://developer.apple.com/library/content/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoCompositionWithAsset:asset applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest * _Nonnull request) {
// set filter input image
[filter setDefaults];
[filter setValue:sourceImage forKey:kCIInputImageKey];
// hue
NSNumber *angle = [NSNumber numberWithFloat:0.8];
[filter setValue:angle forKey:kCIInputAngleKey];
CIImage *outputImage = filter.outputImage;
[request finishWithImage:outputImage context:nil];
}];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset1920x1080];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.outputURL = outputURL;
exportSession.videoComposition = videoComposition;
// export the session async
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
NSLog(@"Yeah!");
break;
default:
NSLog(@"Nooo!");
break;
}
}];
答案 1 :(得分:1)
您不能同时使用CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 2
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
stream.stop_stream()
stream.close()
p.terminate()
和AVVideoCompositionLayerInstruction
。
Intead,您需要直接在过滤器中应用转换。
这可以通过将其应用于源图像来完成。
applyingCIFiltersWithHandler
答案 2 :(得分:0)