2011-08-17 92 views
5

我想盡可能快地找到從iPhone(iOS5)上傳視頻的最佳方式 - 如果可能,請實時上傳。近iPhone上的實時視頻上傳

我發現這個以前的問題和答案非常有用。
streaming video FROM an iPhone

但它給我留下了幾個未解答的問題。我沒有足夠的代表在這個問題上發表評論 - 我認爲我的問題無論如何都超出了原始問題的範圍。

所以:

  1. 是使用AVCaptureSession/AVAssetWriter和切碎的視頻轉換成短片迅速移動(壓縮)視頻關閉iPhone的最佳途徑 - 以接​​近實時?

  2. 如果有人能提供更多關於如何使用兩個AVAssetWriters和背景隊列以避免丟失的細節(正如用戶Steve McFarlin在上面引用的問題中提到的那樣)?我不清楚如何從一個AVAssetWriter切換到另一個會工作...

  3. (關鍵)是否有一種簡單的方法來將切碎的視頻文件追加到全長視頻......或至少能夠玩他們就好像他們是一個完整的視頻?我需要合併較小的文件,使其看起來像服務器和iPhone上的一個文件(用於預覽)。

感謝您的幫助......

+0

你不能在公開場合提出這些問題。正如你是)引人注目的iOS開發者打破他們與蘋果公司的NDA,以及b)如果你自己也是一個付費的iOS開發者,那麼與蘋果公司打破你的NDA。將您的iOS 5開發職位限制在官方**私人**和**機密** Apple主辦的論壇中是明智/謹慎的做法。 – twilson

+0

如果您不是付費的iOS開發人員,那麼您就沒有地方使用iOS 5 beta SDK,並且必須等到Apple發佈iOS 5正式版! – twilson

回答

4

那麼你可以嘗試做手機上的緩衝,但似乎適得其反對我來說,因爲它的內存有限。我會嘗試設置一個AVCaptureSession,並使用AVCaptureVideoDataOutput,它將在單獨的dispatch_queue線程上向您銷售幀(如果安裝它會將它們作爲MPEG幀出售)。該線程可以將幀交給異步套接字進行傳輸,可能會使用指示幀編號和視頻格式的小標題。或者,您也可以通過隊列將數據發送到發送線程,以便監視有多少幀正在等待傳輸。

在接收服務器上,您希望處理創建一個小緩衝區(比如幾秒鐘),並在幀順序顛簸時執行幀重新排序。

最大的問題將是檢測帶寬並知道何時降低質量,因此您不會結束積壓的數據包等待外出。這是一個完全不同而又複雜的話題:)如果編解碼器,質量和視頻大小......將直接決定實時傳輸幀所需的帶寬,那麼將選擇關鍵。在某些模式下,AVVideoCodecH264在硬件中得到支持,並且可能是實時編碼的唯一現實選擇。

我不認爲你會找到一個現成的例子,雖然它代表了很多工作,才能正確工作。

+0

是否有任何propper api讀取媒體片段數據和檢索時間戳, –

0

2)這裏就是我如何分塊的文件,從而無需太多的框架:

- (void) segmentRecording:(NSTimer*)timer { 
    AVAssetWriter *tempAssetWriter = self.assetWriter; 
    AVAssetWriterInput *tempAudioEncoder = self.audioEncoder; 
    AVAssetWriterInput *tempVideoEncoder = self.videoEncoder; 
    self.assetWriter = queuedAssetWriter; 
    self.audioEncoder = queuedAudioEncoder; 
    self.videoEncoder = queuedVideoEncoder; 
    //NSLog(@"Switching encoders"); 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ 
     [tempAudioEncoder markAsFinished]; 
     [tempVideoEncoder markAsFinished]; 
     if (tempAssetWriter.status == AVAssetWriterStatusWriting) { 
      if(![tempAssetWriter finishWriting]) { 
       [self showError:[tempAssetWriter error]]; 
      } 
     } 
     if (self.readyToRecordAudio && self.readyToRecordVideo) { 
      NSError *error = nil; 
      self.queuedAssetWriter = [[AVAssetWriter alloc] initWithURL:[self newMovieURL] fileType:(NSString *)kUTTypeMPEG4 error:&error]; 
      if (error) { 
       [self showError:error]; 
      } 
      self.queuedVideoEncoder = [self setupVideoEncoderWithAssetWriter:self.queuedAssetWriter formatDescription:videoFormatDescription bitsPerSecond:videoBPS]; 
      self.queuedAudioEncoder = [self setupAudioEncoderWithAssetWriter:self.queuedAssetWriter formatDescription:audioFormatDescription bitsPerSecond:audioBPS]; 
      //NSLog(@"Encoder switch finished"); 

     } 
    }); 
} 

https://github.com/chrisballinger/FFmpeg-iOS-Encoder/blob/master/AVSegmentingAppleEncoder.m

3)這裏有一個腳本來連接服務器

import glob 
import os 
run = os.system # convenience alias 


files = glob.glob('*.mp4') 
out_files = [] 

n = 0 
for file in files: 
    out_file = "out-{0}.ts".format(n) 
    out_files.append(out_file) 
    full_command = "ffmpeg -i {0} -f mpegts -vcodec copy -acodec copy -vbsf h264_mp4toannexb {1}".format(file, out_file) 
    run(full_command) 
    n += 1 

out_file_concat = '' 
for out_file in out_files: 
    out_file_concat += ' {0} '.format(out_file) 

cat_command = 'cat {0} > full.ts'.format(out_file_concat) 
print cat_command 
run(cat_command) 
run("ffmpeg -i full.ts -f mp4 -vcodec copy -acodec copy -absf aac_adtstoasc full.mp4") 

https://github.com/chrisballinger/FFmpeg-iOS-Encoder/blob/master/concat-mp4.py上的文件

+0

嘿,如何訪問這些分塊的段和流與nssstream到服務器,然後到其他iOS設備? – sajwan

+0

如果'assetWriter'成功完成了寫作,那麼您是否可以進行委託調用以上傳片段,然後在停止錄製上傳最後?或者我錯過了什麼? – HighFlyingFantasy