从 iPhone 近实时上传视频
我正在尝试找到尽可能快地从 iPhone (iOS5) 上传视频的最佳方法 - 如果可能的话实时上传。
我发现之前的问题和答案非常有用。
从 iPhone 流式传输视频
但这给我留下了几个未解答的问题。我没有足够的代表在该问题中发表评论 - 而且我认为我的问题无论如何都超出了原始问题的范围。
那么:
使用 AVCaptureSession/AVAssetWriter 并将视频切成短片是快速从 iPhone 上移动(压缩)视频的最佳方式吗 - 近乎实时?
如果是这样,有人可以提供有关如何使用两个 AVAssetWriter 和后台队列来避免丢失的更多详细信息(正如用户 Steve McFarlin 在上面引用的问题中提到的那样)?我不清楚从一个 AVAssetWriter 到另一个 AVAssetWriter 的切换是如何工作的...
(关键)是否有一种简单的方法可以将切碎的视频文件附加回完整长度的视频...或者至少能够播放它们好像它们是一个完整的视频?我需要合并较小的文件,使其在服务器和 iPhone 上看起来都像一个文件(用于预览)。
感谢您的帮助...
I am trying to find the best way to upload video from an iPhone (iOS5) as fast as possible - real time if possible.
I found this previous question and answer very useful.
streaming video FROM an iPhone
But it has left me with several unanswered questions. I dont have enough rep to post comments in that question- and I think my questions are getting beyond the scope of the original question anyway.
So:
Is using AVCaptureSession/AVAssetWriter and chopping the video into short clips the best way to rapidly move (compressed) video off of the iPhone - in near realtime?
If so could someone supply more details on how to use two AVAssetWriters and a background queue to avoid dropouts (as user Steve McFarlin mentions in the referenced question above)? I am unclear how the handoff from one AVAssetWriter to another would work...
(Critical) Is there an easy way to append the chopped video files back into a full length video... or at least be able to play them as if they were one complete video? I would need to merge the smaller files to look like one file both on the server AND on the iPhone (for preview).
Thanks for any help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您可以尝试在手机上进行缓冲,但这对我来说似乎适得其反,因为它的内存有限。我会尝试设置 AVCaptureSession 并使用 AVCaptureVideoDataOutput ,它将在单独的dispatch_queue线程上将帧出售给您(如果设置,它将作为 MPEG 帧出售它们)。该线程可以将帧交给异步套接字进行传输,可能带有一个指示帧编号和视频格式的小标头。或者,您可以通过队列将数据交给发送线程,这将让您监视有多少帧正在等待传输。
在接收服务器上,您需要创建一个小缓冲区(例如几秒钟),并在帧不按顺序到达时对帧进行重新排序。
最大的问题是检测带宽并知道何时降低质量,这样您就不会出现积压的数据包等待发送的情况。这是一个完全不同且复杂的主题:) 关键在于您选择编解码器、质量和视频大小……这将直接确定实时传输帧所需的带宽。 AVVideoCodecH264 在某些模式下受硬件支持,并且可能是实时编码的唯一现实选择。
我认为您不会为此找到现成的示例,因为它需要大量工作才能正常工作。
Well you can try to do the buffering on the phone but that seems counter-productive to me, given that it has limited memory. I would try setting up an AVCaptureSession and use the AVCaptureVideoDataOutput which will vend the frames to you on a separate dispatch_queue thread (if setup it will vend them as MPEG frames). That thread can hand the frames off to an async socket to transmit, possibly with a small header that indicates the frame number and video format. Alternately you can hand the data off to a sending thread via a queue which would let you monitor how many frames are waiting to be transmitted.
On the receiving server, you'd want to deal with creating a small buffer (say a few seconds) and doing the frame reordering if they arrive out of order.
The big issue will be detecting the bandwidth and knowing when to drop the quality down so you don't end up with a backlog of packets waiting to go out. That's an entirely different and complicated topic :) The key will be in your selection if codec, quality, and video size... that is going to directly determine the bandwidth required to transmit the frames in real-time. AVVideoCodecH264 is supported in hardware in certain modes and is probably the only realistic option for real-time encoding.
I don't think you are going to find a ready-made example for this though as it represents a lot of work to get working just right.
2)以下是我如何在不丢失太多帧的情况下对文件进行分块:
https ://github.com/chrisballinger/FFmpeg-iOS-Encoder/blob/master/AVSegmentingAppleEncoder.m
3) 这是一个用于连接服务器上的文件
https://github.com/chrisballinger /FFmpeg-iOS-Encoder/blob/master/concat-mp4.py
2) Here's how I chunked the files without dropping too many frames:
https://github.com/chrisballinger/FFmpeg-iOS-Encoder/blob/master/AVSegmentingAppleEncoder.m
3) Here's a script to concatenate the files on the server
https://github.com/chrisballinger/FFmpeg-iOS-Encoder/blob/master/concat-mp4.py