如何在asp.net,C#中从网络摄像头捕获视频

时间:2009-09-24 13:53:54

标签: c# asp.net

我需要从asp.net中的网络摄像头捕获视频并将文件保存在sql 2005数据库中,

如何从浏览器捕获网络摄像头中的视频并保存到数据库,请在asp.net,C#中发送有关此内容的任何示例项目或文章或链接。

3 个答案:

答案 0 :(得分:3)

您想使用DirectShow。在SourceForge上查看DirectShow.NET

如果你正在使用Vista,你应该查看未来的平台:Microsoft Media Foundation,它在SourceForge上也有一个.NET library

祝你好运!

答案 1 :(得分:0)

要让这种东西跨浏览器工作,您可能需要查看Flash对象(其中包含用于挂钩用户网络摄像头的工具)和Flash Communication Server的组合,以捕获来自捕获并转换为.flv,你可以保存在某个地方。

答案 2 :(得分:0)

##         是的,我们可以使用bootstrap和html 5在asp.net c#中捕获视频/图像。

我们也可以将视频保存在服务器文件夹或项目文件夹中。

此本文将在chrome / firebox / Opera浏览器上运行。

要保存此Blob视频,请使用新按钮并在c#中编写click事件。

它可以正常工作,

使用以下代码并捕获您的视频.......

谢谢。        ##         

    
         $(document).ready(function () {
                  
                   
                    let preview = document.getElementById("preview");
                    let recording = document.getElementById("recording");
                    let startButton = document.getElementById("startButton");
                    let stopButton = document.getElementById("stopButton");
                    let downloadButton = document.getElementById("downloadButton");
                    let logElement = document.getElementById("log");
    
    
                    let recordingTimeMS = 30000;
                    function log(msg) {
                        logElement.innerHTML += msg + "\n";
                    }
                    function wait(delayInMS) {
    
                        return new Promise(resolve => setTimeout(resolve, delayInMS));
    
                    }
                    function startRecording(stream, lengthInMS) {
                        let recorder = new MediaRecorder(stream);
                        let data = [];
    
                        recorder.ondataavailable = event => data.push(event.data);
                        recorder.start();
                        log(recorder.state + " for " + (lengthInMS / 1000) + " seconds...");
                       
    
                        $('#startButton').attr('disabled', true);
                        $('#stopButton').attr('disabled', false);
                         $('#downloadButton').attr('disabled', true);
                        $('#<%=btnsaven.ClientID%>').attr('disabled', true);
                
                     
    
                        let stopped = new Promise((resolve, reject) => {
                            recorder.onstop = resolve;
                            recorder.onerror = event => reject(event.name);
                        });
    
                        let recorded = wait(lengthInMS).then(
                            () => recorder.state == "recording" && recorder.stop()
                                           
                        );
    
                        return Promise.all([
                            stopped,
                            recorded
                        ])
                            .then(() => data);
                    }
                    function stop(stream) {
                        stream.getTracks().forEach(track => track.stop());
    
                    }
                    startButton.addEventListener("click", function () {
                      
                        navigator.mediaDevices.getUserMedia({
                            video: true,
                            audio: true
                        }).then(stream => {
                            preview.srcObject = stream;
                            downloadButton.href = stream;
                            preview.captureStream = preview.captureStream || preview.mozCaptureStream;
                            return new Promise(resolve => preview.onplaying = resolve);
                        }).then(() => startRecording(preview.captureStream(), recordingTimeMS))
                            .then(recordedChunks => {
                                let recordedBlob = new Blob(recordedChunks, { type: "video/mp4" });
                                recording.src = URL.createObjectURL(recordedBlob);
                                downloadButton.href = recording.src;
                                downloadButton.download = "RecordedVideo.mp4";
                              
    
                                   $('#startButton').attr('disabled', false);
                                    $('#stopButton').attr('disabled', true);
                                    $('#downloadButton').attr('disabled', false);
                                $('#<%=btnsaven.ClientID%>').attr('disabled', false);
    
                              
    
                                var reader = new FileReader();
                                reader.readAsDataURL(recordedBlob);
                                reader.onloadend = function () {
                                    var base64data = reader.result;
    
                                    document.getElementById("<%=hfName.ClientID %>").value = base64data;
    
                                }
    
    
                                stop(preview.srcObject);
    
                                log("Successfully recorded " + recordedBlob.size + " bytes of " +
                                    recordedBlob.type + " media.");
    
    
                            })
                            .catch(log);
                    }, false); stopButton.addEventListener("click", function () {
    
                       
    
                        stop(preview.srcObject);
    
                    
    
                        $('#startButton').attr('disabled', false);
                                    $('#stopButton').attr('disabled', true);
                                    $('#downloadButton').attr('disabled', false);
                                $('#<%=btnsaven.ClientID%>').attr('disabled', false);
    
                    }, false);
    
                });
    
    
    
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet"/>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
        <div class="panel-body">
                      
                        <div class="col-md-1">
                        </div>
    
                        <div class="col-md-3">
                            <h2>Live Preview</h2>
                            <video id="preview" controls width="260" height="150" autoplay muted style="border: solid 2px green; background-color: black"></video>
                            <br />
                            &nbsp;&nbsp;   &nbsp;&nbsp;
                                    <div id="startButton"  class="button btn btn-success btn-sm">&nbsp; &nbsp; &nbsp;Start  &nbsp; &nbsp; &nbsp; </div>
                            &nbsp;&nbsp;
    
                                    <div id="stopButton" disabled class="button btn btn-warning btn-sm">&nbsp; &nbsp; &nbsp;Stop &nbsp; &nbsp; &nbsp;  </div>
                            <br />
    
                        
    
    
                        </div>
                        <div class="col-md-2">
                            <br /><br /> <br /><br />
                           
                        </div>
                        <div class="col-md-4">
                            <h2>Recorded Video</h2>
                            <video id="recording" width="260" height="150" controls style="border: solid 2px green"></video>
                            <br />
                           
    
                            &nbsp;&nbsp;
                                  <a id="downloadButton" disabled class="button btn btn-primary btn-sm">&nbsp; &nbsp; &nbsp;Download &nbsp; &nbsp; &nbsp;</a>
    
                            <asp:HiddenField ID="hfName" runat="server" />
                        </div>
    
    
                        <div class="col-md-12">
                            <br />
                            <pre id="log"></pre>
                        </div>
                    </div>