0

I have a server on a Raspberry Pi 5 (8 GB of RAM btw). I have Nginx on it that allows me and others to watch my videos through a nice site. Though through trial and various errors, I found out I can't have video streaming enabled on the Pi. It'll overload it and corrupt the OS for some reason and make me reinstall it (as I'll do in a few hours, again...). But I can allow downloading and there's no problem.

So my question is if I can allow streaming of just a bit of videos and allow full download of them. More specifically (since this explanation was probably awful), I'd like a user to start playing a video and the browser only displays the first frame of where the cursor is and doesn't move forward on the video - making the Pi not overload loading the videos. That would make us know which video we want to watch (by knowing what's in the video. The title isn't enough) and then we'd actually download the video to watch it. If I still didn't explain this well enough tell me and I try again.

My server configuration:

server {
    listen 98 default_server ssl;
    ssl_certificate /etc/ssl/certs/...;
    ssl_certificate_key /etc/ssl/private/...;

    server_name default_server;

    root /srv/...;

    location "/favicon.ico" {
        alias /srv/...;
    }

    #location ~* ^.+\.(mp4|mp3)$ {
    #   add_header Content-disposition "attachment";
    #}

    autoindex              on;
    autoindex_format       html;
    autoindex_exact_size   off;
    autoindex_localtime    on;
    add_before_body        "/,theme/nginx-before.html";
    add_after_body         "/,theme/nginx-after.html";

    location /,theme/ {
        root /srv/...;
    }

    location / {
        auth_basic "";
        auth_basic_user_file "/srv/...";

        access_log on;

        try_files $uri $uri/ =404;
    }
}

1 Answer 1

0

This seems to have done it well enough:

location ~* ^.+\.(mp4|mp3)$ {
    limit_rate 1;
    limit_rate_after 5M;

    if ($arg_download) {
        add_header Content-disposition "attachment";

        limit_rate 5M;
        limit_rate_after 0;
    }
}

I limit the rate at which the streaming happens (and normal downloading) to 1 B/s but only after the first 5 MB to allow to watch the first seconds and stop after that. If we want to download the video, we add ?download=1 to the URL and the if statement will get triggered and will instead limit the rate to 5 MB/s on the download. A button on the website helps with writing the ?download=1 thing. Or a switch.

This or I can try limiting the rate to a low but enough value instead of just blocking streaming, but that needs testing. Both options seem good.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .