音視頻開發

command + s 截模擬器的屏幕

MP.4只是一個容器 ? ? H.264 H.263是真正的格式 H.265正在測試中

avi H.264 H.263

?

視頻解碼:將H.263? H.264轉換為視頻和音頻的格式

視頻編碼:

?

?解碼:硬解碼:GPU做的解碼 ? ? CPU做除了圖片以外的,其他的處理? ? GPU(解碼的效率特別快)顯卡上帶的 和圖片有關

? ? ? 軟解碼:CPU做的解碼(前提是GPU不能做相應的解碼時)

? ? ? 硬解碼比軟解碼強一點


一 、AVPlayer

? 播放視頻? ? 可以播放流媒體 ? 導入兩個庫? CoreMedia? AVFoundation

單獨使用AVPlayer類是無法顯示視頻的,要將視頻層添加值AVPlayerLayer中,這樣才能將視頻顯示出來



NSURL * url = [NSURL fileURLWithPath:path];不是規范的path(NSString)時,使用該方法初始化NSURL


CMTimeGetSeconds(currentTime)轉為秒


?? //AVAudioPlayer->url

? ? //AVPlayer-?AVPlayerItem->AVURLAsset->NSURL

? ? NSString * path = [[NSBundle mainBundle]pathForResource:@"敢死隊3" ofType:@"mp4"];

? ? NSURL * url = [NSURL fileURLWithPath:path];

? ? AVURLAsset *asset = [AVURLAsset assetWithURL:url];

? ? //1、異步 檢測

? ? [asset loadValuesAsynchronouslyForKeys:@[@"tracks"] completionHandler:^{

? ? ? ? //AVPlayerItem

? ? ? ? AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset];

? ? ? ? _player = [[AVPlayer alloc]initWithPlayerItem:item];

? ? ? ? //關聯屏幕和播放器

? ? ? ? [_playerView setPlayer:_player];

?? ? ? ?

? ? ? ? //刷新進度

? ? ? ? //這個方法就是加一個監聽? 每隔這么長時間會再者個線程里面調用這個方法 ? CMTimeMake(<#int64_t value#>, <#int32_t timescale#>)? /每秒

? ? ? ? __weak AVPlayer * player = _player;

? ? ? ? __weak UISlider * slider = _slider;

?? ? ? [ _player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {

? ? ? ? ? ? //當前時間 警告的原因是相互強引用

?? ? ? ? ? CMTime currentTime = player.currentItem.currentTime;

?? ? ? ? ? //總時間

?? ? ? ? ? CMTime duration = player.currentItem.duration;

?? ? ? ? ? //CMTimeGetSeconds? 轉為秒

?? ? ? ? ? float pro = CMTimeGetSeconds(currentTime)/CMTimeGetSeconds(duration);

?? ? ? ? ? [slider setValue:pro animated:YES];

? ? ? ? }];

? ? ? ? }];

?? ?

}

//設置進度

-(void)setProgress

{

? ? CMTime duration = _player.currentItem.duration;//總時間

? ? CMTime currentTime = CMTimeMultiplyByFloat64(duration, _slider.value);

? ? //從當前時間播放

? ? [_player seekToTime:currentTime];

}

-(void)play

{

? ? [_player play];

}

-(void)pause

{

? ? [_player pause];

}




二、MPMoviePlayerController? 視頻播放器 不能播放流媒體

需要導入MediaPlayer庫

?MPMoviePlayerViewController * _playerController;//不能播放流媒體 流媒體可以想一想直播


- (IBAction)buttonClick:(UIButton *)sender {

? ? NSString * path = [[NSBundle mainBundle]pathForResource:@"敢死隊3" ofType:@"mp4"];

? ? NSURL * url = [NSURL fileURLWithPath:path];

? ? _playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];

? ? [self presentMoviePlayerViewControllerAnimated:_playerController];

?? ?

}





三、AVAudioPlayer? 音頻播放器 引入AVFoundition

- (void)viewDidLoad {

? ? [super viewDidLoad];


? ? NSString* path = [[NSBundle mainBundle] pathForResource:@"Beat It" ofType:@"mp3"];

? ? NSURL* url = [NSURL fileURLWithPath:path];

? ? _player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

? ? //準備播放

? ? [_player prepareToPlay];

? ? //變速

? ? [_player setEnableRate:YES];

? ? //峰值和平均值監測

? ? [_player setMeteringEnabled:YES];

}


//刷新

- (void)refresh{

? ? //進度 = 當前時間 / 總時間

? ? [_proSlider setValue:_player.currentTime/_player.duration animated:YES];

?? ?

? ? //刷新峰值平均值

? ? [_player updateMeters];

? ? //平均值

? ? float avg = [_player averagePowerForChannel:0];

? ? //峰值

? ? float peak = [_player peakPowerForChannel:0];

? ? //NSLog(@"%f, %f", avg, peak);

? ? [_pv1 setProgress: (avg + 30) / 30 animated:YES];

? ? [_pv2 setProgress: (peak + 30) / 30 animated:YES];

}


//播放

- (void)play:(id)sender{

? ? [_player play];

? ? if (_timer == nil) {

? ? ? ? _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(refresh) userInfo:nil repeats:YES];

? ? }

}


//暫停

- (void)pause:(id)sender{

? ? [_player pause];

? ? if (_timer) {

? ? ? ? [_timer invalidate];

? ? ? ? _timer = nil;

? ? }

}


//設置進度

- (IBAction)setProgress:(id)sender{

? ? //當前時間 = 總時間 * 百分比

? ? UISlider* slider = sender;

? ? _player.currentTime = _player.duration * slider.value;

}

//設置音量

- (IBAction)setVolume:(id)sender{

? ? UISlider* slider = sender;

? ? _player.volume = slider.value;

}

//設置聲道

- (IBAction)setPan:(id)sender{

? ? UISlider* slider = sender;

? ? _player.pan = slider.value;

}

//設置速度

- (IBAction)setRate:(id)sender{

? ? UISlider* slider = sender;

? ? _player.rate = slider.value;

}



四、AVAUdioRecorder? 錄音? 引入AVFoundition系統庫

? //錄音設置

? ? NSMutableDictionary * recordSetting = [[NSMutableDictionary alloc]init];

? ? //設置錄音格式? AVFormatIDKey == kAudioFormatLinearPCM

? ? [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];

? ? //設置錄音采用率(Hz)如:AVSampleRateKey == 8000/44100/96000(影響音頻質量)

? ? [recordSetting setValue:[NSNumber numberWithFloat:44100] forKey:AVSampleRateKey];

? ? //錄音通道數 1 2

? ? [recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];

? ? //線性采樣位數 8.1624.32

? ? [recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];

? ? //錄音質量

? ? [recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey];

? ? _recorder = [[AVAudioRecorder alloc]initWithURL:url settings:recordSetting error:nil];

? ? [_recorder prepareToRecord];


-(void)startRecord

{

? ? [_button setTitle:@"錄音中" forState:UIControlStateNormal];

? ? [_recorder record];

}

-(void)stopRecord

{

? ? [_button setTitle:@"錄音" forState:UIControlStateNormal];

? ? [_recorder stop];

? ? NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Document/a.aac"];

? ? NSURL * url = [NSURL fileURLWithPath:path];

? ? NSLog(@"錄音路徑%@",path);

? ? _player = [[AVAudioPlayer alloc]initWithContentsOfURL:url

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? error:nil];

? ? [_player prepareToPlay];

? ? [_player play];

}


本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/458609.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/458609.shtml
英文地址,請注明出處:http://en.pswp.cn/news/458609.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

10.11 安裝pod

原文地址&#xff1a;http://www.jianshu.com/p/5fc15906c53a 感謝。 更新升級10.11 cocoapods安裝出問題最簡單的解決方法 這是因為10.11把cocoapods直接干掉了 sudo gem install -n /usr/local/bin cocoapods 再加一句&#xff0c;完美解決 sudo xcode-select --switch /App…

windows任務管理器中的工作設置內存,內存專用工作集,提交大小詳解

通俗的講工作設置內存是程序占用的物理內存(包含與其他程序共享的一部分), 內存專用工作集是程序獨占的物理內存, 提交大小是程序獨占的內存(包含物理內存和在頁面文件中的內存). 注:頁面文件就是存放不在物理內存中的內存,文件路徑一般在C:\pagefile.sys,目的是為了能夠讓更…

coreData mapView #include

一、coreData 需要導入系統庫CoreData 新建文件的時候選core data 中的Data Model 然后加相應的表 加完表后 在Model.xcdatamodeld中新建文件 選coredata中的第三個 即可 如果兩個表有聯系 就將附表放到主表中 在build Setting中&#xff0c;輸入search 在Framework Searc…

淺談 C++ 中的 new/delete 和 new[]/delete[]

來自&#xff1a;http://www.cnblogs.com/hazir/p/new_and_delete.html 在 C 中&#xff0c;你也許經常使用 new 和 delete 來動態申請和釋放內存&#xff0c;但你可曾想過以下問題呢&#xff1f; new 和 delete 是函數嗎&#xff1f;new [] 和 delete [] 又是什么&#xff1f…

JavaScript中的原型繼承原理

在JavaScript當中&#xff0c;對象A如果要繼承對象B的屬性和方法&#xff0c;那么只要將對象B放到對象A的原型鏈上即可。而某個對象的原型鏈&#xff0c;就是由該對象開始&#xff0c;通過__proto__屬性連接起來的一串對象。__proto__屬性是JavaScript對象中的內部屬性&#xf…

XMPP

XMPP不支持視頻聊天 支持文字聊天 但對于圖片和語音聊天支持的不好 那么就將他們轉成NSData的形式 IM Instance Message 即時聊天 聊天系統中 XMPP主要做兩個人的聊天和群聊&#xff0c;只用了這兩個功能 還有一個HTTP的服務器 &#xff0c;他是一個旁路服務器 XMPP底層…

QT 調試

QT調試&#xff08;參考下面的說明就可以正常調試&#xff09;&#xff1a;http://blog.csdn.net/wchengshen/article/details/50254731http://blog.csdn.net/sx341125/article/details/53606534 QT調用DLL&#xff1a; Qt中調用VS編譯dll的方法(一)----顯式調用 qt使用動態庫(…

建模元件有哪些在MapleSim中

信號庫&#xff1a;包含通用信號模塊、布爾、控制器、離散信號模塊、信號源、線性信號模塊、非線性信號模塊、時間離散信號模塊、查詢表、信號轉換器、數學運算、關系元件、特殊信號模塊&#xff0c;應用案例。 電子庫&#xff1a;包含電阻、運算放大器、二極管、步進電機、模擬…

iOS小筆記

controller&#xff1a;連接二者的橋梁&#xff1b;cocoa frameworks 有兩個框架&#xff1a;foundationfoundation 是cocoa中最基本的一些類&#xff1b;再mac應用程序中負責對象管理&#xff0c;內存管理&#xff0c;容器等相關數據&#xff1b;uikit&#xff1a;uikit&…

【C++】VS2010將寫好的程序打包成安裝文件發布

參考鏈接&#xff1a;http://blog.csdn.net/yongh701/article/details/51326142 我們可以將自己寫好的VS2010程序打包成安裝文件&#xff0c;給用戶安裝&#xff0c;具體步驟如下&#xff1a; 1、如下圖&#xff0c;同樣是新建一個項目&#xff0c;但是這次是新建一個其它項目…

01_jeecms建站

一、環境安裝 JDK5TOMCAT5.5MYSQL5及以上http://www.jeecms.com/tutorial/index.jhtml參考環境安裝篇二、解壓文件安裝包jeecms-v5zip,如圖圖1ROOT文件夾復制放到tomcat下的webapps文件夾&#xff08;注&#xff1a;請先刪除webapps下原有的默認ROOT文件夾&#xff09;如不想部…

WiFi基本知識

轉自&#xff1a;http://blog.csdn.net/myarrow/article/details/7930131 1. IE802.11簡介 標準號IEEE 802.11bIEEE 802.11aIEEE 802.11gIEEE 802.11n標準發布時間1999年9月1999年9月2003年6月2009年9月工作頻率范圍2.4&#xff0d;2.4835GHz 5.150&#xff0d;5.350GHz5.475&a…

iOS各種小理論知識

Objective-C 部分 1. 你如何理解 OC 的內存管理 OC 內存管理是基于引用計數。誰想使用某個對象 B,就要把對象 B 的計數器1,如果不 使用這個對象了,那么就把對象 B 計數器-1,如果 B 對象計數器減到 0,那么 B 對象自動會調用自己的 dealloc 函數,也就是這個對象被銷毀。 一…

libev 宏展開

想看源碼&#xff0c;宏太多&#xff0c;看著累&#xff0c;宏展開&#xff0c;再看&#xff0c;功力時間不夠&#xff0c;先放下 放上宏展開后的代碼。 libev4.20 展開方示為 ./configure 修改makefile文件&#xff0c;字符串 替換CC為 CPP 注意要把基礎的CC定義保留 make mv …

FreeRTOS高級篇7---FreeRTOS內存管理分析

原文&#xff1a;http://blog.csdn.net/zhzht19861011/article/details/51606068 內存管理對應用程序和操作系統來說都非常重要。現在很多的程序漏洞和運行崩潰都和內存分配使用錯誤有關。 FreeRTOS操作系統將內核與內存管理分開實現&#xff0c;操作系統內核僅規定了必要的內…

筆試題

1.是不是一個父類寫了一個virtual 函數&#xff0c;如果子類覆蓋它的函數不加virtual ,也能實現多態? virtual修飾符會被隱形繼承的。private 也被集成&#xff0c;只事派生類沒有訪問權限而已。virtual可加可不加。子類的空間里有父類的所有變量(static除外)。同一個函數只存…

FreeRTOS學習筆記——互斥型信號量

來自&#xff1a;http://blog.csdn.net/xukai871105/article/details/43456985 0.前言 在嵌入式操作系統中互斥型信號量是任務間資源保護的重要手段。下面結合一個具體例子說明FreeRTOS中的互斥型信號量如何使用。 【相關博文】 【FreeRTOS STM32移植筆記】 【FreeRTOS學習筆記…

JSP動態網站環境搭建應用中的詳細步驟(Tomcat和Apache/IIS的整合)

鏈接地址&#xff1a;http://www.cnblogs.com/dartagnan/archive/2011/03/25/2003426.html JSP動態網站環境搭建應用中的詳細步驟(Tomcat和Apache/IIS的整合)sun推出的JSP&#xff08;Java Server Pages&#xff09;是一種執行于服務器端的動態網頁開發技術&#xff0c;它基于J…

關于JS獲取select值的兩種實現方法

前幾天發了一篇關于javascript獲取select值的方法&#xff0c;后來發現有另一種實現方法&#xff0c;所以就都發出來比較一下&#xff1a; 方法一&#xff1a;通過獲取option標簽的value值來確定&#xff1a; <!DOCTYPE html> <html> <head><meta charset…

c語言題庫1

1. 用預處理指令#define 聲明一個常數&#xff0c;用以表明1年中有多少秒&#xff08;忽略閏年問題&#xff09; #define time (365*24*60*60) #define SECONDS_PER_YEAR (60 * 60 * 24 * 365) 2. 寫一個“標準”宏MIN&#xff0c;這個宏輸入兩個參數并返回較小的一個。 #di…