Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the screenshot of a streaming video on iphone

How can i get the screenshot of a streaming video on iphone. I tried several methods.

  1. UIGetScreenImage() -> This is private. The app will be rejected if I use it.

  2. UIGraphicsBeginImageContext(CGSizeMake(1024, 768)); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();

    The code above cannot take the screenshot of video layer.
    
  3. MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL [NSURL URLWithString:@"myMovie.mp4"]]; UIImage *singleFrameImage = [movie thumbnailImageAtTime:10 timeOption:MPMovieTimeOptionExact];

    The code above does not work on a streaming video.
    

What else can I try besides AVFoundation. Thank you.

like image 709
Tanhan Avatar asked Mar 22 '11 07:03

Tanhan


People also ask

How do I get a screen shot from a video?

Play the video and pause it at the point you want to take a still from it. Press PRINT SCREEN or ALT+PRINT SCREEN, depending on whether the video is playing full screen or in an active window. Tip: You can paste your screen capture into Paint, which is a drawing program you can use to crop, rotate, and resize pictures.

Can I capture a video playing on my iPhone?

Go to Settings > Control Center, then tap the Add button next to Screen Recording. Open Control Center on your iPhone, or on your iPad. , then wait for the three-second countown. Exit Control Center to record your screen.

Where are screen captures saved on iPhone?

Where to find screenshots. Open Photos, then go to Albums > Media Types > Screenshots.


1 Answers

Not sure if it will work, but have you tried using AVPlayer? It should give you access to AVURLAsset which you could pass to AVAssetImageGenerator.

AVPlayerItem *item = [AVPlayerItem playerItemWithURL:yourURL];
AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];

//observe 'status'
[playerItem addObserver:self forKeyPath:@"status" options:0 context:nil];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                        change:(NSDictionary *)change context:(void *)context
{ 
    if ([keyPath isEqualToString:@"status"]) {
        AVPlayerItem *item = (AVPlayerItem *)object;
        if (item.status == AVPlayerItemStatusReadyToPlay) {
            AVURLAsset *asset = (AVURLAsset *)item.asset;
            AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
            CGImageRef thumb = [imageGenerator copyCGImageAtTime:CMTimeMakeWithSeconds(10.0, 1.0)
                                                      actualTime:NULL
                                                           error:NULL];
        }
    }   
}
like image 103
Alex Chugunov Avatar answered Oct 02 '22 11:10

Alex Chugunov