首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用AVFoundation创建MPEG-2传输流

用AVFoundation创建MPEG-2传输流
EN

Stack Overflow用户
提问于 2012-05-16 07:26:00
回答 1查看 2.4K关注 0票数 4

我正在尝试创建一个格式正确的视频文件,以便在Apple的HTTP Live Streaming中使用。以下是创建该文件的代码:

代码语言:javascript
复制
// Init the device inputs
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil];
AVCaptureDeviceInput *newAudioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self audioDevice] error:nil];

// Create session
AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];
newCaptureSession.sessionPreset = AVCaptureSessionPresetMedium;
self.session = newCaptureSession;

// Add inputs and output to the capture session
if ([newCaptureSession canAddInput:newVideoInput]) {
    [newCaptureSession addInput:newVideoInput];
}
if ([newCaptureSession canAddInput:newAudioInput]) {
    [newCaptureSession addInput:newAudioInput];
}

// Setup the output
AVCaptureMovieFileOutput *aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if ([self.session canAddOutput:aMovieFileOutput])
    [self.session addOutput:aMovieFileOutput];

aMovieFileOutput.maxRecordedDuration = CMTimeMakeWithSeconds(10.f, 1);

// Begin recording
AVCaptureConnection *videoConnection = [self.captureOutput connectionWithMediaType:AVMediaTypeVideo];
if ([videoConnection isVideoOrientationSupported])
    [videoConnection setVideoOrientation:[self calculateVideoOrientation]];

[aMovieFileOutput startRecordingToOutputFileURL:[self nextOutputURL] recordingDelegate:self];

[self nextOutputURL]返回一个有效的NSURL,文件被成功保存到磁盘,我可以在VLC和QuickTime中打开并查看该文件。在VLC中看到的视频格式是'avc1‘,我收集的是the same as H.264。在QuickTime中查看的视频格式为H.264。当然,文件的扩展名是.ts。

看起来我做的一切都是正确的,但是当我尝试用mediastreamvalidator验证我的HTTP Live流时,我得到了以下错误:

代码语言:javascript
复制
http://imac.local.:2020/fileSequence000.ts:
ERROR: (-12971) failed to parse segment as either an MPEG-2 TS or an ES

有人知道我可能做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-26 07:21:12

给定的代码不生成MPEG-2传输流,而是生成标准的MPEG-4文件,但扩展名为.ts。VLC和QuickTime都将识别该文件并能够播放它,但mediastreamvalidator正确地指出它不是MPEG-2TS。检查生成的文件是否为MPEG-2TS的一种快速方法是查看第一个字节。如果它不是0x47,那么它就不是MPEG-2 TS。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10610184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档