Recherche avancée

Médias (1)

Mot : - Tags -/belgique

Autres articles (83)

  • Mise à jour de la version 0.1 vers 0.2

    24 juin 2013, par

    Explications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
    Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

Sur d’autres sites (12355)

  • How to transcode MP3 files in django by using FFMPEG, Celery and RabbitMQ ?

    12 janvier 2017, par Srinivas 25

    I am trying to transcode user uploaded MP3 audio files into ogg, ac3 wav or other formats by using django, celery, rabbitMQ and FFMPEG. But i am getting the error with [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call

    OS-Window 10-64bit
    Python 3.0
    Django - 1.10

    here is the code I followed :

    models.py
    import uuid
    from django.db import models

      # Create your models here.

       def unique_file_path(instance, filename):
       new_file_name = uuid.uuid4()
       return str(new_file_name)

       class AudioFile(models.Model):
       name = models.CharField(max_length=100, blank=True)
       mp3_file = models.FileField(upload_to=unique_file_path)
       ogg_file = models.FileField(blank=True, upload_to=unique_file_path)
       wav_file = models.FileField(blank=True, upload_to=unique_file_path)
       ac3_file = models.FileField(blank=True, upload_to=unique_file_path)

       def __str__(self):
           return self.name

       views.py
       from django.shortcuts import render

       # Create your views here.

       from django.views.generic.edit import FormView
       from django.http import HttpResponseRedirect
       from django.core.urlresolvers import reverse

       from django.views.generic import FormView
       from audio_transcoder.taskapp.tasks import transcode_mp3

       from .forms import AudioFileFrom
       from .models import AudioFile

       class UploadAudioFileView(FormView):
       template_name = 'upload/upload.html'
       form_class = AudioFileFrom


       def form_valid(self, form):
           audio_file = AudioFile(
               name=self.get_form_kwargs().get('data')['name'],
               mp3_file=self.get_form_kwargs().get('files')['mp3_file']
           )
           audio_file.save()
           transcode_mp3.delay(audio_file.id)

           return HttpResponseRedirect(self.get_success_url())

       def get_success_url(self):
           return reverse('/')


       tasks.py
       import os
       import os.path
       import subprocess

       from audio_transcoder.taskapp.celery import app




       from celery import Celery

       app = Celery('fftest',
                broker='amqp://guest@localhost//',
                include=['taskapp.tasks'])

       if __name__ == '__main__':
       app.start()

       from audio_transcoder.models import AudioFile
       import fftest.settings as settings

       @app.task
       def transcode_mp3(mp3_id):
       audio_file = AudioFile.objects.get(id=mp3_id)
       input_file_path = audio_file.mp3_file.path
       filename = os.path.basename(input_file_path)

       ogg_output_file_name = os.path.join('transcoded', '{}.ogg'.format(filename))
       ogg_output_file_path = os.path.join(settings.MEDIA_ROOT, ogg_`enter code    
       here`output_file_name)
       enter code here
       ac3_output_file_name = os.path.join('transcoded', '{}.ac3'.format(filename))
       ac3_output_file_path = os.path.join(settings.MEDIA_ROOT,  
       ac3_output_file_name)

       wav_output_file_name = os.path.join('transcoded', '{}.wav'.format(filename))
       wav_output_file_path = os.path.join(settings.MEDIA_ROOT,
       wav_output_file_name)

       if not os.path.isdir(os.path.dirname(ogg_output_file_path)):
           os.makedirs(os.path.dirname(ogg_output_file_path))

       subprocess.call([
               settings.FFMPEG_PATH,
               '-i',
               input_file_path,
               ogg_output_file_path,
               ac3_output_file_path,
               wav_output_file_path
           ]
       )

       audio_file.ogg_file = ogg_output_file_name
       audio_file.ac3_file = ac3_output_file_name
       audio_file.wav_file = wav_output_file_name
       audio_file.save()

    Not sure where the mistake is happening. While uploading video it is showing below :

    OperationalError at /new/
    [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
    Request Method: POST
    Request URL:  http://127.0.0.1:8000/new/
    Django Version: 1.10.4
    Exception Type: OperationalError`enter code here`
    Exception Value:  
    [WinError 10042] An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
    Exception Location: C:\Users\RAMa2r3e4s5h6\fftest\lib\site-packages\amqp\transport.py in _set_socket_options, line 204
  • saving ffmpeg output in a file field in django using tempfiles

    27 janvier 2017, par StarLord

    I am trying to extract audio from video when uploaded, and store it in a different model.

    this is the task code :

    def set_metadata(input_file, video_id):
       """
       Takes the file path and video id, sets the metadata and audio
       :param input_file: file url or file path
       :param video_id: video id of the file
       :return: True
       """
       # extract metadata
       command = [FFPROBE_BIN,
                  '-v', 'quiet',
                  '-print_format', 'json',
                  '-show_format',
                  '-show_streams',
                  '-select_streams', 'v:0',
                  input_file]
       output = sp.check_output(command)
       output = output.decode('utf-8')
       metadata_output = json.loads(output)
       video_instance = Video.objects.get(pk=video_id)
       stream = metadata_output['streams'][0]
       tot_frames_junk = int(stream['avg_frame_rate'].split("/")[0])
       tot_time_junk = int(stream['avg_frame_rate'].split("/")[1])
       # update the video model with newly acquired metadata
       video_instance.width = stream['width']
       video_instance.height = stream['height']
       video_instance.frame_rate = tot_frames_junk/tot_time_junk
       video_instance.duration = stream['duration']
       video_instance.total_frames = stream['nb_frames']
       video_instance.video_codec = stream['codec_name']
       video_instance.save()

       # extract audio
       tmpfile = temp.NamedTemporaryFile(suffix='.mp2')
       command = ['ffmpeg',
                  '-y',
                  '-i', input_file,
                  '-loglevel', 'quiet',
                  '-acodec', 'copy',
                  tmpfile.name]
       sp.check_output(command)
       audio_obj = Audio.objects.create(title='awesome', audio=tmpfile)
       audio_obj.save()

    I am passing video object id and the file path to the method. The file path is a url from azure storage.

    The part where I am processing for metadata, it works and the video object gets updated. But the audio model is not created.

    It throws this error :

    AttributeError("'_io.BufferedRandom' object has no attribute '_committed'",)

    at command :

    audio_obj = Audio.objects.create(title='awesome', audio=tmpfile)

    What am I doing wrong with the temp file.

  • ffmpeg disconnects from the HTTP server

    29 janvier 2017, par Frédéric Lopes

    I am facing to a problem that I cannot solve for days now and cannot find any answer over internet..

    I am currently working on a live streaming & IoT project through internet in order to access to indoor items and see through a webcam. I am using Node.js for the server side and using a mpeg1video decoder working with WebSocket (https://github.com/phoboslab/jsmpeg).

    All the server side (HTTP + WebSocket server) and client side are working properly (I see the clients connecting and waiting for sockets) but when I try to stream a video (or a camera) ffmpeg is not keeping the connection with my HTTP server, the connection is established but it is disconnected 1 second after being connected... Here is the terminal outputs gathered :

    if( process.argv.length < 4 ) {
       console.log(
           'Usage: \n' +
           'node stream-server.js [ ]'
       );
       process.exit();
    }

    var STREAM_PORT = process.argv[2] || 8080,
           WEBSOCKET_PORT = process.argv[3] || 8081,
           STREAM_MAGIC_BYTES = 'jsmp'; // Must be 4 bytes

    var width = 320,
           height = 240;

    // Websocket Server
    var socketServer = new (require('ws').Server)({port: WEBSOCKET_PORT});
    socketServer.on('connection', function(socket) {
       // Send magic bytes and video size to the newly connected socket
       // struct { char magic[4]; unsigned short width, height;}
       var streamHeader = new Buffer(8);
       streamHeader.write(STREAM_MAGIC_BYTES);
       streamHeader.writeUInt16BE(width, 4);
       streamHeader.writeUInt16BE(height, 6);
       socket.send(streamHeader, {binary:true});

       console.log('New WebSocket Connection ('+socketServer.clients.length+' total)');

       socket.on('close', function(code, message){
           console.log( 'Disconnected WebSocket ('+socketServer.clients.length+' total)' );
       });
    });

    socketServer.broadcast = function(data, opts) {
       for( var i in this.clients ) {
           if (this.clients[i].readyState == 1) {
               this.clients[i].send(data, opts);
           }
           else {
               console.log( 'Error: Client ('+i+') not connected.' );
           }
       }
    };

    // HTTP Server to accept incomming MPEG Stream
    var streamConnected = false;
    var streamServer = require('http').createServer(function(request, response) {
       response.connection.setTimeout(0);
       if(streamConnected) {
           response.end();
           return;
       }
       streamConnected = true;

       var params = request.url.substr(1).split('/');

       width = (params[0] || 320)|0;
       height = (params[1] || 240)|0;

       console.log(
           'Stream Connected: ' + request.socket.remoteAddress +
           ':' + request.socket.remotePort + ' size: ' + width + 'x' + height
       );

       request.on('data', function(data){
           socketServer.broadcast(data, {binary:true});
       });

       request.on('close', function(data){
           console.log("Stream disconnected");
           streamConnected = false;
       });

    }).listen(STREAM_PORT);

    console.log('Listening for MPEG Stream on http://127.0.0.1:'+STREAM_PORT+'/<width>/<height>');
    console.log('Awaiting WebSocket connections on ws://127.0.0.1:'+WEBSOCKET_PORT+'/');
    </height></width>

    Once the server running, I am using the command line to send my video to the http server :

    ffmpeg -f mp4 -i in.mp4 -f mpeg1video -r 30 http://127.0.0.1:8080

    Unfortunatelly, the connection is established for 1 seconde maximum and it disconnects right after.. I tried everything to keep it even setting a timeout to the request of ffmpeg.

    Thank you for those who are going to help me with this issue !

    UPDATE : Outputs gathered on the terminal

    1st is the output generated by ffmpeg :

    MacBook-Pro-de-Frederic: ffmpeg -f mp4 -i in.mp4 -f mpeg1video -r 30 http://127.0.0.1:8080
    ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
     built with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
     configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --disable-doc --arch=x86_64 --enable-runtime-cpudetect
     libavutil      55. 34.100 / 55. 34.100
     libavcodec     57. 64.101 / 57. 64.101
     libavformat    57. 56.100 / 57. 56.100
     libavdevice    57.  1.100 / 57.  1.100
     libavfilter     6. 65.100 /  6. 65.100
     libswscale      4.  2.100 /  4.  2.100
     libswresample   2.  3.100 /  2.  3.100
     libpostproc    54.  1.100 / 54.  1.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mp4':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf56.25.101
     Duration: 00:00:13.29, start: 0.000000, bitrate: 490 kb/s
       Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 300x198 [SAR 1:1 DAR 50:33], 489 kb/s, 22.73 fps, 22.73 tbr, 16k tbn, 45.45 tbc (default)
       Metadata:
         handler_name    : VideoHandler
    Output #0, mpeg1video, to 'http://127.0.0.1:8080':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2avc1mp41
       encoder         : Lavf57.56.100
       Stream #0:0(und): Video: mpeg1video, yuv420p, 300x198 [SAR 1:1 DAR 50:33], q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default)
       Metadata:
         handler_name    : VideoHandler
         encoder         : Lavc57.64.101 mpeg1video
       Side data:
         cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream mapping:
     Stream #0:0 -> #0:0 (h264 (native) -> mpeg1video (native))
    Press [q] to stop, [?] for help
    frame=  398 fps=0.0 q=7.2 Lsize=     540kB time=00:00:13.23 bitrate= 334.2kbits/s dup=96 drop=0 speed=49.7x    
    video:540kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

    2nd output, the prints of the Node.js script :

    MacBook-Pro-de-Frederic: node stream-server.js 8080 8081
    Listening for MPEG Stream on http://127.0.0.1:8080/<width>/<height>
    Awaiting WebSocket connections on ws://127.0.0.1:8081/
    New WebSocket Connection (1 total)
    Stream Connected: ::ffff:127.0.0.1:52444 size: 320x240
    Stream disconnected
    </height></width>

    As you can see, my server receives the stream from ffmpeg but is disconnected right after.. Thus, I cannot do any stream and I don’t understand why because there is not any error that appears..

    UPDATE 2 : TESTED ON RASPBERRYPI MODEL B+

    I tested all the code hereabove on raspberry pi (after 5h installing ffmpeg..) and launch the encoding with the terminal command hereafter and it works perfectly ! I am still wondering why it is not working properly on Mac ? Maybe a problem of compatibility between OSX and FFMPEG ? If someone has an answer or an idea of the solution to the problem on Macintosh, let me know !

    raspivid -t 0 -w 320 -h 240 -fps 20 -vf -o - | ffmpeg -y -i pipe:0 -s 320x240 -f video4linux2 -f mpeg1video -b 400k -r 30 http://127.0.0.1:8080

    Configuration used : Macbook Pro updated running Node.js 6.9.2 & ffmpeg 3.2.2.

    Frederic