Prevent HTML5 video from being downloaded (right-click saved)?

前端 未结 20 2073
醉酒成梦
醉酒成梦 2020-11-22 15:33

How can I disable \"Save Video As...\" from a browser\'s right-click menu to prevent clients from downloading a video?

Are there more complete solutions that prevent

相关标签:
20条回答
  • 2020-11-22 16:23

    Short Answer: Encrypt the link like youtube does, don't know how than ask youtube/google of how they do it. (Just in case you want to get straight into the point.)

    I would like to point out to anyone that this is possible because youtube does it and if they can so can any other website and it isn't from the browser either because I tested it on a couple browsers such as microsoft edge and internet explorer and so there is a way to disable it and seen that people still say it...I tries looking for an answer because if youtube can than there has to be a way and the only way to see how they do it is if someone looked into the scripts of youtube which I am doing now. I also checked to see if it was a custom context menu as well and it isn't because the context menu is over flowing the inspect element and I mean like it is over it and I looked and it never creates a new class and also it is impossible to actually access inspect element with javascript so it can't be. You can tell when it double right-click a youtube video that it pops up the context menu for chrome. Besides...youtube wouldn't add that function in. I am doing research and looking through the source of youtube so I will be back if I find the answer...if anyone says you can't than, well they didn't do research like I have. The only way to download youtube videos is through a video download.

    Okay...I did research and my research stays that you can disable it except there is no javascript to it...you have to be able to encrypt the links to the video for you to be able to disable it because I think any browser won't show it if it can't find it and when I opened a youtube video link it showed as this "blob:https://www.youtube.com/e5c4808e-297e-451f-80da-3e838caa1275" without quotes so it is encrypting it so it cannot be saved...you need to know php for that but like the answer you picked out of making it harder, youtube makes it the hardest of heavy encrypting it, you need to be an advance php programmer but if you don't know that than take the person you picked as best answer of making it hard to download it...but if you know php than heavy encrypt the video link so it only is able to be read on yours...I don't know how to explain how they do it but they did and there is a way. The way youtube Encrypts there videos is quite smart so if you want to know how to than just ask youtube/google of how they do it...hope this helps for you although you already picked a best answer. So encrypting the link is best in short terms.

    0 讨论(0)
  • 2020-11-22 16:26

    You can use

    <video src="..." ... controlsList="nodownload">
    

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/controlsList

    It doesn't prevent saving the video, but it does remove the download button and the "Save as" option in the context menu.

    0 讨论(0)
  • 2020-11-22 16:28

    Using a service such as Vimeo: Sign in Vimeo > Goto Video > Settings > Privacy > Mark as Secured, and also select embed domains. Once the embed domains are set, it will not allow anyone to embed the video or display it from the browser unless connecting from the domains specified. So, if you have a page that is secured on your server which loads the Vimeo player in iframe, this makes it pretty difficult to get around.

    0 讨论(0)
  • 2020-11-22 16:31

    PHP sends the html5 video tag together with a session where the key is a random string and the value is the filename.

    ini_set('session.use_cookies',1);
    session_start();
    $ogv=uniqid(); 
    $_SESSION[$ogv]='myVideo.ogv';
    $webm=uniqid(); 
    $_SESSION[$webm]='myVideo.webm';
    echo '<video autoplay="autoplay">'
        .'<source src="video.php?video='.$ogv.' type="video/ogg">'
        .'<source src="video.php?video='.$webm.' type="video/webm">'
        .'</video>'; 
    

    Now PHP is asked to send the video. PHP recovers the filename; deletes the session and sends the video instantly. Additionally all the 'no cache' and mime-type headers must be present.

    ini_set('session.use_cookies',1);
    session_start();
    $file='myhiddenvideos/'.$_SESSION[$_GET['video']];
    $_SESSION=array();
    $params = session_get_cookie_params();
    setcookie(session_name(),'', time()-42000,$params["path"],$params["domain"],
                                             $params["secure"], $params["httponly"]);
    if(!file_exists($file) or $file==='' or !is_readable($file)){
      header('HTTP/1.1 404 File not found',true);
      exit;
      }
    readfile($file);
    exit:
    

    Now if the user copy the url in a new tab or use the context menu he will have no luck.

    0 讨论(0)
  • 2020-11-22 16:33

    We ended up using AWS CloudFront with expiring URLs. The video will load, but by the time the user right clicks and chooses Save As the video url they initially received has expired. Do a search for CloudFront Origin Access Identity.

    Producing the video url requires a key pair which can be created in the AWS CLI. FYI this is not my code but it works great!

    $resource = 'http://cdn.yourwebsite.com/videos/yourvideourl.mp4';
    $timeout = 4;
    
    //This comes from key pair you generated for cloudfront
    $keyPairId = "AKAJSDHFKASWERASDF";
    
    $expires = time() + $timeout; //Time out in seconds
    $json = '{"Statement":[{"Resource":"'.$resource.'","Condition" {"DateLessThan":{"AWS:EpochTime":'.$expires.'}}}]}';     
    
    //Read Cloudfront Private Key Pair
    $fp=fopen("/absolute/path/to/your/cloudfront_privatekey.pem","r"); 
    $priv_key=fread($fp,8192); 
    fclose($fp); 
    
    //Create the private key
    $key = openssl_get_privatekey($priv_key);
    if(!$key)
    {
        echo "<p>Failed to load private key!</p>";
        return;
    }
    
    //Sign the policy with the private key
    if(!openssl_sign($json, $signed_policy, $key, OPENSSL_ALGO_SHA1))
    {
        echo '<p>Failed to sign policy: '.openssl_error_string().'</p>';
        return;
    }
    
    //Create url safe signed policy
    $base64_signed_policy = base64_encode($signed_policy);
    $signature = str_replace(array('+','=','/'), array('-','_','~'), $base64_signed_policy);
    
    //Construct the URL
    $url = $resource.'?Expires='.$expires.'&Signature='.$signature.'&Key-Pair-Id='.$keyPairId;
    
    return '<div class="videowrapper" ><video autoplay controls style="width:100%!important;height:auto!important;"><source src="'.$url.'" type="video/mp4">Your browser does not support the video tag.</video></div>';
    
    0 讨论(0)
  • 2020-11-22 16:34

    @Clayton-Graul had what I was looking for, except I needed the CoffeeScript version for a site using AngularJS. Just in case you need that too, here's what you put in the AngularJS controller in question:

        # This is how to we do JQuery ready() dom stuff
        $ ->
            # let's hide those annoying download video options.
            # of course anyone who knows how can still download
            # the video, but hey... more power to 'em.
            $('#my-video').bind 'contextmenu', -> 
                false
    

    "strange things are afoot at the circle k" (it's true)

    0 讨论(0)
提交回复
热议问题