Ver código fonte

Audio waveform and png are now generated from a temp dat file to avoid processing it twice

pull/48/head
Dashie der otter 7 meses atrás
pai
commit
2ff614659f
Acessado por: Dashie <dashie@sigpipe.me> ID da chave GPG: C2D57B325840B755
3 arquivos alterados com 46 adições e 6 exclusões
  1. 0
    2
      TODO.org
  2. 10
    3
      transcoding_utils.py
  3. 36
    1
      utils.py

+ 0
- 2
TODO.org Ver arquivo

@@ -15,8 +15,6 @@
** SQL optimization
** translations check

Generate a temp .dat file to generate .png and json to avoid dual processing of audio file

~~~~~~~~~ ACTIVITYPUB ~~~~~~~~
-> profile UPDATE not handled yet (littleboxes don't handle UPDATE) upstream


+ 10
- 3
transcoding_utils.py Ver arquivo

@@ -9,7 +9,7 @@ import magic
import mutagen

from models import db, SoundInfo, Sound
from utils import get_waveform, create_png_waveform, duration_song_human, add_user_log
from utils import get_waveform, create_png_waveform, duration_song_human, add_user_log, generate_audio_dat_file
from pydub import AudioSegment
from os.path import splitext
from flask import current_app
@@ -203,8 +203,11 @@ def work_metadatas(sound_id, force=False):
else:
fname_t = fname

print("- GENERATING AUDIO DAT FILE")
dat_file_name = generate_audio_dat_file(fname_t)

print("- WORKING WAVEFORM on {0}, {1}".format(sound.id, sound.filename))
waveform_infos = get_waveform_infos(fname_t)
waveform_infos = get_waveform_infos(dat_file_name)
print("- Our file got waveform infos: {0}".format(waveform_infos))
_infos.waveform = waveform_infos
if not waveform_infos:
@@ -223,7 +226,11 @@ def work_metadatas(sound_id, force=False):
if not os.path.isdir(fdir_wf):
os.makedirs(fdir_wf)

create_png_waveform(fname_t, fname_wf)
create_png_waveform(dat_file_name, fname_wf)

# Delete the temporary dat file
os.unlink(dat_file_name)

_infos.done_waveform = True

db.session.add(_infos)

+ 36
- 1
utils.py Ver arquivo

@@ -119,13 +119,45 @@ def duration_song_human(seconds):
return "%.2f sec" % seconds + "s" * (seconds != 1)


def generate_audio_dat_file(filename):
binary = current_app.config["AUDIOWAVEFORM_BIN"]
if not os.path.exists(binary) or not os.path.exists(filename):
add_log("AUDIOWAVEFORM", "ERROR", "Filename {0} or binary {1} invalid".format(filename, binary))
return None

fname, _ = splitext(filename)

audio_dat = "{0}.dat".format(fname)

cmd = [binary, "-i", filename, "-o", audio_dat, "-b", "8"]

try:
process = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if not process:
add_log("AUDIOWAVEFORM_DAT", "ERROR", "Subprocess returned None")
return None
except subprocess.CalledProcessError as e:
add_log("AUDIOWAVEFORM_DAT", "ERROR", "Process error: {0}".format(e))
return None

print("- Command ran with: {0}".format(process.args))

if process.stderr.startswith(b"Can't generate"):
add_log("AUDIOWAVEFORM_DAT", "ERROR", "Process error: {0}".format(process.stderr))
return None

return audio_dat


def get_waveform(filename):
binary = current_app.config["AUDIOWAVEFORM_BIN"]
if not os.path.exists(binary) or not os.path.exists(filename):
add_log("AUDIOWAVEFORM", "ERROR", "Filename {0} or binary {1} invalid".format(filename, binary))
return None

tmpjson = "{0}.json".format(filename)
fname, _ = splitext(filename)

tmpjson = "{0}.json".format(fname)

cmd = [binary, "-i", filename, "--pixels-per-second", "10", "-b", "8", "-o", tmpjson]

@@ -179,7 +211,10 @@ def create_png_waveform(fn_audio, fn_png):
add_log("AUDIOWAVEFORM_PNG", "ERROR", "Filename {0} or binary {1} invalid".format(fn_audio, binary))
return None

fname, _ = splitext(fn_audio)

pngwf = "{0}.png".format(fn_png)

cmd = [
binary,
"-i",

Carregando…
Cancelar
Salvar