Forums

ffmpeg and linuxbrew?

Hello pythonanywhere folks!

Overall, I've found this to be a much more pleasant experience than other deployments I've tried to implement. Thanks for the easy-to-understand model!

That said, I'm still a bit new to all of this, and I'm not entirely sure how to install ffmpeg into my venv. Normally, I'd use brew (or, here, linuxbrew), but I can't seem to get it to recognize brew (even after a successful install), and I'm not sure why. It might have something to do with the PATH, but honestly, that's not quite something I understand yet! How might I go about installing ffmpeg without brew, and/or getting it to recognize brew?

Thanks so much!

Hi there, I don't think brew is going to work, that's a mac-only tool as far as I know. And I'm not familiar with linuxbrew. But you can sometimes get things to install if you manually compile them, and then set the install target as being a local folder...

But, in the case of ffmpeg, we do have its successor, avconv, available and installed by default. Try that? Its command-line is pretty much identical...

That worked well! Thanks, harry, now it's recording!

Unfortunately, however, now it doesn't like one of my POST calls?

Specifically, I believe, the one attached here

            var data = new FormData();
            data.append('user_audio', blob);
            var xhr = new XMLHttpRequest();
            **xhr.open('POST', '/music_recognition', true);**
            xhr.send(data);

which links to a decorator in my flask file:

**@app.route("/music_recognition", methods=['POST'])**
def music_recognition():
    file = request.files['user_audio']
    filename = secure_filename("user_input.wav")
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    comparison.change_stereo_to_mono(filename)
    time.sleep(1)
    database_iteration = comparison.compare_fingerprint_to_database("new_user_input.wav")
    return json.dumps(database_iteration)

I recently had to change the pathing of the files so that they went into my specific project folder instead of just into the main directory--but it won't push the files into the algorithm I've set up through this call.

Any thoughts?

So what exactly is going wrong?

One tip would be to make sure to use absolute paths everywhere -- so, eg, /home/rhythmsection/audio-files/wherever/user_input.wav, instead of just user_input.wav...

Sorry if that was unclear!

The post error I'm getting is:

POST http://rhythmsection.pythonanywhere.com/music_recognition 404 (NOT FOUND)

Is it somewhere else than it thinks it should be?

Whoops, now I've streamlined it, but it's still giving me an internal server error for the POST call.

POST http://rhythmsection.pythonanywhere.com/music_recognition 500 (INTERNAL SERVER ERROR)

Here's the actual base_app.py file--if that helps!

from flask import Flask, session, render_template, redirect, request, flash
from werkzeug.utils import secure_filename
import os
import comparison
import time
import json



app = Flask(__name__)
app.secret_key = '\xf5!\x07!qj\xa4\x08\xc6\xf8\n\x8a\x95m\xe2\x04g\xbb\x98|U\xa2f\x03'

app.config['UPLOAD_FOLDER'] = 'MHB/'

@app.route("/")
def index():
    return render_template("receiveaudio.html")

@app.route("/music_recognition", methods=['POST'])
def music_recognition():
    file = request.files['user_audio']
    filename = secure_filename("user_input.wav")
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    comparison.change_stereo_to_mono(filename)
    time.sleep(1)
    database_iteration = comparison.compare_fingerprint_to_database("new_user_input.wav")
    return json.dumps(database_iteration)


@app.route("/success")
def successful_ident():
    return render_template("generateresults.html")


if __name__ == "__main__":
    app.run(debug=True)

Okay!

I think I've narrowed down the problem. The problem is that the database is creating itself? Again? I think? Instead of querying the database that already exists. The database is recreating itself in my main area instead of the project directory--how might I go about shifting where it is created?

ENGINE = None
Session = None

Base = declarative_base()


class Fingerprint(Base):
    __tablename__ = "fingerprints"

    id = Column(Integer, primary_key = True)
    title = Column(String, nullable = True)
    artist = Column(String, nullable = True)
    album = Column(String, nullable = True)
    fingerprint = Column(Text, nullable = True)

def connect():
   global ENGINE
   global Session

   ENGINE = create_engine("sqlite:///fingerprint_database.db", echo=True)
   Session = sessionmaker(bind=ENGINE)

   return Session()

Change the create_engine line to move it to your project directory. See here.

how do i update avconv to v 10?

Unfortunately you can't upgrade the system version of avconv. PythonAnywhere runs on Ubuntu LTS (version 14.04 "Trusty") which has version 9 as its standard version.

You could perhaps download the source and compile it yourself, then add it to your path...

Thanks Giles for your quick response!

Allan