Recherche avancée

Médias (1)

Mot : - Tags -/lev manovitch

Autres articles (88)

  • 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 (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Le plugin : Gestion de la mutualisation

    2 mars 2010, par

    Le plugin de Gestion de mutualisation permet de gérer les différents canaux de mediaspip depuis un site maître. Il a pour but de fournir une solution pure SPIP afin de remplacer cette ancienne solution.
    Installation basique
    On installe les fichiers de SPIP sur le serveur.
    On ajoute ensuite le plugin "mutualisation" à la racine du site comme décrit ici.
    On customise le fichier mes_options.php central comme on le souhaite. Voilà pour l’exemple celui de la plateforme mediaspip.net :
    < ?php (...)

Sur d’autres sites (8063)

  • pipe ffmpeg in Python

    14 juillet 2017, par Muhammet PARLAK

    I have a working ffmpeg command which converts rtsp to image.

    FFmpeg command here :

    ffmpeg -i rtsp://192.168.200.230 -vf fps=fps=20/1 -vb 20M -qscale:v 2 img%d.jpg

    I want to adapt the ffmpeg code into pipe code.

    I tried to adapt it but It doesnt look right.

    import subprocess
    import numpy
    import cv2


    proc = subprocess.Popen(['ffmpeg',
       "-i", "rtsp://192.168.200.230/554",
       "-vf", "image2pipe",
       "fps", "20/1",                      
       "-qscale:v", "2",
       "-vb", "20M",
       "img%d.jpg"],
       stdout=subprocess.PIPE,
    )

    while True:
       raw_image = proc.stdout.read(640 * 360 * 3)
       cv2.imshow('image', raw_image)
       cv2.waitKey()
       cv2.destroyAllWindows()

       if not raw_image:
           break
       image =  numpy.fromstring(raw_image, dtype='uint8').reshape((640, 360, 3))

    If u can also give me about placement hints ,It will be very usefull for me.I also want to call the image many times as value.And Im going to use it on vehicle detection.Gonna call it as a frame and doing processing.

    This is the example of ffmpeg reading writing audio files in python.It can help you to guide.

    http://zulko.github.io/blog/2013/10/04/read-and-write-audio-files-in-python-using-ffmpeg/

  • Python : mp3 to alsaaudio through ffmpeg pipe and wave.open(f,'r')

    3 juillet 2017, par user2754098

    I’m trying to decode mp3 to wav using ffmpeg :

    import alsaaudio
    import wave
    from subprocess import Popen, PIPE

    with open('filename.mp3', 'rb') as infile:
       p=Popen(['ffmpeg', '-i', '-', '-f', 'wav', '-'], stdin=infile, stdout=PIPE)
       ...

    Next i want redirect data from p.stdout.read() to wave.open(file, r) to use readframes(n) and other methods. But i cannot because ’file’ in wave.open(file,’r’) can be only name of file or an open file pointer.

       ...
       file = wave.open(p.stdout.read(),'r')
       card='default'
       device=alsaaudio.PCM(card=card)
       device.setchannels(file.getnchannels())
       device.setrate(file.getframerate())
       device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
       device.setsetperiodsize(320)
       data = file.readframes(320)
       while data:
           device.write(data)
           data = file.readframes(320)

    I got :

    TypeError: file() argument 1 must be encoded string without NULL bytes, not str

    So is it possible to handle data from p.stdout.read() by wave.open() ?
    Making temporary .wav file isn’t solution.

    Sorry for my english.
    Thanks.

    UPDATE

    Thanks to PM 2Ring for hit about io.BytesIO.

    However resulting code does not work.

    import alsaaudio
    import wave
    from subprocess import Popen, PIPE

    with open('sometrack.mp3', 'rb') as infile:
           p=Popen(['ffmpeg', '-i', '-', '-f','wav', '-'], stdin=infile , stdout=PIPE , stderr=PIPE)
           fobj = io.BytesIO(p.stdout.read())
    fwave = wave.open(fobj, 'rb')

    Trace :

    File "./script.py", line x, in <module>
     fwave = wave.open(fobj, 'rb')
    File "/usr/lib/python2.7/wave.py", line x, in open
     return Wave_read(f)
    File "/usr/lib/python2.7/wave.py", line x, in __init__
     self.initfp(f)
    File "/usr/lib/python2.7/wave.py", line x, in initfp
     raise Error, 'not a WAVE file'
    wave.Error: not a WAVE file
    </module>

    From /usr/lib/python2.7/wave.py :

    ...
    self._file = Chunk(file, bigendian = 0)
    if self._file.getname() != 'RIFF':
       raise Error, 'file does not start with RIFF id'
    if self._file.read(4) != 'WAVE':
       raise Error, 'not a WAVE file'
    ...

    Checking has been failed due to ’bad’ self._file object.

    Inside /usr/lib/python2.7/chunk.py i have found a source of problem :

    ...
    try:
       self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
    except struct.error:
       raise EOFError
    ...

    Because struct.unpack(strflag+’L’, file.read(4))[0] returns 0.
    But this function works correct.

    As specified here :

    "5-8 bytes - File size(integer)
    Size of the overall file - 8 bytes, in bytes (32-bit integer). Typically, you’d fill this in after creation."
    That’s why my script doesn’t work. wave.open and other functions cannot handle my file object because self.chunksize = 0. Looks like ffmpeg cannot insert File size when using PIPE.

    SOLUTION

    It’s simple.
    I’ve changed init function of Chunk class :

    After :

    ...
    try:
       self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
    except struct.error:
       raise EOFError
    ...

    Before :

    ...
    try:
       self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
       currtell = file.tell()
       if self.chunksize == 0:
           file.seek(0)
           file.read(currtell)
           self.chunksize = len(file.read())-4
           file.seek(0)
           file.read(currtell)
    except struct.error:
       raise EOFError
    ...

    Of course editing of original module is bad idia. So I’ve create custom forks for 2 classes Chunk and Wave_read.

    Working but unstable full code you can find here.

    Sorry for my awful english.

    Thanks.

  • Ffmpeg only receives a piece of information from the pipe

    4 juillet 2017, par Maxim Fedorov

    First of all - my english is not very good, i`m sorry for that.

    I use ffmpeg from c# to convert images to video. To interact with ffmpeg, I use pipes.

    public async Task ExecuteCommand(
           string arguments,
           Action<namedpipeserverstream> sendDataUsingPipe)
       {
           var inStream = new NamedPipeServerStream(
               "from_ffmpeg",
               PipeDirection.In,
               1,
               PipeTransmissionMode.Byte,
               PipeOptions.Asynchronous,
               PipeBufferSize,
               PipeBufferSize);

           var outStream = new NamedPipeServerStream(
               "to_ffmpeg",
               PipeDirection.Out,
               1,
               PipeTransmissionMode.Byte,
               PipeOptions.Asynchronous,
               PipeBufferSize,
               PipeBufferSize);

           var waitInConnectionTask = inStream.WaitForConnectionAsync();
           var waitOutConnectionTask = outStream.WaitForConnectionAsync();

           byte[] byteData;

           using (inStream)
           using (outStream)
           using (var inStreamReader = new StreamReader(inStream))
           using (var process = new Process())
           {
               process.StartInfo = new ProcessStartInfo
               {
                   RedirectStandardOutput = true,
                   RedirectStandardError = true,
                   RedirectStandardInput = true,
                   FileName = PathToFfmpeg,
                   Arguments = arguments,
                   UseShellExecute = false,
                   CreateNoWindow = true
               };

               process.Start();

               await waitOutConnectionTask;

               sendDataUsingPipe.Invoke(outStream);

               outStream.Disconnect();
               outStream.Close();

               await waitInConnectionTask;

               var logTask = Task.Run(() => process.StandardError.ReadToEnd());
               var dataBuf = ReadAll(inStream);

               var shouldBeEmpty = inStreamReader.ReadToEnd();
               if (!string.IsNullOrEmpty(shouldBeEmpty))
                   throw new Exception();

               var processExitTask = Task.Run(() => process.WaitForExit());
               await Task.WhenAny(logTask, processExitTask);
               var log = logTask.Result;

               byteData = dataBuf;

               process.Close();
               inStream.Disconnect();
               inStream.Close();
           }

           return byteData;
       }
    </namedpipeserverstream>

    Action "sendDataUsingPipe" looks like

    Action<namedpipeserverstream> sendDataUsingPipe = stream =>
           {
               foreach (var imageBytes in data)
               {
                   using (var image = Image.FromStream(new MemoryStream(imageBytes)))
                   {
                       image.Save(stream, ImageFormat.Jpeg);
                   }
               }
           };
    </namedpipeserverstream>

    When I send 10/20/30 images (regardless of the size) ffmpeg processes everything.
    When I needed to transfer 600/700 / .. images, then in the ffmpeg log I see that it only received 189-192, and in the video there are also only 189-192 images.
    There are no errors in the logs or exceptions in the code.

    What could be the reason for this behavior ?