近实时视频上传从iPhone



我正在寻找从iPhone (iOS5)上传视频的最佳方式,尽可能快-如果可能的话是实时的。

我发现前面的问题和答案非常有用。
iPhone流媒体视频

但这给我留下了几个未解之谜。我没有足够的权限对这个问题发表评论,而且我认为我的问题已经超出了最初问题的范围。

:

  1. 是否使用AVCaptureSession/avassetwwriter并将视频剪切成短片是快速移动(压缩)视频的最佳方式iPhone -在近实时?

  2. 如果是这样,有人可以提供更多的细节如何使用两个AVAssetWriters和一个后台队列,以避免辍学(作为用户Steve McFarlin在上面提到的问题)?我不清楚如何从一个avassetwwriter切换到另一个将工作…

  3. (关键)是否有一种简单的方法将切碎的视频文件附加回完整长度的视频…或者至少能够像播放一个完整的视频一样播放它们?我需要合并较小的文件,使其在服务器和iPhone上看起来像一个文件(预览)。

你可以试着在手机上做缓冲,但这对我来说似乎适得其反,因为它的内存有限。我会尝试设置AVCaptureSession并使用AVCaptureVideoDataOutput,它将在单独的dispatch_queue线程上将帧出售给您(如果设置它将它们作为MPEG帧出售)。该线程可以将帧传递给异步套接字进行传输,可能带有指示帧号和视频格式的小标题。或者你可以通过队列将数据传递给发送线程,这样你就可以监控有多少帧等待传输。

在接收服务器上,您希望处理创建一个小缓冲区(例如几秒钟),并在它们无序到达时进行帧重新排序。

最大的问题将是检测带宽并知道何时降低质量,这样你就不会以等待发送的数据包积压而告终。这是一个完全不同的和复杂的话题:)关键将是在你的选择,如果编解码器,质量和视频大小…这将直接决定实时传输帧所需的带宽。AVVideoCodecH264在某些模式下被硬件支持,并且可能是实时编码的唯一现实选择。

我不认为你会找到一个现成的例子,虽然它代表了大量的工作要得到正确的工作。

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

下面是连接服务器上的文件的脚本
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

最新更新