Question

I'm attempting to create a properly formatted video file for use in Apple's 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];

The [self nextOutputURL] returns a valid NSURL, the file is successfully saved to disk and I can open and view the file in VLC and QuickTime. The video format as viewed in VLC is 'avc1' which I gather is the same as H.264. The video format as viewed in QuickTime is H.264. The extension on the file is, of course, .ts.

It appears that I'm doing everything correctly, yet when I try and validate my HTTP Live 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

Anyone know what I may be doing wrong?

Était-ce utile?

La solution

The given code doesn't generate a MPEG-2 Transport Stream, rather, it generates a standard MPEG-4 file, but with a .ts extension. VLC and QuickTime will both recognize the file and are able to play it, but mediastreamvalidator correctly notes that it is not an MPEG-2 TS. A quick way to check if the generated file is a MPEG-2 TS is to look at the first byte. If it is not 0x47, then it won't be a MPEG-2 TS.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top