Как исправить проблему с ориентацией видео html5 для захвата с мобильных камер? - PullRequest
0 голосов
/ 08 июня 2019

Я пытался сделать веб-сервер на основе фляги, чтобы брать видео с мобильного телефона и отправлять на сервер.Когда я пытаюсь снять видео с камеры телефона, оно отправляет видео на сервер с вращением -90 ccw.Но когда я отправляю видео из библиотеки фотографий телефона, она отправляется нормальноЕсть ли способ исправить эту проблему.

Спасибо за помощь.

Вот мой html и javascript код

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <script src="../static/js/jquery-3.4.1.min.js"></script>
    <script src="../static/js/toastr.min.js"></script>
    <link rel="stylesheet" href="../static/css/toastr.min.css">

    <title>Video Upload</title>
</head>
<body>

<input id="inputVideo" type="file" accept="video/*;capture=camera">
<button onclick="video()">Take a Video</button>
<button onclick="upload()">Upload Video</button>

<video autoplay></video>

<progress style="display: none;" id="progress" value="0" data-label="Uploading..."></progress>




<style>
    input{
        display:none;
    }
    progress:before {
    content:'Uploading';
    }
    progress {
    text-align:center;
    }
    </style>

<script>
    // toastr options
    toastr.options.closeButton = true;
    toastr.options.positionClass = "toast-bottom-center";
    let progressBar = document.getElementById("progress");



    function video(){
        let input = document.getElementById('inputVideo');
        input.click()
    }


    let videoSource = document.getElementById('inputVideo');    
    if (videoSource){
    videoSource.onchange= function(){
        let file = videoSource.files[0];
        document.querySelector('video').src = URL.createObjectURL(file);
    }
    }

    // upload video to server   
    function upload(){

    let video = document.getElementById('inputVideo');    
    let file = video.files[0];

    })
    if (file){

        let formData = new FormData();
        formData.append('video', file);
        progressBar.style.display = 'block'
        xhr('/save', formData, function () {
            toastr.success('Video Uploaded')
            progressBar.style.display='none'
        })
        video.value='';
        document.querySelector('video').src = ''  
    }
    else{
        toastr.warning('Please, Upload or Take a video!')
    }


    }

    // xhr post method
    function xhr(url, data, callback) {
        let request = new XMLHttpRequest();
        request.onreadystatechange = function () {
            if (request.readyState ==4 && request.status ==200){
                callback(location.href + request.responseText);
            }
        };
        request.open('POST', url);

        request.upload.onprogress = function (e) {
        if (e.lengthComputable) {
            progressBar.max = e.total;
            progressBar.value = e.loaded;
        }
        }
        request.upload.onloadstart = function (e) {
            progressBar.value = 0;
        }
        request.upload.onloadend = function (e) {
            progressBar.value = e.loaded;
        }
        request.send(data);   
    }

</script>

</body>
</html>

А вот скрипт python для сохранения видео

import requests
from flask import render_template, Response, request
from flask import current_app
from . import routes
import os
from werkzeug.utils import secure_filename
from datetime import datetime

@routes.route('/')
def home():
    return render_template('home.html')

@routes.route('/save', methods=['POST'])
def save():
    if request.method == 'POST':           
        file = request.files['video']
        print(file.filename)
        save_filename = file.filename
        save_filename = secure_filename(save_filename)
        file.save(os.path.join('./routes/videos/', save_filename))
        return "success"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...