我正在尝试创建一个格式正确的视频文件以用于 Apple 的 HTTP Live Streaming。这是创建文件的代码:
// 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' 我收集到的与 H.264 相同。在 QuickTime 中查看的视频格式是 H.264。文件的扩展名当然是 .ts。
看来我做的一切都是正确的,但是当我尝试使用 验证我的 HTTP Live 流时mediastreamvalidator
,我收到以下错误:
http://imac.local.:2020/fileSequence000.ts:
ERROR: (-12971) failed to parse segment as either an MPEG-2 TS or an ES
任何人都知道我可能做错了什么?