Recherche avancée

Médias (1)

Mot : - Tags -/ticket

Autres articles (48)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, 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 (...)

  • Mise à disposition des fichiers

    14 avril 2011, par

    Par défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
    Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
    Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)

  • Installation en mode ferme

    4 février 2011, par

    Le mode ferme permet d’héberger plusieurs sites de type MediaSPIP en n’installant qu’une seule fois son noyau fonctionnel.
    C’est la méthode que nous utilisons sur cette même plateforme.
    L’utilisation en mode ferme nécessite de connaïtre un peu le mécanisme de SPIP contrairement à la version standalone qui ne nécessite pas réellement de connaissances spécifique puisque l’espace privé habituel de SPIP n’est plus utilisé.
    Dans un premier temps, vous devez avoir installé les mêmes fichiers que l’installation (...)

Sur d’autres sites (9004)

  • Piping ffmpeg thumbail output to another program

    21 septembre 2018, par Ryan Griggs

    I’m trying to capture frames from a live video stream (h.264) and pipe the resulting JPG images to a Node JS script, instead of saving these individual frames directly to .jpg files.

    As a test, I created the following Node JS script, to simply capture the incoming piped data, then dump it to a file :

    // pipe.js - test pipe output
    var fs = require('fs');
    var data = '';

    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    var filename = process.argv[2];

    process.stdin.on('data', (chunk) => {
           console.log('Received data chunk via pipe.');
           data += chunk;
    });

    process.stdin.on('end', () => {
           console.log('Data ended.');
           fs.writeFile(filename, data, err => {
                   if (err) {
                           console.log('Error writing file: error #', err);
                   }
           });
           console.log('Saved file.');
    });

    console.log('Started...  Filename = ' + filename);

    Here’s the ffmpeg command I used :

    ffmpeg -vcodec h264_mmal -i "rtsp://[stream url]" -vframes 1 -f image2pipe - | node pipe.js test.jpg

    This generated the following output, and also produced a 175kB file which contains garbage (unreadable as a jpg file anyway). FYI using ffmpeg to export directly to a jpg file produced files around 25kB in size.

    ...
    Press [q] to stop, [?] for help
    [h264_mmal @ 0x130d3f0] Changing output format.
    Input stream #0:0 frame changed from size:1280x720 fmt:yuvj420p to size:1280x720 fmt:yuv420p
    [swscaler @ 0x1450ca0] deprecated pixel format used, make sure you did set range correctly
    Received data chunk via pipe.
    Received data chunk via pipe.
    frame=    1 fps=0.0 q=7.7 Lsize=      94kB time=00:00:00.40 bitrate=1929.0kbits/s speed=1.18x
    video:94kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
    Received data chunk via pipe.
    Data ended.
    Saved file.

    You can see that the Node JS script is receiving piped data (per the "Received data via pipe" messages above. However, it doesn’t seem to be outputting a valid JPG file. I can’t find a way to specifically request that ffmpeg output JPG format, since there is no -vcodec option for JPG. I tried using -vcodec png and outputting to a .png file, but the resulting file was about 2MB in size and also unreadable as a png file.

    Is this a problem caused by using utf8 encoding, or am I doing something else wrong ?

    Thanks for any advice.

    UPDATE : OK I got it to send a single jpg image correctly. The issue was in the way Node JS was capturing the stream data. Here’s a working script :

    // pipe.js - capture piped binary input and write to file
    var fs = require('fs');
    var filename = process.argv[2];

    console.log("Opening " + filename + " for binary writing...");

    var wstream = fs.createWriteStream(filename);

    process.stdin.on('readable', () => {
           var chunk = '';
           while ((chunk = process.stdin.read()) !== null) {
                   wstream.write(chunk);   // Write the binary data to file
                   console.log("Writing chunk to file...");
           }
    });

    process.stdin.on('end', () => {
           // Close the file
           wstream.end();
    });

    However, now the problem is this : when piping the output of ffmpeg to this script, how can I tell when one JPG file ends and another one begins ?

    ffmpeg command :

    ffmpeg -vcodec h264_mmal -i "[my rtsp stream]" -r 1 -q:v 2 -f singlejpeg - | node pipe.js test_output.jpg

    The test_output.jpg file continues to grow as long as the script runs. How can I instead know when the data for one jpg is complete and another one has started ?
    According to this, jpeg files always start with FF D8 FF and end with FF D9, so I guess I can check for this ending signature and start a new file at that point... any other suggestions ?

  • Video encoded by ffmpeg.exe giving me a garbage video in c# .net

    10 septembre 2018, par Amit Yadav

    I want to record video through webcam and file to be saved in .mp4 format. So for recording i am using AforgeNet.dll for recording and for mp4 format i am encoding raw video into mp4 using ffmpeg.exe using NamedPipeStreamServer as i receive frame i push into the named pipe buffer. this process works fine i have checked in ProcessTheErrorData event but when i stop recording the output file play garbage video shown in the image below

    enter image description here

    Here is Code for this

      Process Process;
     NamedPipeServerStream _ffmpegIn;
       byte[]  _videoBuffer ;
       const string PipePrefix = @"\\.\pipe\";
       public void ffmpegWriter()
       {
           if(File.Exists("outputencoded.mp4"))
           {
               File.Delete("outputencoded.mp4");
           }

           _videoBuffer = new byte[widht * heigth * 4];
           var audioPipeName = GetPipeName();
           var videoPipeName = GetPipeName();
           var videoInArgs = $@" -thread_queue_size 512 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt rgb32 -video_size 640x480 -i \\.\pipe\{videoPipeName}";
           var videoOutArgs = $"-vcodec libx264 -crf 15 -pix_fmt yuv420p -preset ultrafast -r 10";
           _ffmpegIn = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, _videoBuffer.Length);
           Process=StartFFmpeg($"{videoInArgs} {videoOutArgs} \"{"outputencoded.mp4"}\"", "outputencoded.mp4");
       }

    bool WaitForConnection(NamedPipeServerStream ServerStream, int Timeout)
       {
           var asyncResult = ServerStream.BeginWaitForConnection(Ar => { }, null);

           if (asyncResult.AsyncWaitHandle.WaitOne(Timeout))
           {
               ServerStream.EndWaitForConnection(asyncResult);

               return ServerStream.IsConnected;
           }

           return false;
       }
     static string GetPipeName() => $"record-{Guid.NewGuid()}";

    public static Process StartFFmpeg(string Arguments, string OutputFileName)
           {
               var process = new Process
               {
                   StartInfo =
                   {
                       FileName = "ffmpeg.exe",
                       Arguments = Arguments,
                       UseShellExecute = false,
                       CreateNoWindow = true,
                       RedirectStandardError = true,
                       RedirectStandardInput = true,

                   },
                   EnableRaisingEvents = true
               };

               //  var logItem = ServiceProvider.Get<ffmpeglog>().CreateNew(Path.GetFileName(OutputFileName));

               process.ErrorDataReceived += (s, e) => ProcessTheErrorData(s,e);

               process.Start();

               process.BeginErrorReadLine();

               return process;
           }
    </ffmpeglog>

    and Writing each frame like this.

    private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
           {

               try
               {
                   if (_recording)
                   {

                       using (var bitmap = (Bitmap) eventArgs.Frame.Clone())
                       {
                          var _videoBuffers = ImageToByte(bitmap);


                               if (_firstFrameTime != null)
                               {
                               bitmap.Save("image/" + DateTime.Now.ToString("ddMMyyyyHHmmssfftt")+".bmp");

                                   _lastFrameTask?.Wait();


                                   _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffers, 0, _videoBuffers.Length);
                               }
                               else
                               {
                                   if (_firstFrame)
                                   {
                                       if (!WaitForConnection(_ffmpegIn, 5000))
                                       {
                                           throw new Exception("Cannot connect Video pipe to FFmpeg");
                                       }

                                       _firstFrame = false;
                                   }

                                   _firstFrameTime = DateTime.Now;
                                   _lastFrameTask?.Wait();

                                   _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffers, 0, _videoBuffers.Length);

                               }

                       }
                   }
                   using (var bitmap = (Bitmap) eventArgs.Frame.Clone())
                   {
                       var bi = bitmap.ToBitmapImage();
                       bi.Freeze();
                       Dispatcher.CurrentDispatcher.Invoke(() => Image = bi);
                   }
               }
               catch (Exception exc)
               {
                   MessageBox.Show("Error on _videoSource_NewFrame:\n" + exc.Message, "Error", MessageBoxButton.OK,
                       MessageBoxImage.Error);
                   StopCamera();
               }
           }

    Even i have written each frame to disk as bitmap .bmp and frames are correct but i don’t know what’s i am missing here ? please help thanks in advance.

  • How do I properly enable ffmpeg for matplotlib.animation ?

    9 novembre 2018, par spanishgum

    I have covered a lot of ground on stack so far trying to get ffmpeg going so I can make a timelapse video.

    I am on a CentOS 7 machine, running python3.7.0a0.

    python3
    >>> import numpy as np
    >>> np.__version__
    '1.12.0'
    >>> import matplotlib as mpl
    >>> mpl.__version__
    '2.0.0'
    >>> import mpl_toolkits.basemap as base
    >>> base.__version__
    '1.0.7'

    I found this github gist on installing ffmpeg. I used the chromium source, and installed without a prefix option (using the default).

    I have confirmed that ffmpeg is installed, although I don’t know anything about testing whether it works.

    which ffmpeg
    /usr/local/bin/ffmpeg

    ffmpeg -version
    ffmpeg version N-83533-gada281d Copyright (c) 2000-2017 the FFmpeg dev elopers
    built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11
    configuration:
    libavutil      55. 47.100 / 55. 47.100
    libavcodec     57. 80.100 / 57. 80.100
    libavformat    57. 66.102 / 57. 66.102
    libavdevice    57.  2.100 / 57.  2.100
    libavfilter     6. 73.100 /  6. 73.100
    libswscale      4.  3.101 /  4.  3.101
    libswresample   2.  4.100 /  2.  4.100

    I tried to run a few sample examples I found online :

    [1] http://matplotlib.org/examples/animation/basic_example_writer.html

    [2] https://stackoverflow.com/a/23098090/3454650

    Everything works fine up until I try to save the animation file.

    [1]

    anim.save('basic_animation.mp4', writer = FFwriter, fps=30, extra_args=['-vcodec', 'libx264'])

    [2]

    im_ani.save('im.mp4', writer=writer)

    I found here that explictly setting the path to ffmpeg might be necessary so I added this to the top of the test scripts :

    plt.rcParams['animation.ffmpeg_path'] = '/usr/local/bin/ffmpeg'

    I tried a few more tweaks in the code but always get the same response, which I do not know how to begin deciphering :

    Traceback (most recent call last):
     File "testanim.py", line 27, in <module>
       writer.grab_frame()
     File "/usr/local/lib/python3.7/contextlib.py", line 100, in __exit__
       self.gen.throw(type, value, traceback)
     File "/usr/local/lib/python3.7/site-packages/matplotlib/animation.py", line 256, in saving
       self.finish()
     File "/usr/local/lib/python3.7/site-packages/matplotlib/animation.py", line 276, in finish
       self.cleanup()
     File "/usr/local/lib/python3.7/site-packages/matplotlib/animation.py", line 311, in cleanup
       out, err = self._proc.communicate()
     File "/usr/local/lib/python3.7/subprocess.py", line 836, in communicate
       stdout, stderr = self._communicate(input, endtime, timeout)
     File "/usr/local/lib/python3.7/subprocess.py", line 1474, in _communicate
       selector.register(self.stdout, selectors.EVENT_READ)
     File "/usr/local/lib/python3.7/selectors.py", line 351, in register
       key = super().register(fileobj, events, data)
     File "/usr/local/lib/python3.7/selectors.py", line 237, in register
       key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
     File "/usr/local/lib/python3.7/selectors.py", line 224, in _fileobj_lookup
       return _fileobj_to_fd(fileobj)
     File "/usr/local/lib/python3.7/selectors.py", line 39, in _fileobj_to_fd
       "{!r}".format(fileobj)) from None
    ValueError: Invalid file object: &lt;_io.BufferedReader name=6>
    </module>

    Is there something with my configuration that is malformed ? I searched google for this error for some time but never found anything relevant to animations / ffmpeg. Any help would be greatly appreciated.


    UPDATE :

    @LordNeckBeard pointed me here : https://trac.ffmpeg.org/wiki/CompilationGuide/Centos

    I ran into problems with installing the x264 encoding dependency. Some files in libavcodec/*.c (in the make output) were reporting undefined references to several functions. After a wild goose chase found this : https://mailman.videolan.org/pipermail/x264-devel/2015-February/010971.html

    To fix the x264 installation, I simply added some configure flags :

    ./configure --enable-static --enable-shared --extra-ldflags="-lswresample -llzma"

    UPDATE :

    So everything installed fine after fixing the libx264 problems. I went ahead and copied the ffmpeg binary from the ffmpeg_build folder into /usr/local/bin/ffmpeg.

    After running the script I was getting problems where ffmpeg could not find the libx264 shared object. I think I will have to recompile everything using different prefixes. My intuition tells me there are old files laying around after I have messed with everything, using some configuration that is broken.

    So I decided maybe I should just try to use NUX : http://linoxide.com/linux-how-to/install-ffmpeg-centos-7/
    I installed ffmpeg using the new rpm, but to no avail. I still was not able to run ffmpeg because of a missing shared object.

    Finally, instead of usiong files copied into my /usr/local/bin folder, I ran ffmpeg directly from the build bin directory. Turns out that this does work properly !

    So in essence, if I want to install ffmpeg system wide, I need to manually compile from sources again but using a nonlocal prefix.