summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2015-11-27 19:38:10 +0000
committerMichaël Ball <michael.ball@gmail.com>2015-11-27 19:38:10 +0000
commit4385cc98d1af499be4eeb5ec1269203928d749ff (patch)
treeb1437e884203c6f7929fd5791a056c63fe607be7
parent785369b43565c338d050c4fcb00008be6771c337 (diff)
Serve transcoded track
-rw-r--r--mach2.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/mach2.py b/mach2.py
index 31f9466..ffa1c1e 100644
--- a/mach2.py
+++ b/mach2.py
@@ -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]