Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Uncaught ReferenceError : CCapture is not defined ?

    29 novembre 2018, par user9964622

    I have a simple app to create a canvas and render it. I am using capture js and FFmpeg module for converting videos in my app, but when I run the app I get the following reference error:

    Uncaught ReferenceError: CCapture is not defined
        at test.js:67`
    

    Here is test.js:

    (function() {
      "use strict";
    
      var framesPerSecond = 60;
      var numFrames = 20; //framesPerSecond * 60 * 2;
      var thickness = 100;
      var speed = 4;
      var frameNum = 0;
    
      var canvas = document.getElementById("c");
      var ctx = canvas.getContext("2d");
      canvas.width = 1280;
      canvas.height = 720;
    
      var progressElem = document.getElementById("progress");
      var progressNode = document.createTextNode("");
      progressElem.appendChild(progressNode);
    
      function onProgress(progress) {
        progressNode.nodeValue = (progress * 100).toFixed(1) + "%";
      }
    
      function showVideoLink(url, size) {
        size = size ? (" [size: " + (size / 1024 / 1024).toFixed(1) + "meg]") : " [unknown size]";
        var a = document.createElement("a");
        a.href = url;
        var filename = url;
        var slashNdx = filename.lastIndexOf("/");
        if (slashNdx >= 0) {
          filename = filename.substr(slashNdx + 1);
        }
        a.download = filename;
        a.appendChild(document.createTextNode(url + size));
        document.body.appendChild(a);
      }
    
      var capturer = new CCapture( {
        format: 'ffmpegserver',
        //workersPath: "3rdparty/",
        //format: 'gif',
        verbose: false,
        framerate: framesPerSecond,
        onProgress: onProgress,
        //extension: ".mp4",
        //codec: "libx264",
      } );
      capturer.start();
    
      function drawLines(ctx) {
        for (var xx = -canvas.width; xx < canvas.width; xx += 2) {
          var l = (xx - (-canvas.width)) / (canvas.width * 2);
          ctx.beginPath();
          ctx.moveTo(xx, -canvas.height);
          ctx.lineTo(xx,  canvas.height);
          ctx.strokeStyle = "hsla(" + ((l * 360 * 24) % 360) + ",100%,50%,0.5)";
          ctx.stroke();
        }
      }
    
      function render(time) {
        ctx.fillStyle = "#000";
        ctx.fillRect(0, 0, canvas.width, canvas.height);
    
        ctx.fillStyle = "#FFF";
        for (var xx = 0; xx < canvas.width + thickness * 2; xx += thickness * 2) {
          var x = xx - (frameNum * speed % (thickness * 2));
          ctx.fillRect(x, 0, thickness, canvas.height);
        }
    
        ctx.save();
        ctx.globalCompositeOperation = "difference";
    
        ctx.font = "400px sans-serif";
        ctx.textAlign = "center";
        ctx.textBaseline = "middle";
        ctx.fillText(frameNum, canvas.width / 2, canvas.height / 2);
    
    
        ctx.save();
        ctx.translate(canvas.width * 0.5, canvas.height * 0.5);
        ctx.rotate(frameNum * 0.01);
        ctx.translate(canvas.width * 0.25, 0);
        drawLines(ctx);
        ctx.restore();
    
        ctx.save();
        ctx.translate(canvas.width * 0.5, canvas.height * 0.5);
        ctx.rotate(frameNum * -0.013);
        ctx.translate(canvas.width * 0.37, 0);
        drawLines(ctx);
        ctx.restore();
    
        ctx.restore();
    
        capturer.capture(canvas);
    
        ++frameNum;
        if (frameNum === numFrames) {
          capturer.stop();
          capturer.save(showVideoLink);
        } else {
          requestAnimationFrame(render);
        }
      }
      requestAnimationFrame(render);
    }());
    
  • How to use ffmpeg with laravel 5.7 on a shared hosting with limited resources/access

    29 novembre 2018, par DestinyB

    I have search through different forums and online resources on how I can use ffmpeg on my laravel 5.7 application on a shared host but have not gotten any solution. I actually installed ffmpeg on my project following the instructions from this link How to Install FFMPEG in Laravel.

    I also downloaded the binary files and save them to my local drive C:// in my system with windows 8.1 Operating System. Then I connected my binary as show bellow;

      $ffprobe = FFMpeg\FFProbe::create([
            'ffmpeg.binaries'  => 'C:/FFmpeg/bin/ffmpeg.exe', // the path to the FFMpeg binary
            'ffprobe.binaries' => 'C:/FFmpeg/bin/ffprobe.exe', // the path to the FFProbe binary
            'timeout'          => 3600, // the timeout for the underlying process
            'ffmpeg.threads'   => 12,   // the number of threads that FFMpeg should use
        ]);
    

    I also did the path setting in the system environmental variables settings and everything was working great while serving the website from XAMPP Server.

    The problem I have is that I have uploaded the project to a shared host that I dont have access to check if they have the ffmpeg on the server or not and the host provider could not really give me a helpful information about that. So, I uploaded the binary files into a folder in my filemanger on the cpanel and named it "binary files". Then I changed my codes as given bellow;

    $ffmpeg = FFMpeg\FFMpeg::create([
            'ffmpeg.binaries'  => '/home/username/binary_files/bin/ffmpeg.exe', // the path to the FFMpeg binary
            'ffprobe.binaries' => '/home/username/binary_files/bin/ffprobe.exe',  // the path to the FFProbe binary
            'timeout'          => 3600, // the timeout for the underlying process
            'ffmpeg.threads'   => 1,   // the number of threads that FFMpeg should use
        ]);
    

    But still I get error that Unable to load FFProbe as shown in this Image from the code

        public static function create($configuration, LoggerInterface $logger = null)
    {
        if (!$configuration instanceof ConfigurationInterface) {
            $configuration = new Configuration($configuration);
        }
    
        $binaries = $configuration->get('ffprobe.binaries', array('avprobe', 'ffprobe'));
    
        try {
            return static::load($binaries, $logger, $configuration);
        } catch (BinaryDriverExecutableNotFound $e) {
            throw new ExecutableNotFoundException('Unable to load FFProbe', $e->getCode(), $e);
        }
    }
    

    The major thing I am doing on my project is to convert video into proper encoded streaming video as well as automatically generate a .png or .jpg thumbnail from the video while uploading. So in case if there is an alternative other than ffmpeg to solve this or anyone that have use the ffmpeg library on a shared hosted before should help. Please!

  • How to render or convert animation to video format ?

    29 novembre 2018, par user9964622

    I have created animation using tweenjs and createjs libraries createjs and tweenjs, now, I'd like to convert these animations to video files (MPEG4, or other, doesn't matter) or how can I render it in the backend using nodejs?

    I have animation looking like this: Animated

    Here is solution I have tried so far using nodejs and ffmpeg module

    var express = require('express');
    var cors = require('cors')
    var path = require('path');
    var app = express();
    var ffmpeg = require('ffmpeg');
    //Cors Middleware
    app.use(cors());
    // Body Parser Middleware
    app.use(bodyParser.json())
    // Port Number
    const port = process.env.PORT || 8000;
    //video processing
    
    try {
        var process = new ffmpeg('/path/to/your_movie.mp4');
        process.then(function (video) {
    
            video
            .setVideoSize('640x?', true, true, '#fff')
            .audioCodec('libmp3lame')
            .videoCodec('libx264')
            .setAudioCodec('libfaac')
            .setAudioChannels(2)
            .save('/path/to/save/your_movie.mp4', function (error, file) {
                if (!error)
                    console.log('Video file: ' + file);
            });
    
        }, function (err) {
            console.log('Error: ' + err);
        });
    } catch (e) {
        console.log(e.code);
    
    
    
    app.use('/video', video);
    app.get('/', (req, res) => {
      res.send('invaild endpoint');
    });
    
    app.get('*', (req, res) => {
      res.sendFile(path.join(__dirname + '/video-client/dist/video-client/index.html'));
    });
    
    // Start Server
    app.listen(port, () => {
      console.log('Server started on port '+port);
    });
    

    Here is sample of what I am trying to archive check this website logo animation , in this website as u can see when u click preview u can see the message that waits for its rendering after finish rendering it gives the option to download the rendered video file, on my side I am able to create animation but am not able to render it so that it can convert to video format .

    I am new to nodejs and backend stuff in general, unfortunately, my solution does not work so far, and I am stuck. I need help

    Is this the right way to create video from animation if not what is the best way? ,

    please help, any suggestion or tutorials will be appreciated, thanks

  • How to render animated content in backend using nodejs ?

    29 novembre 2018, par user9964622

    I have created animation using tweenjs and createjs libraries createjs and tweenjs, now, I'd like to convert these animations to video files (MPEG4, or other, doesn't matter) or how can I render it in the backend using nodejs?

    I have animation looking like this: Animated

    Here is solution I have tried so far using nodejs and ffmpeg module

    var express = require('express');
    var cors = require('cors')
    var path = require('path');
    var app = express();
    var ffmpeg = require('ffmpeg');
    //Cors Middleware
    app.use(cors());
    // Body Parser Middleware
    app.use(bodyParser.json())
    // Port Number
    const port = process.env.PORT || 8000;
    //video processing
    
    try {
        var process = new ffmpeg('/path/to/your_movie.mp4');
        process.then(function (video) {
    
            video
            .setVideoSize('640x?', true, true, '#fff')
            .audioCodec('libmp3lame')
            .videoCodec('libx264')
            .setAudioCodec('libfaac')
            .setAudioChannels(2)
            .save('/path/to/save/your_movie.mp4', function (error, file) {
                if (!error)
                    console.log('Video file: ' + file);
            });
    
        }, function (err) {
            console.log('Error: ' + err);
        });
    } catch (e) {
        console.log(e.code);
    
    
    
    app.use('/video', video);
    app.get('/', (req, res) => {
      res.send('invaild endpoint');
    });
    
    app.get('*', (req, res) => {
      res.sendFile(path.join(__dirname + '/video-client/dist/video-client/index.html'));
    });
    
    // Start Server
    app.listen(port, () => {
      console.log('Server started on port '+port);
    });
    

    Here is tutorial of what I want to achieve but its written in js and PHP , I want the same but in nodejs html canvas animations to video

    I am new to nodejs and backend stuff in general, unfortunately, my solution does not work so far, and I am stuck. I need help

    Is this the right way to create video from animation if not what is the best way? ,

    please help, any suggestion or tutorials will be appreciated, thanks

  • How to use filtering and stream copy together with ffmpeg ?

    28 novembre 2018, par chole
    ffmpeg -ss 0 -t 8  -i  input.mp4  -acodec copy -vcodec copy output.mp4
    

    can set codec. However, to filter:

    ffmpeg  -i  input.mp4  -vf  crop=100:100:0:0 output.mp4
    

    if combined:

    Filtergraph 'crop=100:100:0:0' was defined for video output stream 0:0 but codec copy was selected.
    Filtering and streamcopy cannot be used together.
    

    how to set codec like time clip?