2016-01-21 12 views
6

ile videoyu kaydettikten sonra oynanır bunu aşağıdaki kodla iphone kameradan bir video dosyasını kaydetmeyi deneyin:hiçbir ses AVCaptureMovieFileOutput

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) // Save file header every second 

    if _session.canAddOutput(_outputVideo) { 
     _session.addOutput(_outputVideo) 
    } 
} 

func startVideoCapture(writeTo file: NSURL, startedBlock: JrmgxNSURLResultBlock, stopedBlock: JrmgxNSURLResultBlock) { 
    isSessionRunning() 

    prepareForVideoCapture() 
    _startVideoCaptureBlock = startedBlock 
    _stopVideoCaptureBlock = stopedBlock 

    if _outputVideo?.connectionWithMediaType(AVMediaTypeVideo)?.active ?? false == true { 
     _outputVideo?.startRecordingToOutputFileURL(file, recordingDelegate: self) 
    } 
    else { 
     // ERROR 
    } 
} 

... 
} 

ve şimdiye kadar bu çalışıyor, ancak ben AVPlayer kullanarak videoyu oynatırken ses çalınmıyor. Eğer videoyu Quiktime ile, aynı problemle, sessiz olarak denediğimde. AMA VLC ile açtığımda, ses çalıyor. ,

$ ffprobe test4.mp4 
ffprobe version 2.8.1 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test4.mp4': 
    Metadata: 
    major_brand  : qt 
    minor_version : 0 
    compatible_brands: qt 
    creation_time : 2016-01-21 13:13:55 
    Duration: 00:00:06.37, start: 0.000000, bitrate: 818 kb/s 
    Stream #0:0(und): Video: h264 (Baseline) (avc1/0x31637661), yuv420p(tv, smpte170m/bt709/bt709), 480x360, 741 kb/s, 30.01 fps, 30 tbr, 600 tbn, 1200 tbc (default) 
    Metadata: 
     rotate   : 90 
     creation_time : 2016-01-21 13:13:55 
     handler_name : Core Media Video 
    Side data: 
     displaymatrix: rotation of -90.00 degrees 
    Stream #0:1(und): Audio: aac (LC) (mp4a/0x6134706D), 44100 Hz, mono, fltp, 62 kb/s (default) 
    Metadata: 
     creation_time : 2016-01-21 13:13:55 
     handler_name : Core Media Audio 

yanlış olduğunu hiçbir fikrim yok:

player = AVPlayer(URL: v) 
player.actionAtItemEnd = .None 
player.muted = false 
player.volume = 1 
player.play() 

Ben ffprone ile videoyu teftiş:

Başvuru için bu ben ama hiçbir ses ile çalışan video böyle oynanır Bana yardım edebilir misin?

Eğer

+1

Dosyanın NSURL'sini video.mp4'den video.mov'a değiştirdim ve şimdi ses çalışıyor. Bana nedenini açıklayabilirseniz, yine de takdir edilecektir :) – jrmgx

+0

'AVPlayer',' AvPlayerItem' veya 'AVAsset' için dokümanlar bulamadım, belki de AVPlayer mp4'leri oynatamıyor – MikeG

+0

Bu bilgi size yardımcı olabilir http : //www.differencebetween.net/technology/difference-between-mov-and-mp4/ –

cevap

4

mp4 ve mov dosyaları birbirine çok benzer ancak ince farklara sahip ederiz. Bence VLC, dosyanın aslında bir .mov olduğunu ve buna göre oynandığını, ancak AVPlayer'ın bunu aldığını fark ediyor. video ve belgelerini kaydetmek için AVCaptureMovieFileOutput kullanıyor

devletler:

AVCaptureMovieFileOutput is a concrete sub-class of AVCaptureFileOutput you use to capture data to a QuickTime movie.

standart dosya uzantısı .mov olduğunu ortaya koymaktadır ne QuickTime film içine biraz araştırma:

Save as QuickTime movie – This option will save the embedded video in a *.mov file format no matter what the original container is/was.

Dosyayı bir .mov olarak kaydederseniz, artık sorun olmamalıdır.

+0

Somut bir uygulama için herhangi bir fikri/örneği var mı? Bir mp4 FileOutput? – jrmgx

+0

'' AVCaptureVideoDataOutput''' - mp4’e video kaydetme örneği şu adreste bulunabilir: http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html – Casey

İlgili konular