Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (108)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

Sur d’autres sites (12715)

  • How to use ffmpeg in flask server to convert between audio formats without writing files to disk ?

    14 avril 2020, par Athwulf

    I have successfully managed to use ffmpeg in python to convert the format of some audio files like this :

    



    command = "ffmpeg -i audio.wav -vn -acodec pcm_s16le output.wav"
subprocess.call(command, shell=True)


    



    However I want to do this in memory and avoid saving the input and output files to disk.

    



    I have found the follwing code to do such a thing (Passing python’s file like object to ffmpeg via subprocess) :

    



    command = ['ffmpeg', '-y', '-i', '-', '-f', 'wav', '-']
process = subprocess.Popen(command, stdin=subprocess.PIPE)
wav, errordata = process.communicate(file)


    



    But I am struggeling to use this in my context.

    



    I am receiving the file on a server as part of a multipart/form-data request.

    



    @server.route("/api/getText", methods=["POST"])
def api():
    if "multipart/form-data" not in request.content_type:
        return Response("invalid content type: {}".format(request.content_type))
    # check file format
    file = request.files['file']
    if file:
        print('**found file', file.filename)


    



    Now I have the file as a FileStorage Object (https://tedboy.github.io/flask/generated/generated/werkzeug.FileStorage.html). This object has a stream, which can be accessed by using the read method. So I thought I might be able to use this as input for ffmpeg like so :

    



    f = file.read()
command = ['ffmpeg', '-y', '-i', '-', '-f', 'wav', '-']
process = subprocess.Popen(command, stdin=subprocess.PIPE)
wav, errordata = process.communicate(f)


    



    However this yields the the following error :

    



    AssertionError: Given audio file must be a filename string or a file-like object


    



    I have also tried another approach which I found online, using io.BytesIO, to which I can't find the source anymore :

    



    memfile = io.BytesIO()  # create file-object
memfile.write(file.read())  # write in file-object
memfile.seek(0)  # move to beginning so it will read from beginning


    



    And then trying this again :

    



    command = ['ffmpeg', '-y', '-i', '-', '-f', 'wav', '-']
process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
wav, errordata = process.communicate(memfile)


    



    This gets me the following error :

    



    TypeError: a bytes-like object is required, not '_io.BytesIO'


    



    Does anyone have an idea of how to do this ?

    



    Update

    



    The first error message is actually not a error message thrown by ffmpeg. As v25 pointed out correctly in his answer the first approach also returns a bytes object and is also a valid solution.

    



    The error message got thrown by a library (speech_recognition) when trying to work with the modified file. In the unlikely case of someone coming across the same problem here the solution :

    



    The bytes objected returned by ffmpeg (variable wav) has to be turned into a file-like object as the error message implies. This can easily be done like this :

    



    memfileOutput = io.BytesIO(wav)

    


  • How do I use ffmpeg with Python by passing File Objects (instead of locations to files on disk)

    25 mars 2020, par Lyle Pratt

    I’m trying to use ffmpeg with Python’s subprocess module to convert some audio files. I grab the audio files from a URL and would like to just be able to pass the Python File Objects to ffmpeg, instead of first saving them to disk. It would also be very nice if I could just get back a file stream instead of having ffmpeg save the output to a file.

    For reference, this is what I’m doing now :

    tmp = "/dev/shm"
    audio_wav_file = requests.get(audio_url)
    ##              ##                         ##
    ## This is what I don't want to have to do ##
    wavfile = open(tmp+filename, 'wrb')  
    wavfile.write(audio_wav_file.content)
    wavfile.close()
    ##              ##                         ##
    conversion = subprocess.Popen('ffmpeg -i "'+tmp+filename+'" -y "'+tmp+filename_noext+'.flac" 2>&1', shell = True, stdout = subprocess.PIPE).stdout.read()

    Does anyone know how to do this ?

    Thanks !

  • How to get the output from fluent-ffmpeg screenshots as a buffer instead of writing it directly to the disk ?

    17 novembre 2020, par Mohammed S. Yaseen

    I have a set of videos I want to take a screenshot from each of them, then do some processing on these generated images, and finally store them.

    


    To be able to do the processing I need to get the screenshots as buffers.

    


    this is my code

    


    ffmpeg(videoFilePath)
.screenshots({
     count: 1,
     timestamps: ['5%'],
     folder: DestinationFolderPath,
     size: thumbnailWidth + 'x' + thumbnailHeight,
})
.on('err', function (error) {
     console.log(err)
});


    


    as you see the output is being directly stored in the DestinationFolderPath. Instead of that I want to get the output as a buffer.