【问题标题】:How to store video on iPhone while publishing video with RTMPStreamPublisher?使用 RTMP Stream Publisher 发布视频时如何在 iPhone 上存储视频?
【发布时间】:2013-12-07 04:51:48
【问题描述】:

现在我正在使用RTMPStreamPublisher 在 wowzaserver 上发布视频。它正在那里成功上传,但是谁能告诉我如何在 iPhone 上存储相同的视频,同时上传到服务器?

我正在使用https://github.com/slavavdovichenko/MediaLibDemos,但没有太多可用的文档。如果我可以只存储发送用于发布的数据,那么我的工作将会成功。

这是他们用来上传视频流的方法,但我找不到在我的 iPhone 设备上存储相同视频的方法:

// ACTIONS

-(void)doConnect {
#if 0 // use ffmpeg rtmp 
    NSString *url = [NSString stringWithFormat:@"%@/%@", hostTextField.text, streamTextField.text];
    upstream = [[BroadcastStreamClient alloc] init:url  resolution:RESOLUTION_LOW];
    upstream.delegate = self;
    upstream.encoder = [MPMediaEncoder new];
    [upstream start];
    socket = [[RTMPClient alloc] init:host]
    btnConnect.title = @"Disconnect";     
    return;
#endif

#if 0 // use inside RTMPClient instance
    upstream = [[BroadcastStreamClient alloc] init:hostTextField.text resolution:RESOLUTION_LOW];
    //upstream = [[BroadcastStreamClient alloc] initOnlyAudio:hostTextField.text];
    //upstream = [[BroadcastStreamClient alloc] initOnlyVideo:hostTextField.text resolution:RESOLUTION_LOW];

#else // use outside RTMPClient instance

    if (!socket) {
        socket = [[RTMPClient alloc] init:hostTextField.text];
        if (!socket) {
            [self showAlert:@"Socket has not be created"];
            return;
        }
        [socket spawnSocketThread];
   }
    upstream = [[BroadcastStreamClient alloc] initWithClient:socket resolution:RESOLUTION_LOW];
#endif

    [upstream setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
    //[upstream setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
    //[upstream setVideoBitrate:512000];
    upstream.delegate = self;
    [upstream stream:streamTextField.text publishType:PUBLISH_LIVE];
    //[upstream stream:streamTextField.text publishType:PUBLISH_RECORD];
    //[upstream stream:streamTextField.text publishType:PUBLISH_APPEND];
    btnConnect.title = @"Disconnect";     
}

我确实发现BroadcastStreamClient 的实例被命名为“上游”,我可以通过以下行获得AVCaptureSession

[upstream getCaptureSession];

如何使用AVCaptureSession 在 iPhone 上录制视频?

【问题讨论】:

  • 要将设备作为文件存储在您的 iOS 设备上,我猜您需要特定的代码来执行此操作。 Wowza 是一个流媒体服务器,所以你不会用它来下载文件。由于我对 iOS 不熟悉,所以无法提供答案。
  • thanx 的答案..但是我在 sn-p 中给出的代码不是 wowza 的.. 我刚刚从 Github 找到了那个库,并且只使用 rtmp。
  • 嗨 Bhavik Kama,您能否提供使用 MedialIb 将 iOS 视频流式传输到 wowza 的示例代码。我正在尝试示例,但我只能从我的 ios 程序中看到与 wowza 建立的连接,无法理解如何进一步将视频流式传输到 wowza。
  • 你可以在这里找到示例代码github.com/slavavdovichenko/MediaLibDemos/tree/master/…
  • 嗨 Bhavik Kama,不幸的是,这不是流式传输视频到 wowza,但它能够建立连接。我在我的 iOS 设备上成功运行 RTMPStreamPublisher。现在,我可以点击 Connect it 以成功连接 Wowza。美好的。接下来,切换相机和开始按钮等选项仍然是灰色的。因此,我在 MainStoryBoard 中启用了这些按钮并运行此应用程序。连接成功后,如果我点击“开始”按钮,不知道后面发生了什么,是否将现场录制的视频流到Wowza,

标签: ios iphone objective-c rtmp avcapturesession


【解决方案1】:

获得AVCaptureSession 后,您可以向其中添加AVCaptureMovieFileOutput 的实例,如下所示:

AVCaptureMovieFileOutput *movieFileOutput = [AVCaptureMovieFileOutput new];
if([captureSession canAddOutput:movieFileOutput]){
    [captureSession addOutput:movieFileOutput];
}

// Start recording
NSURL *outputURL = …
[movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];

来源: https://www.objc.io/issues/23-video/capturing-video/

为了更好地了解如何使用AVCaptureFileOutput,还请查看此内容:https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureFileOutput_Class/index.html#//apple_ref/occ/cl/AVCaptureFileOutput

【讨论】:

    【解决方案2】:

    当您从相册中选择视频或录制视频时尝试此操作。或者在 didFinishPickingMediaWithInfo 方法中

    NSURL __block *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
    
    NSString *moviePath = [videoUrl path];
    
    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
                 UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
     }
    

    【讨论】:

      【解决方案3】:

      只要您的对象符合<NSCoding> 协议(许多集合类型已经符合此协议),您就可以使用 NSKeyedArchiver 缓存视频。此缓存目录会定期清除

      http://khanlou.com/2015/07/cache-me-if-you-can/

      或者更好的选择可能是使用NSTemporaryDirectory() 在本地存储您的临时视频文件(这是NSPathUtilities 的一部分)。 AVAssetExportSession 应该允许您将视频文件放在那里:

      AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
      exportSession.outputURL = outputFileURL;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-04
        相关资源
        最近更新 更多