小编MuT*_*TeD的帖子

AVFoundation + AssetWriter:使用图像和音频生成电影

我必须从我的iPhone应用程序导出一部电影,其中包含来自NSArray的UIImage,并添加一些必须在预先指定的时间开始的.caf格式的音频文件.现在我已经能够使用AVAssetWriter导出包含图像的视频部分(经历就这个问题和其他网站的许多问题和答案后),但不能似乎找到一个方法来添加音频文件来完成电影.

这是我到目前为止所得到的

-(void) writeImagesToMovieAtPath:(NSString *) path withSize:(CGSize) size
{
    NSLog(@"Write Started");

    NSError *error = nil;

    AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:
                              [NSURL fileURLWithPath:path] fileType:AVFileTypeQuickTimeMovie
                                                          error:&error];    
    NSParameterAssert(videoWriter);

    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt:size.width], AVVideoWidthKey,
                               [NSNumber numberWithInt:size.height], AVVideoHeightKey,
                               nil];

    AVAssetWriterInput* videoWriterInput = [[AVAssetWriterInput
                                    assetWriterInputWithMediaType:AVMediaTypeVideo
                                    outputSettings:videoSettings] retain];


    AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor
                                            assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput
                                                 sourcePixelBufferAttributes:nil];

    NSParameterAssert(videoWriterInput);
    NSParameterAssert([videoWriter canAddInput:videoWriterInput]);
    videoWriterInput.expectsMediaDataInRealTime = YES;
    [videoWriter addInput:videoWriterInput];

    //Start a session:
    [videoWriter startWriting];
    [videoWriter startSessionAtSourceTime:kCMTimeZero];

    CVPixelBufferRef buffer = NULL;

    //convert uiimage to CGImage.

    int frameCount = 0; …
Run Code Online (Sandbox Code Playgroud)

iphone avfoundation avassetwriter avmutablecomposition

38
推荐指数
1
解决办法
2万
查看次数

如何在Keras中将输入拆分为不同的通道

我有20个通道数据,每个通道数据都有5000个值(在HD中以.npy文件形式存储的总计150,000+条记录)。

我正在关注https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly.html上提供的keras fit_generator教程以读取数据(每个记录都读为( 5000,20)float32类型的numpy数组。

我已经理论化的网络,每个通道都有并行的卷积网络,这些卷积网络最后连接到,因此需要并行地馈送数据。仅读取和馈送数据中的单个通道并馈送到单个网络是成功的

def __data_generation(self, list_IDs_temp):
    'Generates data containing batch_size samples' # X : (n_samples, *dim, n_channels)
    # Initialization
    if(self.n_channels == 1):
        X = np.empty((self.batch_size, *self.dim))
    else:
        X = np.empty((self.batch_size, *self.dim, self.n_channels))
    y = np.empty((self.batch_size), dtype=int)

    # Generate data
    for i, ID in enumerate(list_IDs_temp):
        # Store sample
        d = np.load(self.data_path + ID + '.npy')
        d = d[:, self.required_channel]
        d = np.expand_dims(d, 2)
        X[i,] = d

        # Store class
        y[i] = self.labels[ID]

    return X, keras.utils.to_categorical(y, num_classes=self.n_classes)
Run Code Online (Sandbox Code Playgroud)

但是,当读取整个记录并尝试使用Lambda层进行切片将其馈送到网络时,我得到了 …

python multiprocessing keras tensorflow keras-layer

3
推荐指数
1
解决办法
5236
查看次数