由于无法识别电影的文件格式,无法打开视频文件

Video file could not be opened due to movie's file format isn't recognized

提问人:BADRI 提问时间:1/9/2013 最后编辑:Lou FrancoBADRI 更新时间:1/20/2017 访问量:1009

问:

我正在尝试从 image magick 库给出的图像创建视频文件。在逐一应用一些效果(如不透明度差异)后,它创建成功,但给出了错误。Quick time player" video file could not be opened. The movie's file format isn't recognized "

我正在使用以下代码:

double d = 0.00;

- (void)posterizeImageWithCompression:(id)sender {

    // Here we use JPEG compression.
    NSLog(@"we're using JPEG compression");

    MagickWandGenesis();
    magick_wand = NewMagickWand();
    magick_wand = [self magiWandWithImage:[UIImage imageNamed:@"iphone.png"]];

    MagickBooleanType status;

    status = MagickSetImageOpacity(magick_wand, d);

    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }
    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }
    size_t my_size;
    unsigned char * my_image = MagickGetImageBlob(magick_wand, &my_size);
    NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size];
    free(my_image);
    magick_wand = DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    UIImage * image = [[UIImage alloc] initWithData:data];

    d = d + 0.05;
    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }

    NSData *data1;

    NSArray *paths;

    NSString *documentsDirectory,*imagePath ;

    UIImage *image1 = image;

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    documentsDirectory = [paths objectAtIndex:0];

    imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString   stringWithFormat:@"%f.png",d]];

    data1 = UIImagePNGRepresentation(image1);

    if (d <= 1.0 ) {

        [data1 writeToFile:imagePath atomically:YES];

        [imageViewButton setImage:image forState:UIControlStateNormal];

        // If ready to have more media data
         if (assetWriterPixelBufferAdaptor.assetWriterInput.readyForMoreMediaData) {
             CVReturn cvErr = kCVReturnSuccess;
             // get screenshot image!
             CGImageRef image1 = (CGImageRef) image.CGImage;

             // prepare the pixel buffer
             CVPixelBufferRef pixelsBuffer = NULL;

             // Lock pixel buffer address
             CVPixelBufferLockBaseAddress(pixelsBuffer, 0);

            // pixelsBuffer = [self pixelBufferFromCGImage:image1];

             CVPixelBufferUnlockBaseAddress(pixelsBuffer, 0);

             CFDataRef imageData= CGDataProviderCopyData(CGImageGetDataProvider(image1));
             NSLog (@"copied image data");
             cvErr = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,
                                                  FRAME_WIDTH,
                                                  FRAME_HEIGHT,
                                                  kCVPixelFormatType_32BGRA,
                                                  (void*)CFDataGetBytePtr(imageData),
                                                  CGImageGetBytesPerRow(image1),
                                                  NULL,
                                                  NULL,
                                                  NULL,
                                                  &pixelsBuffer);
             NSLog (@"CVPixelBufferCreateWithBytes returned %d", cvErr);

             // calculate the time
             CFAbsoluteTime thisFrameWallClockTime = CFAbsoluteTimeGetCurrent();
             CFTimeInterval elapsedTime = thisFrameWallClockTime - firstFrameWallClockTime;
             NSLog (@"elapsedTime: %f", elapsedTime);
             CMTime presentationTime =  CMTimeMake (elapsedTime * TIME_SCALE, TIME_SCALE);

             // write the sample
             BOOL appended = [assetWriterPixelBufferAdaptor appendPixelBuffer:pixelsBuffer withPresentationTime:presentationTime];

             if (appended) {
                 NSLog (@"appended sample at time %lf", CMTimeGetSeconds(presentationTime));
             } else {
                 NSLog (@"failed to append");
                 [self stopRecording];
             }

             // Release pixel buffer
             CVPixelBufferRelease(pixelsBuffer);
             CFRelease(imageData);
         }
     }


}

它还显示错误,例如...

VideoToolbox`vt_Copy_32BGRA_2vuyITU601 + 91 and 
VideoToolbox`vtPixelTransferSession_InvokeBlitter + 574 and 
VideoToolbox`VTPixelTransferSessionTransferImage + 14369 and 
VideoToolbox`VTCompressionSessionEncodeFrame + 1077 and 
MediaToolbox`sbp_vtcs_processSampleBuffer + 599
iOS Objective-C iPhone ImageMagick

评论

0赞 Vishal Sharma 11/16/2015
所以你想从图像创建视频吗?
0赞 Swati 11/19/2015
您是否尝试过将 FFMPEG 用于此功能?
0赞 Sumeet 12/22/2015
我认为这可能是因为不正确的 presentationTime。我们赋予的价值以及您期望最终电影的 FPS 是什么。TIME_SCALE
0赞 11/30/2016
使用 Image Magick 有什么特别的原因吗?如果没有,这里有一个更好的方法从图像创建电影:stackoverflow.com/questions/3741323/......

答:

0赞 Douglas Daseeco 1/20/2017 #1

QT 播放器的信息量不是很大。通常,玩家会提供缺少的编解码器的名称。如果您生成了文件,并在QT播放失败的同一台计算机上以编程方式播放了它,那么,无论出于何种原因,程序库显然可以看到的编解码器(因为它使用了它)没有在操作系统中注册。在shell中,您可以执行“文件”并获取文件类型,可能还有编解码器。如果没有,您应该能够找到带有 vlc、转码或 gstreamer 的编解码器,然后按照 Apple 的说明将所需的编解码器直接下载并安装到操作系统中。