【问题标题】:Create MPEG-2 Transfer Stream with AVFoundation使用 AVFoundation 创建 MPEG-2 传输流
【发布时间】:2012-05-15 23:26:00
【问题描述】:

我正在尝试创建格式正确的视频文件以用于 Apple 的 HTTP 实时流媒体。以下是创建文件的代码:

// 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 实时流时,我收到以下错误:

http://imac.local.:2020/fileSequence000.ts:
ERROR: (-12971) failed to parse segment as either an MPEG-2 TS or an ES

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

【问题讨论】:

    标签: avfoundation http-live-streaming avcapturemoviefileoutput


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-02
      • 2013-10-04
      • 1970-01-01
      • 2017-04-07
      相关资源
      最近更新 更多