Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Huge latency in HTTP streaming desktop to browser

    29 janvier 2019, par fineman

    I'm trying to put together a reliable, reasonably low (<2s) latency desktop window share to browser solution. Currently I have:

    client sender using FFMPEG:

    ffmpeg -f gdigrab -i "title=notepad.exe" -r 10 -framerate 10  -c:v libx264 -g 50  -preset fast -tune zerolatency -f rtp rtp://192.168.1.85:1234
    

    server re-stream to HTTP using VLC:

    vlc -vv test.sdp  --sout=#transcode{vcodec=theo,vb=1600,scale=1,channels=1,acodec=none}:http{dst=:8080/webcam.ogg} :no-sout-rtp-sap :no-sout-standard-sap :sout-keep 
    

    where the sdp file is generated from the output of the ffmpeg command

    Client browser:

    
    

    This works and gives good quality. But the latency is terrible (around 10s) and I'm at a loss to know how to tune it. I know that the latency is in the VLC transcoding/restreaming - displaying the RTP stream from the client on the server only has around 1s lag.

    I guess there are two questions - can this approach be sensibly tuned, or is the approach wrong to start with?

  • How to execute commands through PHP ?

    29 janvier 2019, par SuperSimplePimpleDimple

    I am trying to convert videos into MP4 using FFMPEG. I have it set up this way:

    .
    .
    private $ffmpegPath;
    
    public function __construct($con) {
        $this->con = $con;
        $this->ffmpegPath = realpath("ffmpeg/bin/ffmpeg.exe");
    }
    .
    .
    public function convertVideoToMp4($tempFilePath, $finalFilePath){
        $cmd = "$this->ffmpegPath -i $tempFilePath $finalFilePath 2>&1";
    
        $outputLog = array();
        exec($cmd, $outputLog, $returnCode);
    
        if($returnCode != 0){
            foreach ($outputLog as $line){
                echo $line."
    "; return false; } } return true; }

    And in the browser i get the following error: 'C:\xampp\htdocs\Thinksmart First Sprint' is not recognized as an internal or external command".

    In my constructor i have it set up to give me the realpath and i suspect that this is what it does in the command line:

    C:/xampp/htdocs/Thinksmart FIrst Sprint/ffmpeg/bin/ffmpeg.exe -i (file temp name) (file name i want)

    And this should work, but i dont know why it wont. Any ideas? Its my first time working with video conversions.

  • Error : ENOENT : no such file or directory ( AWS Lambda function)

    29 janvier 2019, par Arun

    I am trying to convert the video file to audio using FFMPEG. But I keep getting this error while converting video to audio in AWS Lambda function. I searched a lot of googles but I can't figure out a suitable solution. If anyone knows the answer please share your solution. I referred this video to audio convertion method from this post.

    Error:

    { Error: ENOENT: no such file or directory, lstat '/var/task/tmp/c82f117b7841f1c2a4c9cd86cd93aad9.mp3'
    at Error (native)
    at Object.fs.lstatSync (fs.js:994:11)
    at Object.byteLength (/var/task/node_modules/aws-sdk/lib/util.js:175:30)
    at Request.SET_CONTENT_LENGTH (/var/task/node_modules/aws-sdk/lib/event_listeners.js:161:40)
    at Request.callListeners (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/task/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/task/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/var/task/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/task/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/task/node_modules/aws-sdk/lib/state_machine.js:26:10
    
    message: 'ENOENT: no such file or directory, lstat 
    \'/var/task/tmp/c82f117b7841f1c2a4c9cd86cd93aad9.mp3\'',
    errno: -2,
    code: 'ENOENT',
    syscall: 'lstat',
    path: '/var/task/tmp/c82f117b7841f1c2a4c9cd86cd932332.mp3'}
    

    Code

    const child_process = require('child_process');
    const fs = require('fs');
    const path = require('path');
    
    const AWS = require('aws-sdk');
    const request = require('request');
    const tempy = require('tempy');
    
    const s3 = new AWS.S3();
    
    
    exports.handler = (event, context, callback) => {
      // We're going to do the transcoding asynchronously, so we callback immediately.
      callback();
    
      // Extract the event parameters.
      const { mp3Key, url } = event;
    
      const filename = event.filename || path.basename(mp3Key);
      const logKey = event.logKey || `${mp3Key}.log`;
      const s3Bucket = event.s3Bucket || 'bucket-name;
    
      // Create temporary input/output filenames that we can clean up afterwards.
      const inputFilename = tempy.file();
      const mp3Filename = tempy.file({ extension: 'mp3' });
    
      // Download the source file.
      Promise.resolve().then(() => new Promise((resolve, revoke) => {
        const writeStream = fs.createWriteStream(inputFilename);
        writeStream.on('finish', resolve);
        writeStream.on('error', revoke);
        request(url).pipe(writeStream);
      }))
      // Perform the actual transcoding.
      .then(() => {
        // Use the Exodus ffmpeg bundled executable.
        const ffmpeg = path.resolve(__dirname, 'exodus', 'bin', 'ffmpeg');
    
        // Convert the FLV file to an MP3 file using FFmpeg.
        const ffmpegArgs = [
          '-i', inputFilename,
          '-vn', // Disable the video stream in the output.
          '-acodec', 'libmp3lame', // Use Lame for the mp3 encoding.
          '-ac', '2', // Set 2 audio channels.
          '-q:a', '6', // Set the quality to be roughly 128 kb/s.
          mp3Filename,
        ];
        const process = child_process.spawnSync(ffmpeg, ffmpegArgs);
        console.log("process ", process.stdout);
        // return process;
      // return process.stdout.toString() + process.stderr.toString();
      })
      // Upload the generated MP3 to S3.
      .then(logContent => new Promise((resolve, revoke) => {
        console.log("inside s3 upload", mp3Filename)
        s3.putObject({
          Body: fs.createReadStream(mp3Filename),
          Bucket: s3Bucket,
          Key: mp3Key,
          ContentDisposition: `attachment; filename="${filename.replace('"', '\'')}"`,
          ContentType: 'audio/mpeg',
        }, (error) => {
          if (error) {
            revoke(error);
          } else {
            // Update a log of the FFmpeg output.
            const logFilename = path.basename(logKey);
            console.log("log file upload")
            s3.putObject({
              Body: logContent,
              Bucket: s3Bucket,
              ContentType: 'text/plain',
              ContentDisposition: `inline; filename="${logFilename.replace('"', '\'')}"`,
              Key: logKey,
            }, resolve);
          }
        })
      }))
      .catch(console.error)
      // Delete the temporary files.
      .then(() => {
        [inputFilename, mp3Filename].forEach((filename) => {
          if (fs.existsSync(filename)) {
            fs.unlinkSync(filename);
          }
        });
      });
    };
    
  • Want to overlay video over an Image - FFMPEG

    29 janvier 2019, par Siddharth

    I'm willing to overlay video over an Image just as below: enter image description here

    The Car is the image and rest orange or background you are seeing is the video.

    Now for overlaying video over the image I'm using the following command:

    ffmpeg -i image.jpg -i input.mp4
       -filter_complex "[1]split=2[color][alpha];
                        [color]crop=iw/2:ih:0:0[color];[alpha]crop=iw/2:ih:iw/2:0[alpha];
                        [color][alpha]alphamerge[ovrly];
                        [0][ovrly]overlay=0:0" output.mp4
    

    and its throwing me an error as below:

    At least one output file must be specified
    zsh: command not found: -filter_complex
    

    What am I doing wrong here?

    Any help will be highly appreciated.

  • How can I capture and record the desktop and also the sound from speakers using ffmpeg ?

    29 janvier 2019, par Dubi Duboni

    This is how I'm recording the video of the desktop without sound: And it's working good:

    ffmpeg -f gdigrab -framerate 24 -i desktop -preset ultrafast -pix_fmt yuv420p out.mp4
    

    But now I want to capture and record also the sound so I tried:

    ffmpeg -f gdigrab -framerate 24 -i audio="Stereo Mix (Realtek High Definition Audio)"  desktop -preset ultrafast -pix_fmt yuv420p testing002.mp4
    

    But getting error:

    [gdigrab @ 0000000000df2cc0] Please use "desktop" or "title=" to specify your target. audio=Stereo Mix (Realtek High Definition Audio): I/O error

    This is a screenshot of my speakers properties:

    Speakers