I am trying to save a video file from an iphone camera using the following code:
class Camera { ... private func loadDeviceInput() { let devices = AVCaptureDevice.devices() as! [AVCaptureDevice] for device in devices { if device.hasMediaType(AVMediaTypeVideo) { if device.position == .Back { _deviceBack = device _inputBack = try? AVCaptureDeviceInput(device: device) } else if device.position == .Front { _deviceFront = device _inputFront = try? AVCaptureDeviceInput(device: device) } } else if device.hasMediaType(AVMediaTypeAudio) { _inputAudio = try? AVCaptureDeviceInput(device: device) } } } private func loadDeviceOutput() { _outputStill = AVCaptureStillImageOutput() _outputStill?.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG] if _session.canAddOutput(_outputStill) { _session.addOutput(_outputStill) } _outputAudio = AVCaptureAudioDataOutput() if _session.canAddOutput(_outputAudio) { _session.addOutput(_outputAudio) } _outputVideo = AVCaptureMovieFileOutput() _outputVideo?.movieFragmentInterval = CMTimeMake(1, 1)
and while it works, but when I play the video using AVPlayer, the sound does not play. If I try a video with Quiktime, with the same problem, no sound. BUT, when I open it using VLC, the sound is reproduced.
For reference, this is how I play a video that works, but without sound:
player = AVPlayer(URL: v) player.actionAtItemEnd = .None player.muted = false player.volume = 1 player.play()
I watched the video using ffprone :
$ ffprobe test4.mp4 ffprobe version 2.8.1 Input
I have no idea what is wrong, could you help me?
thanks
jrmgx source share