在iOS下检索电影编解码器

在iOS下检索电影编解码器

本文介绍了在iOS下检索电影编解码器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到用于压缩电影的编解码器。我确定我是否需要以某种方式使用CMFormatDescription并获取CMVideoCodecType密钥。我被困在如何通过元数据数组。 ?如何检索编解码器的任何想法

I am trying to find the codec used to compress a movie. I am sure if I need to somehow use CMFormatDescription and get a CMVideoCodecType key. I am stuck as to how to get past the metadata array. Any ideas on how to retrieve the codec?

AVURLAsset* movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];
NSArray *tracks = [movieAsset tracksWithMediaType:AVMediaTypeVideo];

if ([tracks count] != 0) {
    AVAssetTrack *videoTrack = [tracks objectAtIndex:0];

    //
    // Let's get the movie's meta data
    //

    // Find the codec
    NSArray *metadata = [movieAsset commonMetadata];
 }


推荐答案

稍微更具可读性的版本@ jbat100的答案(对于那些和我一样困惑的人 #define FourCC2Str ,哈哈)

A slightly more readable version of @jbat100's answer (for those who were as confused as I was with that #define FourCC2Str, hah)

// Get your format description from whichever track you want
CMFormatDescriptionRef formatHint;

// Get the codec and correct endianness
CMVideoCodecType formatCodec = CFSwapInt32BigToHost(CMFormatDescriptionGetMediaSubType(formatHint));

// add 1 for null terminator
char formatCodecBuf[sizeof(CMVideoCodecType) + 1] = {0};
memcpy(formatCodecBuf, &formatCodec, sizeof(CMVideoCodecType));

NSString *formatCodecString = @(formatCodecBuf);

这篇关于在iOS下检索电影编解码器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 18:27