Sanic 20.9.1 and uvicorn 0.12.2 not serving correctly mp4 files

Hello,
I am using Sanic 20.9.1 and uvicorn 0.12.2 to serve small mp4 files. Sanic works perfectly but if use uvicorn like in the following code, the mp4 files are not served properly and the player is not able to decode the incoming data.
Is this a uvicorn issue?

file: main.py

from sanic import Sanic
from sanic.response import json
import uvicorn

app = Sanic("App Name")
app.static('vod.html', "vod.html", stream_large_files=1024 * 1024)
app.static('sample.mp4', "sample.mp4", stream_large_files=1024 * 1024)

@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    #app.run(host="0.0.0.0", port=8000)
    uvicorn.run(app, host="0.0.0.0", port=8000, workers=1, log_level="debug")

file: requirements.txt

sanic==20.9.1
Sanic-Cors==0.10.0.post3
sanic-openapi==0.6.2
uvicorn==0.12.2
h11==0.8.0

file vod.html

<!DOCTYPE html>
<html lang="en">

<head>
    <title>VOD Test</title>
    <style>
        video {
            width: 480px;
            height: 282px;
            background-color: black;
            margin: 5px 10px 5px 10px;
            padding: 5px;
            float: left;

        }
    </style>
</head>

<body>
    <div id="header">
    <video src='http://localhost:8000/sample.mp4' autoplay controls></video>
    </div> 
</body>
</html>

Thanks!
Jay

Additional info, sniffing with wireshark

With uvicorn (not working):

Without uvicorn (sanic direct, working)

I see an additional 407, any ideas?
Error code from the video tag is 4, the browsers does not recognize the format.
DEMUXER_ERROR_COULD_NOT_OPEN: FFmpegDemuxer: open context failed

Thanks!

As reported in #1964, with PR to master in #1965 and LTS in #1966. Fix to be releases in 19.12.4, and TBD if it will have intermediary 20.9 release or wait until 20.12.

1 Like