首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试设置画布宽度和视频宽度,但使用对象objetct回答

尝试设置画布宽度和视频宽度,但使用对象objetct回答
EN

Stack Overflow用户
提问于 2015-09-04 11:26:19
回答 1查看 833关注 0票数 0

我试图修改我正在录制的视频和音频默认设置,但由于任何原因我不知道,它不工作。我一开始就开始记录的是:

代码语言:javascript
复制
started recording audio stream.
sample-rate 48000
buffer-size 4096
started recording [Object Object] stream.
sample-rate 48000
buffer-size 4096

主要问题是返回[Object Object]的“开始录制”。它应该返回宽度和高度大小。似乎我没有正确地设置强制变量。

下面我粘贴我的代码:

代码语言:javascript
复制
var video = $('preview')[0],
    audio,
    fileName,
    replay,
    blob,
    timer,
    streaming,
    isFirefox = !!navigator.mozGetUserMedia,
    recordAudio,
    recordVideo,
    progress,
    upload_bar,
    seconds,
    video_constraints = { mandatory: { minWidth: 1280, minHeight: 720, minFrameRate: 30}, optional: [] };

//If getUserMedia is soported by our browser and we allow to use it, our video tag will show the stream we're recording.
function success(stream) {
    'use strict';

    video = $('#preview')[0];

    video.src = window.URL.createObjectURL(stream);

    video.play();

    video.muted = true;

    if (!isFirefox) {
        window.stream = stream;
    } else {
        audio = document.querySelector('audio');
        streaming = stream;
    }

    $('#start-camara').hide();
    $('#round-record').css('display', 'block');

    $('.record-actions').css('justify-content', 'center');

    setTimeout(function () {
        $('#preview').css('width', 'auto');
    }, 1255);

    $('#round-record > path').on('click', function () {
        if (!isFirefox) {
            $('#splitbar-pause').css('display', 'block');
        }

        if (!video.src) {
            window.alert("there must be an error with your video");
            return;
        } else {
            $('#square-stop').css('display', 'block');
            $('#round-record').css('display', 'none');
        }

        countdown();

        recordAudio = new RecordRTC(stream, {
            // bufferSize: 16384,
            onAudioProcessStarted: function () {
                if (!isFirefox) {
                    recordVideo.startRecording();
                }
            }
        });

        recordVideo = new RecordRTC(stream, {
            type: video_constraints
        });

        recordAudio.startRecording();
    });


}

// Sets a poster error when there's no posibility to load the camera
function error(e) {
    'use strict';

    if (!video.hasAttribute("poster")) {
        video.setAttribute("poster", "img/nocamera.png");
    }
}

// Check the webRTC library compatible with the browser
function checkCompatibility() {
    'use strict';

    return !!(navigator.getUserMedia ||
                 navigator.webkitGetUserMedia ||
                 navigator.mozGetUserMedia ||
                 navigator.msGetUserMedia);
}

function startCamera() {
    'use strict';

    if (!checkCompatibility()) {
        error();
    }

    if (!window.stream && navigator.getUserMedia) {
        navigator.getUserMedia({
            audio: true,
            video: video_constraints
        }, success, error);
    } else {
        error();
    }
}

有人能帮我吗?

谢谢你的建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-04 13:56:21

是的,如果您只想录制视频,recordRTC(stream, options)的第二个参数应该是{type: 'video'}

这里您没有传递这个video参数,所以我认为它试图记录一个可能失败的mandatory

对于录制的视频的限制宽度/高度,选项应该如下所示

代码语言:javascript
复制
var options = {
   type: 'video',  // Mandatory STRING
   video: {
      width: 320,
      height: 240
   },
   canvas: {
      width: 320,
      height: 240
   }
};

var recordVideo = RecordRTC(MediaStream, options);

您甚至可以设置宽度/高度:

代码语言:javascript
复制
var options = {
   type: 'video',     // Mandatory STRING
   width: 1920,
   height: 1280
};

var recordVideo = RecordRTC(MediaStream, options);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32396932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档