Recherche avancée

Médias (91)

Autres articles (39)

  • Ajouter notes et légendes aux images

    7 février 2011, par

    Pour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
    Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
    Modification lors de l’ajout d’un média
    Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)

  • Librairies et binaires spécifiques au traitement vidéo et sonore

    31 janvier 2010, par

    Les logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
    Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
    Binaires complémentaires et facultatifs flvtool2 : (...)

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

Sur d’autres sites (9309)

  • What could make the JVM fail catastrophically (or hang indefinitely) when executing ffmpeg ?

    13 octobre 2022, par Brendan Hill

    I am trying to debug a Java microservice hosted in Kubernetes, in pods which are created dynamically by KEDA feeding off an SQS queue. Pods have dedicated resources of up to 3GB RAM, which to our knowledge is sufficient (although this assumption might need to be revisited).

    


    The service at one point calls ffmpeg, and sometimes randomly this appears to cause catastrophic failure of the process. (Sometimes it succeed on the next attempt of exactly the same job.)

    


    It is so catastrophic that no logs are generated, no exceptions thrown, and even the finally {} block is not even triggered.

    


    This appears to occur in the remote k8 environment only and I have failed to replicate it locally.

    


    What general reasons are there for a Java, executing another program with Execution.executeAndWait(), to fail so catastrophically ?

    


    How could I continue investigating the cause ?

    


        public void executeFfmpeg(String[] cmd) {

        log.info("1");  // <-- this IS logged!
        int retval = 0;
        try {
            retval = Execution.executeAndWait(cmd, stdout, stderr);
            if ( retval != 0 ) {
                log.error("FFMPEG broke. stderr: {}", errorFile);   // <-- this log never occurs
                throw new TranscodingFailedException("ffmpeg command failed: " + String.valueOf(retval) + " - " + String.join(" ", cmd)); // <-- never thrown
            }
        } catch (InterruptedException e) {
            log.error("InterruptedException caught in the middle of the execution of ffmpeg. this will now proceed to crash...", e); // <-- this log never occurs
            throw e;
        } finally {
            log.info("2"); // <-- THIS IS NOT CALLED!!! even in the finally block!?
            stdout.close();
            stderr.close();
        }
    }


/// Execution class:

    public static int executeAndWait(String[] cmd, Writer stdout, Writer stderr) throws IOException, InterruptedException {
        Process proc = null;
        ExecutorService outExecutor = Executors.newSingleThreadExecutor();
        ExecutorService errExecutor = Executors.newSingleThreadExecutor();

        try {
            proc = exec(cmd, stdout, stderr, outExecutor, errExecutor);
            // block until sub-process exits
            return proc.waitFor();
        } finally {
            shutdownProcess(proc);
            shutdownAndAwaitTermination(outExecutor);
            shutdownAndAwaitTermination(errExecutor);
        }
    }



    private static void shutdownProcess(Process proc) {
        try {
            if (proc != null) {
                proc.destroy();
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    private static void shutdownAndAwaitTermination(ExecutorService pool) {
        try {
            pool.shutdown(); // Disable new tasks from being submitted
            try {
                // Wait a while for existing tasks to terminate
                if (!pool.awaitTermination(800, TimeUnit.MILLISECONDS)) {
                    pool.shutdownNow(); // Cancel currently executing tasks
                }
            } catch (InterruptedException ie) {
                // (Re-)Cancel if current thread also interrupted
                pool.shutdownNow();
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    private static Process exec(String[] cmd, Writer stdout, Writer stderr, ExecutorService outExecutor, ExecutorService errorExecutor) throws IOException {
        // execute input command in a sub-process
        Process proc = Runtime.getRuntime().exec(cmd);

        StreamConsumer outConsumer = new StreamConsumer(proc.getInputStream(), stdout);
        StreamConsumer errConsumer = new StreamConsumer(proc.getErrorStream(), stderr);

        // execute data read/write in separate threads
        outExecutor.submit(outConsumer);
        errorExecutor.submit(errConsumer);

        return proc;

    }


    


    An example of the ffmpeg command is :

    


    /usr/local/bin/ffmpeg -i /tmp/transcode-a5ff7706-488a-4e24-9ef8-9657d1254a26626348807122071896/str_CAM_Z2VH_con_H0Zqr2flbT.webm -filter_complex [0:v]setpts=0.8363824*PTS,scale=w=1280:h=720:force_original_aspect_ratio=1,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[0:a]aresample=async=1000[0sync] -map [v0] -map [0sync] -vsync vfr -r 25 -c:v libx264 -c:a mp3 /tmp/transcode-a5ff7706-488a-4e24-9ef8-9657d1254a26626348807122071896/intermediate-str_CAM_Z2VH_con_H0Zqr2flbT.webm.mkv | stdout: /tmp/intermediate-stdout-12310474463787935763.log | stderr: /tmp/intermediate-stderr-12166558954928907997.log


    


  • Multiple streams with ffmpeg and python opencv

    27 janvier 2023, par share2020 uis

    I need to run multiple streams from python open cv to rtmp/rtsp with FFMPG. Now I can see two streams are going via ffmpeg (in console the information are mixed). In destinations the first stream is empty while second stream plays correctly (first stream metedata is reaching to destination).

    


    Multiple stream semaratly in destination.

    


    ## st.txt = 'rtsp://ip:port/source/1' & 'rtsp://ip:port/source/2'
from multiprocessing.pool import ThreadPool
import cv2
import random
import subprocess

def f(x):
    name = (x.split('/'))[-1]
    y=30
    if len(x)==1:
        x = int(x)

    cam = cv2.VideoCapture(x)
    width = cam.get(cv2.CAP_PROP_FRAME_WIDTH)
    height = cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
    fps = cam.get(cv2.CAP_PROP_FPS)
    def streamer():
        command = ['ffmpeg',
                            '-r', str(fps ),
                            '-y',
                            '-f', 'rawvideo',

                            '-pix_fmt', 'bgr24',
                            '-s', "{}x{}".format(int(width),int(height)),
                            '-i', '-',
                            '-c:v', 'libx264',
                            '-pix_fmt', 'yuv420p',
                            '-preset', 'fast',
                            '-bufsize','7000k',
                            '-flvflags', 'no_duration_filesize', 
                            '-g','180',
                            '-f', 'flv',
                            'rtmp://ip:port/live/'+ str(name)]                        
        return command                        
    p_stream = subprocess.Popen(streamer() , stdin=subprocess.PIPE)


    while cam.isOpened():
                ret, frame = cam.read()
                if not ret:
                    break
                cv2.imshow(str(name),frame)
                p_stream.stdin.write(frame.tobytes()) 
                key = cv2.waitKey(1)
                
                if key == ('w'):
                    cam.release()
                    cv2.destroyAllWindows()
                    break

            





def ls():
    with open(r'st.txt') as f:
        lns = [line.rstrip('\n') for line in f]  
         return lns


if __name__ == '__main__':
    
    pool = ThreadPool()
    results = pool.map(f, ls())


    


  • Streaming images to ffmpeg out of order

    6 novembre 2022, par Jason C

    I have an algorithm that generates a video frame by frame, which I am refactoring to stream the images to ffmpeg rather than save them all to disk first.

    


    The algorithm currently generates and saves a bunch of QImages then executes ffmpeg (with QProcess). The new version will generate QImages then stream them out to ffmpeg's stdin via QProcess. I can do all that just fine.

    


    The issue is, I'm not actually generating the images serially, I'm generating them on a thread pool, maybe 12-16 at a time (just using QtConcurrent). I'd like to keep this parallelism for performance reasons, since the operation (even excluding image encoding and file I/O) does take a long time.

    


    So my question is, does ffmpeg have something like image2pipe but that can take the images slightly out of order (let's assume there's some sane maximum offset, +/- 20 or so) ?

    


    If not, my solution will be to divide the image set into small batches, then for each batch, run it on the pool, reorder it, and stream them in the correct order ; sacrificing some fraction of performance depending on the batch size. I'd rather not do that just because the code right now is dirt simple, and simple is good. So I'm wondering if there's a way to get ffmpeg to accept the images out of order.

    


    They're at a fixed frame rate, if that is useful (maybe there's some way to set PTS's or something, then I just find a codec + container that can store out-of-order frames).