Create MPEG-2 Transmission Stream with AVFoundation

I am trying to create a properly formatted video file for use in Apple HTTP Live Streaming. Here is the code that creates the file:

// 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]returns valid NSURL, the file is successfully saved to disk, and I can open and view the file in VLC and QuickTime. The video format in VLC is "avc1", which I find the same as H.264 . The QuickTime video format is H.264. The file extension is, of course, .ts.

It seems that I am doing everything right, but when I try to check my HTTP stream with mediastreamvalidator, I get the following error:

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

Does anyone know what I can do wrong?

+3
source share
1 answer

MPEG-2, , MPEG-4, .ts. VLC QuickTime , mediastreamvalidator , MPEG-2 TS. , TS MPEG-2, - . 0x47, MPEG-2 TS.

+3

All Articles