Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • file samples into frame : avcodec_fill_audio_frame

    28 mai, par Mr.Wang from Next Door

    Rust binding https://github.com/larksuite/rsmpeg of ffmpeg.

    I try to fill AVFrame with samples as below.

    let bgm_samples : AVSamples = ...;
    assert_eq!(bgm_samples.nb_channels, 1);
    assert_eq!(bgm_samples.sample_fmt, AV_SAMPLE_FMT_FLTP);
    
    let mut frame = AVFrame::new();
    frame.set_nb_samples(bgm_samples.nb_samples);
    frame.set_ch_layout(AVChannelLayout::from_nb_channels(1).into_inner());
    frame.set_format(bgm_samples.sample_fmt);
    frame.set_sample_rate(22050);
    
    frame
        .alloc_buffer()
        .context("Could not allocate frame buffer")?;
    
    let raw_ptr = frame.into_raw();
    unsafe {
        let err = ffi::avcodec_fill_audio_frame(
            raw_ptr.as_ptr(),
            1,
            bgm_samples.sample_fmt,
            bgm_samples.audio_data[0].as_mut().unwrap(),
            bgm_samples.nb_samples
                * ffi::av_get_bytes_per_sample(bgm_samples.sample_fmt),
            0,
        );
        if err < 0 {
            bail!("avcodec_fill_audio_frame failed with {}", err);
        }
    }
    
    let frame = unsafe { AVFrame::from_raw(raw_ptr) };
    

    The frame from above code would cause an error in encoder:

    [aac @ 0000021A08201AC0] Input contains (near) NaN/+-Inf

    If I change the above code as below, to copy samples into an AVAudioFifo and then read samples from AVAudioFifo into AVFrame, it works! It means the bgm_samples contains valid samples. But somehow avcodec_fill_audio_frame does not copy the samples correctly.

    Can someone help? thanks in advance.

    let mut fifo: AVAudioFifo = AVAudioFifo::new(
        bgm_samples.sample_fmt,
        1,
        bgm_samples.nb_samples,
    );
    
    unsafe {
        fifo.write(bgm_samples.audio_data.as_ptr(), bgm_samples.nb_samples)?;
    }
    
    // create frame from samples
    let mut frame = AVFrame::new();
    frame.set_nb_samples(bgm_samples.nb_samples);
    frame.set_ch_layout(AVChannelLayout::from_nb_channels(1).into_inner());
    frame.set_format(bgm_samples.sample_fmt);
    frame.set_sample_rate(22050);
    
    frame
        .alloc_buffer()
        .context("Could not allocate frame buffer")?;
    
    if unsafe { fifo.read(frame.data_mut().as_mut_ptr(), bgm_samples.nb_samples)? }
        < bgm_samples.nb_samples
    {
        bail!("Could not read data from FIFO");
    }
    
  • php ffmpeg cannot save video to system temporary folder

    28 mai, par user2818066

    I am trying to covert a video to h.264 format. I can save the new video to a normal directory but saving the new video to a Windows temp file fails. However I can manage to save a snapshot image from the video into Windows temp folder without problem. I cannot figure out what is the problem?

    require_once(dirname(__FILE__).'/../vendor/autoload.php');
    
    function get_ffmpeg_exe_path_arr_def(){ 
      return( array( 'ffmpeg.binaries'  => "C:/bin/ffmpeg.exe",
                     'ffprobe.binaries' => "C:/bin/ffmpeg.exe",
                     'timeout' => 3600000000, 'ffmpeg.threads' => 12
                    )   )  ;  
    }
    
    $vid_inp = 'C:/Users/Jordan/Downloads/motorboat_org.mp4' ; 
    $vid_out = 'C:/Users/Jordan/Downloads/motorboat_9.mp4' ;
    $tmp_vid_out_file = tempnam(sys_get_temp_dir(), "Vid") ; //C:\Windows\Temp\VidA318.tmp 
    $tmp_img_file = tempnam(sys_get_temp_dir(), "Img") ; //C:\Windows\Temp\ImgA234.tmp
    
    
    $ffmpeg = FFMpeg\FFMpeg::create( get_ffmpeg_exe_path_arr_def() );
    $video = $ffmpeg->open($vid_inp);
    $format = new FFMpeg\Format\Video\X264('aac', 'libx264');
    
    $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(0.2))->save($tmp_img_file);
    // Ok to save snapshot image to  C:\Windows\Temp\ImgA234.tmp 
    
    $video->save($format, $vid_out); 
    // This is ok to save video to  C:/Users/Jordan/Downloads/motorboat_9.mp4
    
    $video->save($format, $tmp_vid_out_file); 
    // This fails to save new video to   C:\Windows\Temp\VidA318.tmp  
    
    
    
     -------  Error Message -----
        Fatal error: Uncaught exception 'Alchemy\BinaryDriver\Exception\ExecutionFailureException' with message 
    'ffmpeg failed to execute command "C:\AppServ\www/ecity/bin/windows/ffmpeg.exe" -y -i 
    "C:/Users/Jordan/Downloads/motorboat_org.mp4" 
    -threads 12 -vcodec libx264 -acodec aac -b:v 1000k 
    -refs 6 -coder 1 -sc_threshold 40 -flags +loop 
    -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 
    -qdiff 4 -trellis 1 -b:a 128k -pass 1 -passlogfile 
     "C:\WINDOWS\TEMP\ffmpeg-passes66557e75d5e53hbzbo/pass-66557e75d6e0b" C:\Windows\Temp\VidEA8F.tmp: 
    Error Output: ffmpeg version 4.3.2-2021-02-27-full_build-www.gyan.dev Copyright (c) 2000-2021 
    the FFmpeg developers built with gcc 10.2.0 
    (Rev6, Built by MSYS2 project) configuration: 
    --enable-gpl --enable-version3 --enable-static 
    --disable-w32threads --disable-autodetect 
    --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma 
    --enable-libsnappy --enable-zlib --enable-libsrt 
    --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-li in C:\AppServ\www\ecity\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Media\AbstractVideo.php on line 106
    
  • Fingerprint vs transcribing, what is the best approach to identify an audio sample inside another longer audio

    28 mai, par Bernard Wiesner

    I am trying to detect a shorter version of a spoken audio sample inside a longer audio (full version). The shorter audio should be the same or very similar to the one inside the longer version. I also need to have a rough estimate of the timestamp where the audio sample was found.

    Similar questions here:

    What I have researched so far:

    1. fingerprints

    • Using chromaprint extract the fingerprints from both audio files and store them in a DB, then compare them and find matches.

    2. transcribing

    • Use a transcriber such as whisper, to transcribe both audio files and store the text in a DB, then compare them and find matches.

    I am trying to figure out the simplest solution for this, while still being performant and not too CPU/GPU intensive. My questions are:

    1. Which one would you chose for simplest, cost effective solution?
    2. Which one would consume more disk space?
    3. Which one would perform better, in terms of searching/matching using SQL?

    FYI: If there are any other alternatives to those I listed please let me know.

  • I'm new and am trying to convert video files

    28 mai, par ZDM

    So I have upscaled videos of the Fallout 1 cinematics but they're in .avi and I'm using Fallout1in2 which has the cinematics in .mve so I'm trying to convert the .avi to .mve and using ffmpeg I have used this command "ffmpeg -i C:\PATH_Programs\BOIL1.AVI BOIL1.MVE" but get this error "ffmpeg unable to choose an output format use standard extension for filename or specify the format manually". Am I doing something wrong or is it just not possible to do it this way?

    I have used this command "ffmpeg -i C:\PATH_Programs\BOIL1.AVI BOIL1.MVE" but get this error "ffmpeg unable to choose an output format use standard extension for filename or specify the format manually".

  • ffmpeg conversion increase bitrate

    28 mai, par Robert D Weir

    When extracting Audio streams using ffmpeg from containers such as MP4, how does ffmpeg increase bitrate, if it is higher than the source bitrate?

    An example might be ffmpeg -i video.mp4 -f mp3 -ab 256000 -vn music.mp3. What does ffmpeg do if the incoming bitrate is 128k? Does it interpolate or default to 128k on the output music.mp3? I know this seems like not a so-called "programming question" but ffmpeg forum says it is going out of business and no one will reply to posts there.