get the pointer value for AVURLAsset, ios - ios

I am new in iPhone. I want to get data from AVURLAsset format.
following is my AVURLAsset response.
<AVURLAsset: 0x1768c800, URL = http://s9.voscast.com:7924/;.mp3>
i can get URL by following code.
AVPlayerItem *item = (AVPlayerItem *)object;
if(item.status != AVPlayerItemStatusReadyToPlay)
return;
if(item.status == AVPlayerItemStatusReadyToPlay)
{
AVURLAsset *asset = (AVURLAsset *)item.asset;
NSLog(#"myasset:%#",asset);
NSString *myurl = [asset valueForKey:#"URL"];
NSLog(#"myurl:%#",myurl);
}
output of above code is
myasset:<AVURLAsset: 0x1768c800, URL = http://s9.voscast.com:7924/;.mp3>
2015-04-15 23:01:50.452 myurl:http://s9.voscast.com:7924/;.mp3
but I want to get 0x1768c800
can anybody help me how to get above value.

Related

Objective-c how to add filter to an existing video like Instagram Application?

I'm trying to add filter to video after recording it, just like Instagram. After searching for a way I found GPUImage, but that didn't solve it since in this code the video is being written to directory before displaying it (causing delay):
//Setting path for temporary storing the video in document directory
NSURL *movieURL = [self dataFilePath: #"tempVideo.mp4"]; // url where we want to save our new edited video
Is there a way to preview the filtered video before saving it in order not to take time? If so, how it is done?
Also, I found in the apple documentation about CIFilter but still can not find a way that states how to add filters to the video.
In addition, that there are some codes but written in swift.
Thanks in advance.
I couldn't find a way to stop the delay that is happing with the GPUImage. So I tried working with the SCRecorder.
What I have done is:
[_player setItemByUrl:videoURL];
instead of:
[_player setItemByAsset:_recordSession.assetRepresentingSegments];
by this way I'm able to play and add filter to an existing video just like Instagram.
To export the video with the chosen filter I used this code:
- (void)saveToCameraRoll {
NSString *fileName = videoURL.lastPathComponent;
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *videoPath = [NSString stringWithFormat:#"%#/%#",docsDir,fileName];
NSURL *urlPath = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#", videoPath]];
NSURL *assetUrl = urlPath;
AVAsset *asset = [AVAsset assetWithURL:assetUrl];
SCFilter *exportFilter = [self.filterSwitcherView.selectedFilter copy];
SCAssetExportSession *exportSession = [[SCAssetExportSession alloc] initWithAsset:asset];
NSURL *urlFile = [NSURL URLWithString:[NSString stringWithFormat:#"%#/%#.mov",docsDir,fileName]];
exportSession.outputUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#",urlFile]];
filterURL = exportSession.outputUrl;
exportSession.videoConfiguration.filter = exportFilter;
exportSession.videoConfiguration.preset = SCPresetHighestQuality;
exportSession.audioConfiguration.preset = SCPresetHighestQuality;
exportSession.videoConfiguration.maxFrameRate = 35;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.delegate = self;
exportSession.contextType = SCContextTypeAuto;
self.exportSession = exportSession;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
if (exportSession.error == nil) {
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[exportSession.outputUrl saveToCameraRollWithCompletion:^(NSString * _Nullable path, NSError * _Nullable error) {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
if (error == nil) {
//Success
}
}];
} else {
NSLog(#"Error: %#", exportSession.error);
}
}];
}

AVPlayer fails to play video and AVURLAsset return empty array of tracks

Before posting my question, I tried with this post.
Currently I am migrating my project from MPMoviewPlayer to AVPlayer.
In that moment Video file not played if I changed name with French characters. AVURLAsset will return empty tracks array.
Also, asset.playable returns NO.
Here is my code :
NSURL *videoURL = [NSURL fileURLWithPath:videoFilePath];
videoURL = [NSURL fileURLWithPath:videoFilePath isDirectory:NO];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
if([asset tracksWithMediaType:AVMediaTypeVideo].count == 0) {
NSLog(#"No Video Track");
} else if([asset tracksWithMediaType:AVMediaTypeAudio].count == 0) {
NSLog(#"No Audio Track");
}
If you observe my File path Users/Axio-Mac/Library/Developer/CoreSimulator/Devices..../Library/Caches/AppFiles/première journée French_accent File name â ê i-xiufm2.mp4 you can see french accented characters. Is that the impact ?

AVURLAsset load webvtt file

I am trying to use AVURLAsset to load a webvtt file.
Below is my code.
NSString *urlAddress = #"http://somewhere/some.vtt";
NSURL *urlStream = [[NSURL alloc] initWithString:urlAddress];
AVAsset *avAsset = [AVURLAsset URLAssetWithURL:urlStream options:nil];
NSArray *requestKeys = [NSArray arrayWithObjects:#"tracks",#"playable",nil];
[avAsset loadValuesAsynchronouslyForKeys:requestKeys completionHandler:^{
dispatch_async(dispatch_get_main_queue(),^{
//complete block here
AVKeyValueStatus status =[avAsset statusOfValueForKey:#"tracks" error:nil];
if(status == AVKeyValueStatusLoaded) {
//loaded block !
//Question 1
CMTime assetTime = [avAsset duration];
Float64 duration = CMTimeGetSeconds(assetTime);
NSLog(#"%f", duration);
//Question 2
AVMediaSelectionGroup *subtitle = [avAsset mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicLegible];
NSLog(#"%#", subtitle);
}
else {
//don’t load block !
}
});
}];
Question 1: It always go into the "Loaded Block", but I find the avAsset's duration is not complete, that means the data is not loaded? How should I modify it?
Question 2: I am trying to use it to my avplayer's subtitle, but the AVMediaSelectionGroup is always null. What should I do?
For question 1, add duration to your keys:
NSArray *requestKeys = #[#"tracks",#"playable", #"duration"];
I've posted a solution over here: https://stackoverflow.com/a/37945178/171933 Basically you need to use an AVMutableComposition to join the video with the subtitles and then play back that composition.
About your second question: mediaSelectionGroupForMediaCharacteristic seems to only be supported when these "characteristics" are already baked into either the media file or your m3u8 stream, according to this statement by an Apple engineer (bottom of the page).

How to get video attributes in iOS8 share extension

I am trying to create a sharing extension to share videos using the new iOS 8 app extensions.I want to open the photo app and share the video by my extension.
I get the video url by following codes:
NSExtensionItem *inputItem = self.extensionContext.inputItems.firstObject;
NSItemProvider *provider = inputItem.attachments[0];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
if ([provider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeQuickTimeMovie])
{
[provider loadItemForTypeIdentifier:#"com.apple.quicktime-movie" options:nil completionHandler:^(NSURL *path,NSError *error){
if (path)
{
dispatch_async(dispatch_get_main_queue(), ^{
_moviePath = path;
});
}
}];
}
});
But I only got the video file url:
file:///var/mobile/Media/DCIM/100APPLE/IMG_0062.MOV
I also want to get more video attributes ,like: size and duration
I used following codes,but not work:
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];
int second = urlAsset.duration.value / urlAsset.duration.timescale;
and this code:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:_moviePath];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(#"duration: %.2f", seconds);
they are all do not work
and xcode tips:
Error [IRForTarget]: Call to a symbol-only function 'memset' that is not present in the target
error: 0 errors parsing expression
error: The expression could not be prepared to run in the target
You can help me to get the video attributes?Thank you very much!
Now the following codes do working:
NSDictionary *opts = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];
int second = urlAsset.duration.value / urlAsset.duration.timescale;
And I don't know Why it does not work before!

Determine whether mp4 is a audio or video in objective C

Since mp4 is a container file format it can store audio as well as video files. What i am struggling to find out is its true media type. (Whether its a audio or video) Could this be done in IOS (objective c) ?
AVAsset *asset = [AVAsset assetWithURL:<URL to mp4>];
BOOL hasVideo = [asset tracksWithMediaType:AVMediaTypeVideo].count > 0;
BOOL hasAudio = [asset tracksWithMediaType:AVMediaTypeAudio].count > 0;
BOOL isMP4VideoType; //Global Variables;
BOOL isMP4AudioType; //Global Variables;
//Create an object of AVAsset class With MP4 URL.
AVAsset *asset = [AVAsset assetWithURL:YOUR_MP4_URL];
NSArray *aryVideoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
NSArray *aryAudioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
if([aryVideoTracks count]!=0)
{
isMP4VideoType = YES;
}else if([aryVideoTracks count]!=0)
{
isMP4AudioType = YES;
}
AVURLAsset* asset = [[AVURLAsset alloc]initWithURL:_assetUrl options:nil];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack * audioTrack = [audioTracks firstObject];
if([track hasMediaCharacteristic:AVMediaCharacteristicAudible]){
}

Resources