Lrenger semigo
Lrenger semigo

Reputation: 243

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

Upvotes: 6

Views: 2846

Answers (3)

Ofir Malachi
Ofir Malachi

Reputation: 1286

AVURLAsset* asset = [[AVURLAsset alloc]initWithURL:_assetUrl options:nil];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack * audioTrack = [audioTracks firstObject];
if([track hasMediaCharacteristic:AVMediaCharacteristicAudible]){

}

Upvotes: 0

Jekil Patel
Jekil Patel

Reputation: 403

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

Upvotes: 0

imihaly
imihaly

Reputation: 1858

AVAsset *asset = [AVAsset assetWithURL:<URL to mp4>];
BOOL hasVideo = [asset tracksWithMediaType:AVMediaTypeVideo].count > 0;
BOOL hasAudio = [asset tracksWithMediaType:AVMediaTypeAudio].count > 0;

Upvotes: 10

Related Questions