getting thumbnail images from saved path of video files in iPhone - 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.

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 :)

Adding videos to application

I want to store large number of videos in my application's directory. Will it make my application slow? Or will it take time to launch the application. I am loading videos only when necessary.
It will make large size of your application which is not good...& it will also take time to launch in place of save all ur video u can make user to download that video from server and after that it will be saved in ur doc directory so ur app will be not of large size.............
Where is it located locally
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"videoname" ofType:#"mov" inDirectory:#""]];
and play with that
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view
[self.view addSubview:[player view]];
[player play];
[player release];
EDIT:-
The exact answer to this question is NO, it will not make your App Slow,But yeah it ill take some time to load the videos in your App,Time will depend upon number of videos you are loading in your APP. The solution to this is you have to use blocks for ALAssetLibaries.
Have a look on this ALAssetLibary Apple's class reference.
It may help you if not do contact me. Thanks :)

how to set thumbnail image of video?

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];

objective c MPMoviePlayerController wont work on iOS 4.3

Ive got this code from an ebook tutorial on embedding MPMoviePlayerController from a VIEW object but it just dont work at all on iOS 4.3, it just gives me a black screen. I've tried looking at other sources and they have the same source code. Can anyone help me on finding what is the problem in this code.
Thanks
- (IBAction)playMovie:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"shawarma" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[player.view setFrame: movieHolder.bounds];
[movieHolder addSubview: player.view];
[player play];
}
My VIEW object has a dimension of 400 x 300.
From the MPMoviePlayerController class reference guidelines Consider
a movie player view to be an opaque structure.
You can add your own custom subviews to layer content on top of the
movie but you must never modify any of its existing subviews.
In addition to layering content on top of a movie, you can provide
custom background content by adding
subviews to the view in the backgroundView
MPMoviePlayerController it self has a property view to present the video
Hope this LINK might help you
There is no issue with MPMoviePlayer and ios 4.3 i am working on an application that plays movie from a server and this is working fine for me. I request you to check
Path of you resource try some hardcode path.
Frame of the MoviePlayer.
Thanks

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