【问题标题】:App-recorded videos sometimes play no audio when played on phone应用程序录制的视频在手机上播放时有时不播放音频
【发布时间】:2014-12-15 11:26:07
【问题描述】:

我们的应用录制和播放(那些)视频。但不知何故,有些视频播放时没有声音。

如果我通过 iTunes 将视频文件复制到 mac,它会播放有声视频,所以视频确实有声音。

我使用工具(称为 GSpot)检查了视频,它们都具有相同的音频编解码器和比特率。

我尝试了我在 SO 上找到的所有内容,但有些视频不播放音频,而且代码始终相同,而且视频确实有声音,就像在 Mac 上你能听到的那样。

这就是我设置播放器的方式

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[audioSession setActive:YES error:&setCategoryError];
[audioSession setCategory:AVAudioSessionCategoryPlayback
                           error:&setCategoryError];

_mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviepath]];

_mpviewController.moviePlayer.movieSourceType   = MPMovieSourceTypeFile;
_mpviewController.moviePlayer.controlStyle      = MPMovieControlStyleNone;
[_mpviewController.moviePlayer setScalingMode:MPMovieScalingModeAspectFill];

_mpviewController.moviePlayer.shouldAutoplay = YES;

[_mpviewController.moviePlayer prepareToPlay];

_mpviewController.view.frame = CGRectMake(0, 0, _screenWidth, _screenHeight);

[self addSubview:_mpviewController.view];

一段时间后,按下按钮,它开始播放。

录音设置

[_session beginConfiguration];

[_session setSessionPreset: AVCaptureSessionPreset640x480];

AVCaptureDevice * videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
BOOL lock = [videoDevice lockForConfiguration:&error];
if(lock) videoDevice.focusMode = AVCaptureFocusModeContinuousAutoFocus;
[videoDevice unlockForConfiguration];

if(videoDevice == nil){
    assert(0);
}

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if(error){
    assert(0);
}

[_session addInput:input];

AVCaptureDevice *audioDevice        = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput * audioInput   = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];
if(audioInput != nil) {
    [_session addInput:audioInput];
}

[_session commitConfiguration];

我不知道这是否相关,但音频似乎无法在录制期间覆盖不同视图的视频上播放。可以在录制时在视频预览上覆盖全屏视图,它可以很好地录制,并且文件本身有音频,并且它们在 pc/mac 上可以正常播放......仅在我们应用程序内的设备上这些视频(再次,不确定如果相关)没有音频。应用程序对每个视频使用相同的代码,所以我可以重命名它们,交换它们等,行为与视频的音频通道有关。

编辑

补充观察: 没有声音的视频,quicktime(仅在mac上)也不会播放音频。 Windows 上的 QT 确实播放音频,Windows 上的所有其他播放器也播放音频。 手机不知何故损坏了自己的录音,以至于之后它无法识别刚刚录制的音频通道

编辑 2

iPhone 6、iOS 8.1beta 2 -> 如上所述 iPhone 4S、iOS 7.1.2 -> 没有问题 iPad mini,iOS 8.0.2 -> 总是有问题,没有一个视频音频通道可以读取,但始终存在并且 windows 可以播放音频

【问题讨论】:

    标签: ios iphone audio video


    【解决方案1】:

    我想总结一下。

    文件保存为“.mp4”,这会导致偶发错误。 将文件另存为“.mov”有效。相同的编解码器等,但没有错误。

    NSString *path = [[documentsDirectoryPath stringByAppendingPathComponent:
       [NSString stringWithFormat:@"/%@", name]] stringByAppendingString:@".mov"];
    
    outputURL = [[NSURL alloc] initFileURLWithPath:path];
    
    [mAVCaptureMovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
    

    【讨论】:

    • 我在整个互联网上搜索了这个......谢谢你!谢谢..我也把它保存为 .mp4
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多