Recherche avancée

Médias (3)

Mot : - Tags -/pdf

Autres articles (46)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

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

Sur d’autres sites (11061)

  • ffprobe different results video duration using pipe and reading a file from the file system

    5 février 2024, par alex

    I have a method to convert a video file, after processing the file I use pipe to pass bytes to a method to get meta information about the file using pipe. But in this case I get wrong duration of video file, 8.22, but if I save the file on file system and read it to get meta information I get result 15.85. Why is this happening ?

    


    Video Convert method :

    


    // ConvertVideoWithPath converts a video file specified by its path using FFmpeg.
// It returns the converted video data and any error that occurred during conversion.
func (f *FFmpeg) ConvertVideoWithPath(filePath string) (bytes []byte, err error) {
    if filePath == "" {
        return nil, ErrEmptyPath
    }

    // Create a CmdRunner instance for executing FFmpeg.
    commander := &CmdRunner{}
    commander.Command = "ffmpeg"
    args := []string{
        "-loglevel", "fatal",
        "-i", filePath,
        "-y",
        "-filter:v", "crop=trunc(iw/2)*2:trunc(ih/2)*2",
        "-c:v", f.videoCodec, // libx264
        "-c:a", f.audioCodec, // aac
        "-pix_fmt", "yuv420p",
        "-movflags", "frag_keyframe+faststart",
        "-map_metadata", "-1",
        "-crf", "5",
        "-vsync", "2",
        "-bufsize", "15000000",
        "-maxrate", "5000000",
        "-preset", "medium",
        "-f", "mp4",
        "pipe:1",
    }
    commander.Args = args

    // Initialize output pipe.
    reader := commander.InitStdOutPipe()

    // Use WaitGroup to synchronize goroutines.
    wg := &sync.WaitGroup{}
    wg.Add(1)

    // Goroutine for reading data from the output pipe.
    go func() {
        defer reader.Close()
        defer wg.Done()

        // Read data from the output pipe.
        data, _ := io.ReadAll(reader)
        // Safely update the 'bytes' variable.
        f.mutex.Lock()
        bytes = data
        f.mutex.Unlock()
    }()

    // Run the FFmpeg command with pipes and wait for completion.
    err = <-commander.RunWithPipe()
    wg.Wait()

    return
}


    


    // MetadataWithReader retrieves metadata from media data provided by an io.Reader using FFprobe.
// It returns the metadata and any error that occurred during metadata retrieval.
func (f *FFmpeg) MetadataWithReader(fileBytes io.Reader) (*Metadata, error) {
    if fileBytes == nil {
        return nil, ErrInvalidArgument
    }

    // Create a CmdRunner instance for executing FFprobe.
    commander := &CmdRunner{}
    commander.Command = "ffprobe"
    args := []string{
        "-loglevel", "fatal",
        "-i", "pipe:0",
        "-print_format", "json",
        "-show_format", "-show_streams",
        "-show_error",
    }
    commander.Args = args

    // Get output data from FFprobe with pipes.
    err := commander.GetOutputWithPipe(fileBytes)
    if err != nil {
        return nil, err
    }

    // Unmarshal JSON output into a Metadata struct.
    output := &Metadata{}
    err = json.Unmarshal(commander.GetOutput(), output)
    if err != nil {
        return nil, err
    }

    return output, err
}


    


    // MetadataWithPath extracts metadata of a file using FFprobe.
// It returns a Metadata struct or an error if the operation fails.
func (f *FFmpeg) MetadataWithPath(filePath string) (*Metadata, error) {
    if filePath == "" {
        return nil, ErrEmptyPath
    }

    // Create a CmdRunner instance for executing FFprobe.
    commander := &CmdRunner{}
    commander.Command = "ffprobe"
    args := []string{
        "-loglevel", "fatal",
        "-i", filePath,
        "-loglevel",
        "fatal",
        "-print_format", "json",
        "-show_format", "-show_streams", "-show_error",
    }
    commander.Args = args
    buffer := bytes.NewBuffer([]byte{})
    commander.StdOutWriter = buffer

    err := commander.Run()
    if err != nil {
        return nil, err
    }

    // Unmarshal JSON output into a Metadata struct.
    output := &Metadata{}
    err = json.Unmarshal(buffer.Bytes(), output)
    if err != nil {
        return nil, err
    }

    return output, nil
}


    


    The source code of the CmdRunner biblio library can be found here link , so as not to overload the question with a large piece of code.

    


    Unit test code

    


    t.Run("convert video", func(t *testing.T) {
        ffmpeg := NewFFmpeg("aac", "libx264", "24M", "12M")

        filePath := "../../test/testdata/input_video_ts.mp4"
        firstMeta, err := ffmpeg.MetadataWithPath(filePath)
        assert.NoError(t, err)
        fmt.Print("first meta duration: ", firstMeta.Format.DurationSeconds) // 15.75

        outFile := "../../test/testdata/output_mp4.mp4"
        newVideoOut, err := ffmpeg.ConvertVideoWithPath(filePath)
        assert.NoError(t, err)
        assert.NotEmpty(t, newVideoOut)

        meta, err := ffmpeg.MetadataWithReader(bytes.NewBuffer(newVideoOut))
        assert.NoError(t, err)
        assert.NotEmpty(t, meta)

        err = os.WriteFile(outFile, newVideoOut, 0644)
        assert.NoError(t, err)
        assert.FileExists(t, outFile)

        fmt.Print("meta duration: ", meta.Format.DurationSeconds) // 8.22

        secondMeta, err := ffmpeg.MetadataWithPath(outFile)
        assert.NoError(t, err)
        fmt.Print("second meta duration: ", secondMeta.Format.DurationSeconds) //15.85

        err = os.Remove(outFile)
        assert.NoError(t, err)
    })


    


  • Upload FFmpeg output directly to Amazon S3

    26 octobre 2017, par user1790300

    I am using the fluent-ffmpeg library with node.js to transcode videos originally in a flash movie format to the mp3 format with multiple resolutions, 1080p, etc.. Once the transcoding is complete, I would like to move the transcoded video to an s3 bucket.

    I pull the original .flv file from a source s3 bucket and pass the stream to the ffmpeg constructor function. The issue is after the transcoding completes, how do I then get the stream of the mp4 data to send to s3.

    Here is the code I have so far :

           var params = {
               Bucket: process.env.SOURCE_BUCKET,
               Key: fileName
           };
           s3.getObject(params, function(err, data) {
               if (err) console.log(err, err.stack); // an error occurred

               var format = ffmpeg(data)
               .size('854x480')
               .videoCodec('libx264')
               .format('flv')
               .toFormat('mp4');
               .on('end', function () {
                   //Ideally, I would like to do the uploading here

                   var params = {
                      Body: //{This is my confusion, how do I get the stream to add here?},
                      Bucket: process.env.TRANSCODED_BUCKET,
                      Key: fileName
                   };
                   s3.putObject(params, function (err, data) {

                  });
               })
               .on('error', function (err) {
                   console.log('an error happened: ' + err.message);
               });

           });

    For the code above, where can I get the transcoded stream to add to the "Body" property of the params object ?

    Update :

    Here is a revision of what I am trying to do :

    var outputStream: MemoryStream = new MemoryStream();

           var proc = ffmpeg(currentStream)
               .size('1920x1080')
               .videoCodec('libx264')
               .format('avi')
               .toFormat('mp4')
               .output(outputStream)
               // setup event handlers
               .on('end', function () {
                   uploadFile(outputStream, "").then(function(){
                       resolve();
                   })
               })
               .on('error', function (err) {
                   console.log('an error happened: ' + err.message);
               });

    I would like to avoid copying the file to the local filesystem from s3, rather I would prefer to process the file in memory and upload back to s3 when finished. Would fluent-ffmpeg allow this scenario ?

  • C# on linux : FFmpeg (FFMediaToolkit) on linux System.IO.DirectoryNotFoundException : Cannot found the default FFmpeg directory

    6 mai 2021, par Jan Černý

    I have C# project in rider and FFMediaToolkit installed via NuGet. I made instance of MediaBuilder. When I hit run I get this error message :

    


    /home/john/Projects/Slimulator/bin/Debug/net5.0/Slimulator /home/john/Projects/Slimulator/test_mazes/small-maze-food2.png
Loading file /home/john/Projects/Slimulator/test_mazes/small-maze-food2.png
Unhandled exception. System.IO.DirectoryNotFoundException: Cannot found the default FFmpeg directory.
On Windows you have to set "FFmpegLoader.FFmpegPath" with full path to the directory containing FFmpeg shared build ".dll" files
For more informations please see https://github.com/radek-k/FFMediaToolkit#setup
   at FFMediaToolkit.FFmpegLoader.LoadFFmpeg()
   at FFMediaToolkit.Encoding.Internal.OutputContainer.Create(String extension)
   at FFMediaToolkit.Encoding.MediaBuilder..ctor(String path, Nullable`1 format)
   at FFMediaToolkit.Encoding.MediaBuilder.CreateContainer(String path)
   at Slimulator.AnimationBuffer..ctor(String videoPath, Int32 height, Int32 width, Int32 frameRate) in /home/john/Projects/Slimulator/AnimationBuffer.cs:line 11
   at Slimulator.Simulation..ctor(Space space, String seed, String outputVideoPath) in /home/john/Projects/Slimulator/Simulation.cs:line 12
   at Slimulator.Launcher.Main(String[] args) in /home/john/Projects/Slimulator/Launcher.cs:line 8

Process finished with exit code 134.


    


    When I go to https://github.com/radek-k/FFMediaToolkit#setup I find just this :

    


    


    Linux - Download FFmpeg using your package manager.

    


    You need to set FFmpegLoader.FFmpegPath with a full path to FFmpeg libraries.

    


    If you want to use 64-bit FFmpeg, you have to disable the Build -> Prefer 32-bit option in
Visual Studio project properties.

    


    


    I have already installed FFmpeg package via pacman and I am still getting these error.

    


    How can I fix this so I can use FFMediaToolkit without problem on linux ?
    
Thank you for help

    


    EDIT1 : I use Arch linux.
EDIT2 : There is related issue on github : https://github.com/radek-k/FFMediaToolkit/issues/80