Recherche avancée

Médias (91)

Autres articles (59)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

  • Encoding and processing into web-friendly formats

    13 avril 2011, par

    MediaSPIP automatically converts uploaded files to internet-compatible formats.
    Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
    Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
    Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
    All uploaded files are stored online in their original format, so you can (...)

  • Les formats acceptés

    28 janvier 2010, par

    Les commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
    ffmpeg -codecs ffmpeg -formats
    Les format videos acceptés en entrée
    Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
    Les formats vidéos de sortie possibles
    Dans un premier temps on (...)

Sur d’autres sites (9600)

  • Firebase function error : Cannot find ffmpeg

    9 janvier 2020, par Nathan

    I’m using the firebase storage to execute a function when a video gets uploaded to the default bucket, in the function I’m using Ffmpeg to convert the video and set some other options like size, then I want to reupload the file back to storage and I keep getting this error :

    Error: Cannot find ffmpeg
    at /srv/node_modules/fluent-ffmpeg/lib/processor.js:136:22
    at FfmpegCommand.proto._getFfmpegPath (/srv/node_modules/fluent-ffmpeg/lib/capabilities.js:90:14)
    at FfmpegCommand.proto._spawnFfmpeg (/srv/node_modules/fluent-ffmpeg/lib/processor.js:132:10)
    at FfmpegCommand.proto.availableFormats.proto.getAvailableFormats (/srv/node_modules/fluent-ffmpeg/lib/capabilities.js:517:10)
    at /srv/node_modules/fluent-ffmpeg/lib/capabilities.js:568:14
    at nextTask (/srv/node_modules/async/dist/async.js:4578:27)
    at Object.waterfall (/srv/node_modules/async/dist/async.js:4589:9)
    at Object.awaitable(waterfall) [as waterfall] (/srv/node_modules/async/dist/async.js:208:32)
    at FfmpegCommand.proto._checkCapabilities (/srv/node_modules/fluent-ffmpeg/lib/capabilities.js:565:11)
    at /srv/node_modules/fluent-ffmpeg/lib/processor.js:298:14

    I have used npm install to install both fluent-ffmpeg and ffmpeg-static yet it says it cannot find it ? Here’s my code :

    const ffmpeg = require('fluent-ffmpeg');
    const ffmpeg_static = require('ffmpeg-static');
    const {Storage} = require('@google-cloud/storage');
    const fs = require('fs');
    const os = require('os');
    var path = require('path');

    // Creates a client
    const storage = new Storage({
    projectId: 'projectID',
    });

    function promisifyCommand(command) {
    return new Promise((resolve, reject) => {
     command.on('end', resolve).on('error', reject).run();
    });
    }

    exports.updatePost = functions.storage.object().onFinalize(async (object) => {

    const fileBucket = object.bucket; // The Storage bucket that contains the file.
    const filePath = object.name; // File path in the bucket.
    const contentType = object.contentType; // File content type.
    const resourceState = object.resourceState; // The resourceState is 'exists' or 'not_exists' (for file/folder deletions).
    const metageneration = object.metageneration; // Number of times metadata has been generated. New objects have a value of 1.

    // Get file name
    const fileName = path.basename(filePath);

    // Exit if this is a move or deletaion event.
    if(resourceState === 'not_exists'){
       console.log('This is a deletion event');
       return;
    }

    // Download file from bucket
    const bucket = storage.bucket(fileBucket);
    const tempFilePath = path.join(os.tmpdir(), fileName)
    // We add a '_output.flac' suffix to target audio file name. That's where we'll upload the converted audio.
    const targetTempFileName = fileName.replace(/\.[^/.]+$/, "") + '_output.mp4';
    const targetTempFilePath = path.join(os.tmpdir(), targetTempFileName);
    const targetStorageFilePath = path.join(path.dirname(filePath), targetTempFileName);

    await bucket.file(filePath).download({destination: tempFilePath});
       console.log('Video downloaded locally to', tempFilePath);
       // Convert the video to suitable formats
       const command = ffmpeg(tempFilePath)
       .setFfmpegPath(ffmpeg_static.path)
       .withSize('50%')
       .toFormat('mp4')
       .output(targetTempFilePath);
       await promisifyCommand(command);
           console.log('New video created');

           //Upload video again
           await bucket.upload(targetTempFilePath, {destination: targetStorageFilePath});
               console.log('Output video uploaded to', targetStorageFilePath);
               // Delete the local file from server as it's been uploaded to storage
               fs.unlinkSync(tempFilePath);
               fs.unlinkSync(targetTempFilePath);

               console.log('Tempory files removed.', targetTempFilePath);
    });

    I have searched everywhere and people are also saying that running the ffmpeg module on the function will also exceed the limit very quickly and where told to use ffmpeg-static instead ?
    Thanks,

    Nathan

  • Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_split_0

    26 mars 2023, par VenoM

    So I'm using ytdl-core & ffmpeg to convert some videos from YouTube to MP4 and then manipulate them in a way or take screenshots. But the issue I'm facing is - some videos are downloaded and are completely playable, but others are corrupt.

    


    This is the error I get when I try to take screenshot of the corrupted video :

    


    


    Error : ffmpeg exited with code 1 : Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_split_0

    


    


    And obviously, error is there because the video is corrupted, but WHY is that the case ?

    


    Here's my code (read TL ;DR below) :

    


      router.post("/screenshot", async (req, res) => {
  const urlToScreenshot = req.body.url;
  const timestamp = parseInt(req.body.t, 10);
  const YouTubeURL = `https://youtube.com/watch?v=${urlToScreenshot}`;
  const filename = uuidv4();

  const videoPath = `${filePath}/${filename}.mp4`;

  const downloadStartTime = timestamp - 3;
  const downloadEndTime = timestamp + 3;

  const videoStream = ytdl(YouTubeURL, {
    quality: "highest",
  });

  const ffmpegCommand = ffmpeg(videoStream)
    .setStartTime(downloadStartTime)
    .duration(downloadEndTime - downloadStartTime)
    .outputOptions("-c:v", "libx264")
    .outputOptions("-c:a", "copy")
    .outputOptions("-b:v", "10M")
    .outputOptions("-filter:v", "scale=1920:1080")
    .outputOptions("-q:v", "1")
    .outputOptions("-reconnect", "1") // enable reconnection attempts
    .outputOptions("-ignore_io_errors", "1") // ignore input/output errors
    .on("end", async () => {
      console.log("Video downloaded successfully: " + videoPath);

      const screenshotPath = `${filePath}/${filename}.png`;
      ffmpeg(videoPath)
        .screenshots({
          count: 1,
          timemarks: ["1"],
          folder: filePath,
          filename: `${filename}.png`,
        })
        .on("end", async () => {
          console.log(`Screenshot saved successfully: ${screenshotPath}`);
          try {
            const cloudinaryResult = await cloudinary.uploader.upload(
              screenshotPath
            );
            const screenshotUrl = cloudinaryResult.secure_url;
            console.log(`Screenshot uploaded to Cloudinary: ${screenshotUrl}`);
            // await unlink(videoPath);
            console.log(`Video file deleted: ${videoPath}`);
            // await unlink(screenshotPath);
            console.log(`Screenshot file deleted: ${screenshotPath}`);
            res.status(200).json({ screenshotUrl });
          } catch (err) {
            console.error(
              "An error occurred while uploading the screenshot to Cloudinary:",
              err
            );
            // await unlink(videoPath);
            // await unlink(screenshotPath);
            res.status(500).send("Internal Server Error");
          }
        })
        .on("error", async (err) => {
          console.error("An error occurred while taking the screenshot:", err);
          // await unlink(videoPath);
          // await unlink(screenshotPath);
          res.status(500).send("Internal Server Error");
        });
    })
    .on("error", async (err) => {
      console.error("An error occurred while downloading the video:", err);
      await unlink(videoPath); // delete the file on error
      res.status(500).send("Internal Server Error");
    })
    .save(videoPath);

  // console.log(ffmpegCommand);
});


    


    Code Summary : Basically I'm passing the videoID and timestamp (because I want to download a certain section of the video, not the whole video), it downloads the video, then takes a screenshot of the video at a certain timestamp (i.e 1st second) and sends the screenshot to Cloudinary (a cloud file storage).

    


    This works fine for 50% of the videos I've tried, but doesn't for other videos.

    


    Here's a picture of a corrupt video and a working video.

    


    enter image description here

    


    Working Video

    


    Corrupt Video

    


    Some help would be greatly appreciated !

    


  • ffmpeg audio - video sync issue (audio ahead of video) - while screen recording using x11grab

    12 juillet 2023, par maheshg

    While screen-recording using the below ffmpeg options I consistently get audio ahead of video, delay is in the order of few seconds

    


    ffmpeg cmd :

    


    ffmpeg -y -f x11grab -thread_queue_size 1024 -draw_mouse 0 -video_size 1920x1080 -i :0 -f pulse -thread_queue_size 1024 -i default -c:v libx264 -threads 0 -preset faster -c:a flac -async 1 -vsync 1 -crf 30 -crf_max 33 -f matroska output.mkv

    


    ffprobe output below :

    


    $ ffprobe demo.mkv 
ffprobe version 3.4.4-1~16.04.york0 Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
  configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, matroska,webm, from 'demo.mkv':
  Metadata:
    ENCODER         : Lavf57.71.100
  Duration: 01:00:31.93, start: 0.000000, bitrate: 416 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
    Metadata:
      ENCODER         : Lavc57.89.100 libx264
      DURATION        : 01:00:31.928000000
    Stream #0:1: Audio: flac, 48000 Hz, stereo, s16 (default)
    Metadata:
      ENCODER         : Lavc57.89.100 flac
      DURATION        : 01:00:30.912000000


    


    I have even tried using avoid_negative_ts flag, but it didnt help with the sync issue.

    


    


    OS : Ubuntu-18.04

    


    ffmpeg version : 3.4

    


    


    Update : (with ffmpeg-4.0)
I have since split this process into 2 parts and tried as shown below (quality is better, but audio/video sync is still an issue)

    


    # STEP-1: screen recording
/usr/bin/ffmpeg -y -f x11grab -thread_queue_size 1024 -draw_mouse 0 \
-video_size 1920x1080 -i :91141925 -f pulse -thread_queue_size 1024 \
-i virtual_sink.monitor -c:v libx264rgb -threads 0 -preset ultrafast \
-c:a flac -ac 1 -crf 0 -f matroska output.mkv

# STEP-2: audio/video encoding
/usr/bin/ffmpeg -y -i output.mkv -c:v libx264 -threads 0 \
-preset faster -pix_fmt yuv420p -c:a copy -ac 1 -crf 25 \
-f matroska final_output.mkv


    


    STEP-1 uses much less CPU during screen recording, but audio is still ahead of video. the display I am using is xvfb one in STEP-1 (since, this is a headless machine in the cloud)

    


    Also, i have tried flags -filter_complex aresample=44100 -vsync 1 in STEP-1 to no avail.

    


    Can someone please help !

    


    


    Update 2 : (with latest ffmpeg from git master)

    


    IT WORKED ! THANKS @llogan for the helpful comments.