Recherche avancée

Médias (91)

Autres articles (61)

  • 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 ;

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

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

  • fail continuous transfer video file into buffer

    9 décembre 2016, par chintitomasud

    here I want to process a video file transcoding on demand by using ffmpeg but I failed. without ffmpeg all code runs properly. but using ffmpeg I face some problem. it shows this message :

    Spawning new process /samiul113039/1080.mp4:GET
    piping ffmpeg output to client, pid 10016
    HTTP connection disrupted, killing ffmpeg : 10016
    Spawning new process /samiul113039/1080.mp4:GET
    piping ffmpeg output to client, pid 4796
    HTTP connection disrupted, killing ffmpeg : 4796
    ffmpeg didn’t quit on q, sending signals
    ffmpeg has exited : 10016, code null
    ffmpeg didn’t quit on q, sending signals
    ffmpeg has exited : 4796, code nul
    
    var fs=require('fs');

    var url=require("url");
    var urlvalue="http://csestudents.uiu.ac.bd/samiul113039/1080.mp4";


    var parseurl=url.parse(urlvalue);

    var HDHomeRunIP = parseurl.hostname;
    var HDHomeRunPort = parseurl.port;
    var childKillTimeoutMs = 1000;

    var parseArgs = require('minimist')(process.argv.slice(2));

    // define startsWith for string
    if (typeof String.prototype.startsWith != 'function') {
     // see below for better implementation!
     String.prototype.startsWith = function (str){
       return this.indexOf(str) == 0;
     };
    }
    // Called when the response object fires the 'close' handler, kills ffmpeg
    function responseCloseHandler(command) {
     if (command.exited != true) {
       console.log('HTTP connection disrupted, killing ffmpeg: ' + command.pid);
       // Send a 'q' which signals ffmpeg to quit.
       // Then wait half a second, send a nice signal, wait another half second
       // and send SIGKILL
       command.stdin.write('q\n');
       command.stdin.destroy();
       // install timeout and wait
       setTimeout(function() {
         if (command.exited != true) {
           console.log('ffmpeg didn\'t quit on q, sending signals');
           // still connected, do safe sig kills
           command.kill();
           try {
             command.kill('SIGQUIT');
           } catch (err) {}
           try {
             command.kill('SIGINT');
           } catch (err) {}
           // wait some more!
           setTimeout(function() {
             if (command.exited != true) {
               console.log('ffmpeg didn\'t quit on signals, sending SIGKILL');
               // at this point, just give up and whack it
               try {
                 command.kill('SIGKILL');
               } catch (err) {}
             }
           }, childKillTimeoutMs);
         }    
       }, childKillTimeoutMs);
     }
    }

    // Performs a proxy. Copies data from proxy_request into response
    function doProxy(request,response,http,options) {
     var proxy_request = http.request(options, function (proxy_response) {
       proxy_response.on('data', function(chunk) {
         response.write(chunk, 'binary');
       });
       proxy_response.on('end', function() {
         response.end();
       });
       response.writeHead(proxy_response.statusCode, proxy_response.headers);
     });
     request.on('data', function(chunk) {
       proxy_request.write(chunk, 'binary');
     });
     // error handler
     proxy_request.on('error', function(e) {
       console.log('problem with request: ' + e.message);
       response.writeHeader(500);
       response.end();
     });

     proxy_request.end();
    }

    var child_process = require('child_process');
    var auth = require('./auth');
    // Performs the transcoding after the URL is validated
    function doTranscode(request,response) {
     //res.setHeader("Accept-Ranges", "bytes");
     response.setHeader("Accept-Ranges", "bytes");
     response.setHeader("Content-Type", "video/mp4");        
     response.setHeader("Connection","close");
     response.setHeader("Cache-Control","no-cache");
     response.setHeader("Pragma","no-cache");

     // always write the header
     response.writeHeader(200);

     // if get, spawn command stream it
     if (request.method == 'GET') {
       console.log('Spawning new process ' + request.url + ":" + request.method);

    var command = child_process.spawn('ffmpeg',
                                         ['-i','http://csestudents.uiu.ac.bd/samiul113039/1080.mp4','-f','mpegts','-'],
                                         { stdio: ['pipe','pipe','ignore'] });

        command.exited = false;
       // handler for when ffmpeg dies unexpectedly
       command.on('exit',function(code,signal) {
         console.log('ffmpeg has exited: ' + command.pid + ", code " + code);
         // set flag saying we've quit
         command.exited = true;
         response.end();
       });
       command.on('error',function(error) {
         console.log('ffmpeg error handler - unable to kill: ' + command.pid);
         // on well, might as well give up
         command.exited = true;
         try {
           command.stdin.close();
         } catch (err) {}
         try {
           command.stdout.close();
         } catch (err) {}
         try {
           command.stderr.close();
         } catch (err) {}
         response.end();
       });
       // handler for when client closes the URL connection - stop ffmpeg
       response.on('end',function() {
        responseCloseHandler(command);
       });
       // handler for when client closes the URL connection - stop ffmpeg
       response.on('close',function() {
         responseCloseHandler(command);
       });

       // now stream
       console.log('piping ffmpeg output to client, pid ' + command.pid);
       command.stdout.pipe(response);
       command.stdin.on('error',function(err) {
         console.log("Weird error in stdin pipe ", err);
         response.end();
       });
       command.stdout.on('error',function(err) {
         console.log("Weird error in stdout pipe ",err);
         response.end();
       });
     }
     else {
       // not GET, so close response
       response.end();
     }
    }

    // Load the http module to create an http server.
    var http = require('http');

    // Configure our HTTP server to respond with Hello World to all requests.
    var server = http.createServer(function (request, response) {
     //console.log("New connection from " + request.socket.remoteAddress + ":" + request.url);

     if (auth.validate(request,response)) {
       // first send a HEAD request to our HD Home Run with the same url to see if the address is valid.
       // This prevents an ffmpeg instance to spawn when clients request invalid things - like robots.txt/etc
       var options = {method: 'HEAD', hostname: HDHomeRunIP, port: HDHomeRunPort, path: request.url};
       var req = http.request(options, function(res) {
         // if they do a get, and it returns good status
         if (request.method == "GET" &&
             res.statusCode == 200 &&
             res.headers["content-type"] != null &&
             res.headers["content-type"].startsWith("video")) {
           // transcode is possible, start it now!
           doTranscode(request,response);
         }
         else {
           // no video or error, cannot transcode, just forward the response from the HD Home run to the client
           if (request.method == "HEAD") {
             response.writeHead(res.statusCode,res.headers);
             response.end();
           }
           else {
             // do a 301 redirect and have the device response directly  

             // just proxy it, that way browser doesn't redirect to HDHomeRun IP but keeps the node.js server IP
             options = {method: request.method, hostname: HDHomeRunIP, /* port: HDHomeRunPort, */path: request.url};
             doProxy(request,response,http,options);
           }
         }
       });
       req.on('error', function(e) {
         console.log('problem with request: ' + e.message);
         response.writeHeader(500);
         response.end();
       });
       // finish the client request, rest of processing done in the async callbacks
       req.end();
     }
    });

    // turn on no delay for tcp
    server.on('connection', function (socket) {
     socket.setNoDelay(true);
    });
    server.listen(7000);
  • FFmpeg sws_scale crash at certain resolution

    23 mai 2016, par Tamás Szobonya

    I’m having a weird issue with sws_scale. The problem is, that at certain resolutions i got an Access violation reading location exception. Resolutions like 1920x1080, 1600x900 works, but 1280x720 doesn’t ? This happens in a c++ cli code which is called from c#. Every project is x64 build (no Any CPU) on a Win7 x64.

    c++ cli code :

    void FFmpegWrapper::Codec::E(int width, int height, IntPtr dataIn, [Out] IntPtr %dataOut)
    {
       int ret;
       AVFrame *f, *fIn, *fOut;
       f = av_frame_alloc();
       fIn = av_frame_alloc();
       fOut = av_frame_alloc();

       fIn->format = AV_PIX_FMT_RGB24;
       fIn->width = width;
       fIn->height = height;
       ret = av_image_alloc(fIn->data, fIn->linesize, width, height, AV_PIX_FMT_RGB24, 32);

       f->format = AV_PIX_FMT_YUV420P;
       f->width = width;
       f->height = height;
       ret = av_image_alloc(f->data, f->linesize, width, height, AV_PIX_FMT_YUV420P, 32);

       fOut->format = AV_PIX_FMT_RGB24;
       fOut->width = width;
       fOut->height = height;
       ret = av_image_alloc(fOut->data, fOut->linesize, width, height, AV_PIX_FMT_RGB24, 32);


       uint8_t *data = (uint8_t*)dataIn.ToPointer();
       fIn->data[0] = data;

       //with or without struct no difference
       /*struct */SwsContext *convertCtx = sws_getContext(width, height, AV_PIX_FMT_RGB24, width, height, AV_PIX_FMT_YUV420P, 0, NULL, NULL, NULL);

       // CRASH here
       sws_scale(convertCtx, fIn->data, fIn->linesize, 0, height, f->data, f->linesize);

       convertCtx = sws_getContext(width, height, AV_PIX_FMT_YUV420P, width, height, AV_PIX_FMT_RGB24, 0, NULL, NULL, NULL);

       sws_scale(convertCtx, f->data, f->linesize, 0, height, fOut->data, fOut->linesize);

       dataOut = (IntPtr)fIn->data[0];

    }

    And its called from c# like this :

    FFmpegWrapper.Codec test = new FFmpegWrapper.Codec();

    Bitmap image = new Bitmap(w, h, PixelFormat.Format24bppRgb);

    // Get a screenshot from the desktop
    Screen.Capture(w, h, image, PixelFormat.Format24bppRgb);

    Rectangle rec = new Rectangle(0, 0, image.Width, image.Height);
    BitmapData bitmapData = image.LockBits(rec, ImageLockMode.ReadWrite, image.PixelFormat);

    IntPtr ptr = bitmapData.Scan0;

    IntPtr testptr1;

    test.E(w, h, ptr, out testptr1);

    // We never reach this with 1280x720 resolution
    Bitmap bmp = new Bitmap(w, h, w * 3, PixelFormat.Format24bppRgb, testptr1);

    bmp.Save(@"H:\sajt1.bmp", ImageFormat.Bmp);

    What i don’t understand is, how can it work with certain resolutions and crash with others ?
    Using 20160512-git-cd244fa-win64 version of ffmpeg.

    Edit :
    It seems, that changing AV_PIX_FMT_RGB24 to AV_PIX_FMT_BGR24 fixes it, but I’m not sure why. I know that .Net stores the pixels in bgr, but why does wrong format crashes it ? And only at some resolutions ?

  • ffmpeg live stream transcoding. A/V sync issues on fast camera movement

    21 août 2020, par Kelsnare
      

    1. I create a webrtc peer connection with my server(only stun)
    2. 


    3. Using pion webrtc for the server
    4. 


    5. I write the received RTP packets as VP8 and opus streams, as described here, to two pipes (the writers ; created with os.Pipe() in golang)
    6. 


    7. The read ends of these two pipes are received by ffmpeg as inputs (via exec.Command.ExtraFiles) for transcoding using libx264 and aac into a single stream. The command :
    8. 


    


    ffmpeg -re -i pipe:3 -re -r pipe:4 -c:a aac -af aresample=48000 -c:v libx264 -x264-params keyint=48:min-keyint=24 -profile:v main -preset ultrafast -tune zerolatency -crf 20 -fflags genpts -avoid_negative_ts make_zero -vsync vfr -map 0:0,0:0 -map 1:0,0:0 -f matroska -strict -2 pipe:5


    


      

    1. The above command outputs to a pipe(:5) the read end of which is being taken as input by the following :
    2. 


    


    ffmpeg -hide_banner -y -re -i pipe:3 -sn -vf scale=-1:'min(ih,360)' -c:v libx264 -pix_fmt yuv420p -ca aac -b:a 128k -b:v 1400k -maxrate 1498k -bufsize 2100k -hls_time 1 -hls_playlist_type event -hls_base_url /workdir/streamID/360p -hls_segment_filename /workdir/streamID/360p/360_%%03d.ts -f hls /workdir/streamID/360p.m3u8


    


      

    1. This works fine as long as there are no movements of my webcam. The moment that happens the video speed suddenly increases for a split second and audio delay gets introduced. This delay keeps increasing each time I shake my webcam.
    2. 


    


    The first command in point 4 above - if written to a file separately will be absolutely fine, in terms of a/v sync, even with vigorous camera shaking. The weird audio delay is only when transcoding for hls output irrespective of whether I'm actually viewing it live or playing it back later.

    


    This is my first time working with ffmpeg/hls/webrtc - would be really helpful if I could be pointed in the correct direction at least to be able to debug this or even know why this happens. Any and all help is greatly appreciated