diff options
author | Michaël Ball <michael.ball@gmail.com> | 2015-11-27 19:38:10 +0000 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2015-11-27 19:38:10 +0000 |
commit | 4385cc98d1af499be4eeb5ec1269203928d749ff (patch) | |
tree | b1437e884203c6f7929fd5791a056c63fe607be7 | |
parent | 785369b43565c338d050c4fcb00008be6771c337 (diff) |
Serve transcoded track
-rw-r--r-- | mach2.py | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1,7 +1,11 @@ import configparser import json import mimetypes +import os import sqlite3 +import subprocess +import tempfile +import threading from flask import Flask, Response, current_app, g, redirect, render_template from flask import request, url_for @@ -144,17 +148,23 @@ def track(track_id): if chunk: yield chunk else: + os.remove(filename) break local_track = Track(track_id) + fd, temp_filename = tempfile.mkstemp() + + subprocess.call(["ffmpeg", "-y", "-i", local_track.filename, "-acodec", + "libopus", "-b:a", "64000", "-f", "opus", temp_filename]) + mime_string = "application/octet-stream" - mime = mimetypes.guess_type(local_track.filename) + mime = mimetypes.guess_type(temp_filename) if mime[0]: mime_string = mime[0] - resp = Response(stream_file(local_track.filename), mimetype=mime_string) + resp = Response(stream_file(temp_filename), mimetype=mime_string) if mime[1]: resp.headers["Content-Encoding"] = mime[1] |