【问题标题】:Is there any way other than thumbnail method to take a screenshot of an video in Iphone?除了缩略图方法之外,还有其他方法可以在 Iphone 中截取视频吗?
【发布时间】:2012-05-23 16:00:41
【问题描述】:

除了缩略图方法之外,还有其他方法可以截取视频吗?如果是,那么请告诉我,如果不是,那么请告诉我如何调整具有相同分辨率的缩略图图像的大小?我在截取视频时遇到问题。我用过这个:-

How to take a screenshot from an video playing through MPMediaPlayerController in iPhone?

在此之后,我使用了图像的合并,我得到了这个

这里的图像质量是我的大问题。

我想要这个

我只想要上面屏幕截图中显示的视频和绘图,结果相同。 请帮忙谢谢:)

【问题讨论】:

    标签: iphone objective-c image-capture


    【解决方案1】:

    除了缩略图之外,还有其他方法可以截取视频。!!!

    方法是这样的:-

    - (UIImage *)imageFromVideoURL 
    {
    // result 
    UIImage *image = nil;
    
    // AVAssetImageGenerator
    AVAsset *asset = [[AVURLAsset alloc] initWithURL:appDelegate.videoURL options:nil];; 
    AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    imageGenerator.appliesPreferredTrackTransform = YES;
    
    // calc midpoint time of video
    Float64 durationSeconds = CMTimeGetSeconds([asset duration]);
    CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600); 
    
    // get the image from 
    NSError *error = nil; 
    CMTime actualTime;
    CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];
    
    if (halfWayImage != NULL) 
    {
        // cgimage to uiimage
        image = [[UIImage alloc] initWithCGImage:halfWayImage];
        [dic setValue:image forKey:kImage];
        NSLog(@"Values of dictonary==>%@", dic);
        NSLog(@"Videos Are:%@",appDelegate.videoURLArray);
        CGImageRelease(halfWayImage);
    }
    return image;
    }
    

    但我的问题仍然是相同的,我在视频上绘图我无法通过绘图叠加获得视频的屏幕截图,因此我必须使用图像合并。

    谢谢:)

    【讨论】:

      【解决方案2】:

      试试下面的代码。

          moviePlayer = [[MPMoviePlayerController alloc] init];
          containerView =[[UIView alloc]initWithFrame:CGRectMake(40,130, 240,219)];
          [moviePlayer setContentURL:[NSURL fileURLWithPath:moviePath]];
          [[moviePlayer view] setFrame:CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height)];  // frame must match parent view
          [self.view addSubview:containerView];
          [containerView addSubview: [moviePlayer view]];
          [moviePlayer setFullscreen:YES animated:YES];
      

      【讨论】:

        【解决方案3】:

        这将在您想要的时间点为您提供视频播放器的屏幕截图。 这是一个标准的方法,通过时间选项来获取玩家的缩略图。

        MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
        UIImage *thumbnail = [player thumbnailImageAtTime:60.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
        
        
        UIImageView *imagV=[[UIImageView alloc]initWithImage:thumbnail];
        [imagV setFrame:CGRectMake(self.view.center.x, self.view.center.y, 200.0, 200.0)];
        

        【讨论】:

          猜你喜欢
          • 2019-09-14
          • 1970-01-01
          • 1970-01-01
          • 2018-03-01
          • 1970-01-01
          • 1970-01-01
          • 2015-12-08
          • 1970-01-01
          • 2017-07-18
          相关资源
          最近更新 更多