獲取NSData數(shù)據(jù)的md5(以視頻為例)

視頻為例如下:

//導入
#include <CommonCrypto/CommonDigest.h>

/// 獲取視頻MD5方法
/// @param url 視頻url,暫未用到
/// @param localAsset 本地的asset數(shù)據(jù)
- (void)getPhoneDateVideo:(NSURL *)url phAsset:(PHAsset *)localAsset
{
    PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
    options.version = PHImageRequestOptionsVersionCurrent;
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
    
    PHImageManager *manager = [PHImageManager defaultManager];
    [manager requestAVAssetForVideo:localAsset
                            options:options
                      resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
        // asset 類型為 AVURLAsset  為此資源的fileURL
        // <AVURLAsset: 0x283386e60, URL = file:///var/mobile/Media/DCIM/100APPLE/IMG_0049.MOV>
        AVURLAsset *urlAsset = (AVURLAsset *)asset;
        // 視頻數(shù)據(jù)
        NSData *vedioData = [NSData dataWithContentsOfURL:urlAsset.URL];
        NSLog(@"%@",vedioData);
        [vedioData writeToFile:KVideoUrlPath atomically:YES];
        dispatch_async(dispatch_get_main_queue(), ^{
             //獲取視頻MD5
            NSData *data = vedioData;

            unsigned char digest[CC_MD5_DIGEST_LENGTH];
            
            CC_MD5( data.bytes, (CC_LONG)data.length, digest );
            
            NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
            
            for( int i = 0; i < CC_MD5_DIGEST_LENGTH; i++ )
            {
                [output appendFormat:@"%02x", digest[i]];
                
            }
            NSLog(@"視頻的MD5:%@",output);
        });
    }];

}
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容