Recherche avancée

Médias (0)

Mot : - Tags -/formulaire

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (58)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • MediaSPIP Player : problèmes potentiels

    22 février 2011, par

    Le lecteur ne fonctionne pas sur Internet Explorer
    Sur Internet Explorer (8 et 7 au moins), le plugin utilise le lecteur Flash flowplayer pour lire vidéos et son. Si le lecteur ne semble pas fonctionner, cela peut venir de la configuration du mod_deflate d’Apache.
    Si dans la configuration de ce module Apache vous avez une ligne qui ressemble à la suivante, essayez de la supprimer ou de la commenter pour voir si le lecteur fonctionne correctement : /** * GeSHi (C) 2004 - 2007 Nigel McNie, (...)

Sur d’autres sites (14889)

  • 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)
    })


    


  • How to save python compatible audio file from JavaScript blob

    16 septembre 2020, par Talha Anwar

    I am trying to save an audio blob to the backend.
Here is an audio blob

    


     const blob = new Blob(chunks, { 'type' : 'audio/wav; codecs=0' });


    


    Here is the upload function

    


    function uploadAudio( blob ) {
  var reader = new FileReader();
  reader.onload = function(event){
    var fd = {};
    fd["data"] = event.target.result;
    $.ajax({
     // contentType:"application/x-www-form-urlencoded; charset=UTF-8",
      type: 'POST',
      url: 'testing/',
      data: fd,
      dataType: 'text'
    }).done(function(data) {
        console.log(data);
        document.getElementById("response").innerHTML=data;
       // alert(data);
    });
  };


    


    Here is the function to save the file.

    


    def upload_audio(request):
    print('upload_audio')
    if request.is_ajax():
        
        req=request.POST.get('data')
        d=req.split(",")[1]
        print("Yes, AJAX!")
        #print(request.body)
        f = open('./file.wav', 'wb')
        
        f.write(base64.b64decode(d))
        #f.write(request.body)
        f.close()
    return HttpResponse('audio received')


    


    When I try to read it in python for converting to text. I got following error

    


    ValueError: Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format


    


    I tried to convert the file

    


    import ffmpeg
stream = ffmpeg.input('file.wav')
stream = ffmpeg.output(stream, 'filen.wav')
ffmpeg.run(stream)


    


    I got following error

    


    Traceback (most recent call last):&#xA;  File "script.py", line 8, in <module>&#xA;    ffmpeg.run(stream)&#xA;  File "C:\Anaconda3\envs\VA\lib\site-packages\ffmpeg\_run.py", line 320, in run&#xA;    overwrite_output=overwrite_output,&#xA;  File "C:\Anaconda3\envs\VA\lib\site-packages\ffmpeg\_run.py", line 285, in run_async&#xA;    args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream&#xA;  File "C:\Anaconda3\envs\VA\lib\subprocess.py", line 729, in __init__&#xA;    restore_signals, start_new_session)&#xA;  File "C:\Anaconda3\envs\VA\lib\subprocess.py", line 1017, in _execute_child&#xA;    startupinfo)&#xA;FileNotFoundError: [WinError 2] The system cannot find the file specified&#xA;</module>

    &#xA;

  • Create a 44-byte header with ffmpeg

    13 juillet 2015, par Joe Allen

    I made a program using ffmpeg libraries that converts an audio file to a wav file. Except the only problem is that it doesn’t create a 44-byte header. When input the file into Kaldi Speech Recognition, it produces the error :

    ERROR (online2-wav-nnet2-latgen-faster:Read4ByteTag():wave-reader.cc:74) WaveData: expected 4-byte chunk-name, got read errror

    I ran the file thru shntool and it reports a 78-byte header. Is there anyway I can get the standard 44-byte header using ffmpeg libraries ?