how to set thumbnail image of video? - iphone

I have a custom button in my application on click of which I present a UIImagePickerControllerSourceTypeCamera to take a video.
Now, after capturing the video I want to set a thumbnail of it to this custom button.
How to take 1st frame of that video to set thumbnail ?

refer the following links. You can get some ideas regarding creating thumbnails for videos.
Getting a thumbnail from a video url or data in iPhone SDK
stackoverflow.com/questions/1259316/iphone-sdk-3-0-video-thumbnail

Check This.
NSString *videoLink=[info objectForKey:#"UIImagePickerControllerMediaURL"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:(NSURL*)videoLink];
UIImage *imageSel = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];
[player release];

Related

Split videos to frames/images

I have a requirement to split a 5 sec video to images /frames from my iphone.
Is it possible using objective C.Any libraries available for this?
Help is highly appreciable.
Thanks,
there are many ways by which you can get images from a video. Some of them are :-
NSURL *videoURL = [NSURL fileURLWithPath:url];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
[player release];
You can also check these links:-
Is there any way other than thumbnail method to take a screenshot of an video in Iphone?
How to take a screenshot from an video playing through MPMediaPlayerController in iPhone?
It may help you :)
Thanks :)

Iphone Videoplayer

I am creating video based ios application.I am using MPMoviePlayerController for playing video. It is working correctly for local video files but I am not able to play the video for the server link please give me some idea
Here is my code
MPMoviePlayerController * player = [[MPMoviePlayerController alloc] init];
NSURL *url = [NSURL URLWithString:imageName];
player.scalingMode = MPMovieScalingModeFill;
[player setContentURL:url];
[player prepareToPlay];
[player play];
if you want using a MPMoviePlayerController implement that server links or streaming.
refer a this sample code. Will help you a lot: MoviePlayer

getting thumbnail images from saved path of video files in iPhone

I am trying to display thumbnail images for the downloaded videos in one of my apps. I have shown the images along with the video title inside a table view. I'm using this code for getting the image:
NSURL *videoURL = [NSURL fileURLWithPath:myString];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:videoURL];
UIImage *thumbnail =
[player thumbnailImageAtTime:1.0
timeOption:MPMovieTimeOptionNearestKeyFrame];
cell.imageView.image = thumbnail;`
Images are showing for the files that are downloaded from YouTube, but I'm not getting the images from .flv video files. Can anyone suggest a solution? This is a sample of my video path
/Users/admin/Library/Application Support/iPhone Simulator/5.0/Applications/AA8DDEED-E91C-47BB-8F1E-C057D9E94B7C/Documents/downloads/qkycmzafawmk.flv
What is the value of thumbnail after the call to -thumbnailImageAtTime:timeOption:? Assuming that this UIImage is not nil, have you checked its alpha property?
If thumbnail is nil, have you checked into the numerous other SO questions regarding this? Here are a couple to get you started:
MPMoviePlayerControlle thumbnailImageAtTime: timeOption: giving
empty UIImage
MPMoviePlayerController
thumbnailImageAtTime:timeOption: simple case doesn't work
This is the tutorial i have followed to solve this issue.Hope this may help someone: http://www.codza.com/extracting-frames-from-movies-on-iphone.

Open movie stream in another view

I have in my app a tab view with many tabs, and in one of them I have a button that when is clicked, I want to show a movie stream in a view. I have this code:
NSString *moviePath = #"http://10.0.0.4/prog_index.m3u8";
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
[theMovie.view setFrame:CGRectMake(0, 0, (self.view.frame.size.width), (self.view.frame.size.height))];
theMovie.view.backgroundColor = [UIColor grayColor];
theMovie.view.tag = 9999;
[self.view addSubview:[theMovie view]];
[theMovie play];
The view appears, but the video doesn't start. What is wrong?
You're passing to the MPMoviePlayerController an URL pointing to a m3u8 file. That is a playlist. To play media with MPMoviePlayerController, you have to set it an actual video file. You should parse the playlist to get the link to the real video and then init your MPMoviePlayerController with the real link.
Check M3U - Wikipedia and MPMoviePlayerController reference
Also check this related question
EDIT: Thanks to Hugo Silva, I realized that MPMoviePlayerController is able to play live streams in m3u8 format, since I've not seen anything wrong in your code, I suggest you to check if it's a problem of your stream. Try using one of the samples provided by Apple. Also make sure that your stream meets Apple's requirements for HTTP Streaming

MPMoviePlayerController questions, best practices

I have any number of thumbnail images that, when tapped, will play a different video (fullscreen). I have never been clear on whether I should keep one MPMoviePlayerController object in my view controller and have it play whichever url according to the thumbnail that was tapped, or create a new MPMoviePlayerController each time. What is the best practice?
I am also having problems where tapping on different thumbs crashes the app, I believe because the MPMoviePlayerController tries to stream a video while it is already trying to stream. There seems to be no way to cancel a MPMoviePlayerController and clear out what it was doing, then start loading a new video.
Here's how I create it:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];
Then to play a video I do this:
//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];
Any advice is welcome... thanks.
When you are changing the video in an MPMovieplayerController,then you can remove the mpmoviecontrollerplayer view from super view using removeFromSuperView and again add it's subview to the super view initializing it with new URL.
No need to create new object every time.