3

Apple의 HTTP 실시간 스트리밍에서 사용할 올바른 형식의 비디오 파일을 만들려고합니다. 여기에 파일을 생성하는 코드입니다 :AVFoundation을 사용하여 MPEG-2 전송 스트림 만들기

// 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 

누구나 알고있는 일을 할 수있다?

답변

3

주어진 코드는 MPEG-2 전송 스트림을 생성하지 않고 표준 MPEG-4 파일을 생성하지만 확장자는 .ts입니다. VLC와 QuickTime은 파일을 인식하고 재생할 수 있지만 mediastreamvalidator는 MPEG-2 TS가 아니라는 사실을 올바르게 알려줍니다. 생성 된 파일이 MPEG-2 TS인지 확인하는 빠른 방법은 첫 번째 바이트를 보는 것입니다. 0x47이 아닌 경우 MPEG-2 TS가 아닙니다.