Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • FFMPEG - Concat Image to a video without re-encoding

    2 mai 2017, par Pubudu Thelahera

    I have been googling this but didn't found a definitive answer.

    I need to concat two images to the beginning and end of a video without re-encoding the whole video.

    Edit: Please assume i'm using h264 codec with python. Say i need the image to be displayed for 03 seconds.

    Can this really be done? If so appreciate a sample code.

    Thanks in advance.

  • Trying to redirect binary stdout of ffmpeg to NeroAacEnc stdin

    2 mai 2017, par Ben

    I am trying to write a program in C# 2010 that converts mp3 files to an audio book in m4a format via ffmpeg.exe and NeroAACenc.exe. For doing so I redirect stdout of ffmpeg to stdin of the Nero encoder within my application using the build in Diagnostics.Process class.

    Everything seems to work as expected but for some reason StandardOutput.BaseStream of ffmpeg stops receiving data at some time. The process does not exit and the ErrorDataReceived event is also not getting raised. The produced output m4a file has always a length of ~2 minutes. The same applies if I just encode the mp3 file to a temp wav file without feeding Nero.

    I tried the same via the command line and this works without any problem.

    ffmpeg -i test.mp3 -f wav - | neroAacEnc -ignorelength -if - -of test.m4a 
    

    Can anyone please tell me what I am doing wrong here? Thanks in advance.

    class Encoder
    {
        private byte[] ReadBuffer = new byte[4096];
        private Process ffMpegDecoder = new Process();
        private Process NeroEncoder = new Process();
        private BinaryWriter NeroInput;
    
        //Create WAV temp file for testing
        private Stream s = new FileStream("D:\\test\\test.wav", FileMode.Create);
        private BinaryWriter outfile;
    
        public void Encode()
        {
            ProcessStartInfo ffMpegPSI = new ProcessStartInfo("ffmpeg.exe", "-i D:\\test\\test.mp3 -f wav -");
            ffMpegPSI.UseShellExecute = false;
            ffMpegPSI.CreateNoWindow = true;
            ffMpegPSI.RedirectStandardOutput = true;
            ffMpegPSI.RedirectStandardError = true;
            ffMpegDecoder.StartInfo = ffMpegPSI;
    
            ProcessStartInfo NeroPSI = new ProcessStartInfo("neroAacEnc.exe", "-if - -ignorelength -of D:\\test\\test.m4a");
            NeroPSI.UseShellExecute = false;
            NeroPSI.CreateNoWindow = true;
            NeroPSI.RedirectStandardInput = true;
            NeroPSI.RedirectStandardError = true;
            NeroEncoder.StartInfo = NeroPSI;
    
            ffMpegDecoder.Exited += new EventHandler(ffMpegDecoder_Exited);
            ffMpegDecoder.ErrorDataReceived += new DataReceivedEventHandler(ffMpegDecoder_ErrorDataReceived);
            ffMpegDecoder.Start();
    
            NeroEncoder.Start();
            NeroInput = new BinaryWriter(NeroEncoder.StandardInput.BaseStream);
    
            outfile = new BinaryWriter(s);
    
            ffMpegDecoder.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, new AsyncCallback(ReadCallBack), null);
    
        }
    
        private void ReadCallBack(IAsyncResult asyncResult)
        {
            int read = ffMpegDecoder.StandardOutput.BaseStream.EndRead(asyncResult);
            if (read > 0)
            {
    
                NeroInput.Write(ReadBuffer);
                NeroInput.Flush();
    
                outfile.Write(ReadBuffer);
                outfile.Flush();
    
                ffMpegDecoder.StandardOutput.BaseStream.Flush();
    
                ffMpegDecoder.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, new AsyncCallback(ReadCallBack), null);
            }
            else
            {
                ffMpegDecoder.StandardOutput.BaseStream.Close();
                outfile.Close();
            }
    
        }
    
        private void ffMpegDecoder_Exited(object sender, System.EventArgs e)
        {
            Console.WriteLine("Exit");
        }
    
        private void ffMpegDecoder_ErrorDataReceived(object sender, DataReceivedEventArgs errLine)
        {
            Console.WriteLine("Error");
        }
    
    }
    
  • How to remove a section from an audio and keep the rest with ffmpeg

    2 mai 2017, par user2128078

    I'm trying to remove a section from an audio. For example I want to remove from 30s to 45s and have the rest with me. What I'm doing is the following:

    ffmpeg -i input.mp3 -filter_complex "[0]atrim=duration=30[a];[0]atrim=start=45[b];[a][b]concat" output.mp3
    

    But unfortunately this doesn't seem to work.

    What I obtain is the following error:

    [Parsed_atrim_0 @ 00000000000c8700] Media type mismatch between the 'Parsed_atrim_0' filter output pad 0 (audio) and the 'Parsed_concat_2' filter input pad 0 (video)
    [AVFilterGraph @ 0000000002435260] Cannot create the link atrim:0 -> concat:0
    Error initializing complex filters.
    Invalid argument
    
  • Why am I getting a 'withSize' of undefined error ?

    1er mai 2017, par Nick Garver

    I am trying to simply covert an avi video to flv using the example in the fluent-ffmpeg documentation. I am doing this for my node.js app but for some reason no matter how I specify my video path I seem to keep getting "undefined" when I do thing like .setStartTime or .setDuration. I am aware of this post but I still seem to be getting this error. Could anyone help me just set up the basic starter code? Thank you

    var ffmpeg = require('fluent-ffmpeg');
    
    
    // path to my video file
    var infs = fs.createReadStream('uwf.mp4');
    infs.on('error', function(err) {
      console.log("u messed up");
    });
    
    var proc = new ffmpeg({ source: infs, nolog: true })
      .setFfmpegPath("ffmpeg") //Set the path to where FFmpeg is installed 
      .setStartTime(25)
      .setDuration(2)
      .saveToFile('test.mp4');
    

    my console

    my file tree

  • Replace blank spaces to run command

    1er mai 2017, par ChrisBlp

    I'm using Runtime.getRuntime.exec(String) to cut some songs with ffmpeg. But when my song has a name with a blankspace it doesn't work ...

    So before I cut the song, I want to replace every blank space of my songs by "\ ".

    I did that :

    String in = directory+songs.get(i);
    String out = directory+"trimed_"+songs.get(i);
    in.replaceAll(" "," \\ ");
    out.replaceAll(" ", "\\ ");
    String str = "ffmpeg -t 1 -i "+in+" -vcodec copy "+out;
    Runtime.getRuntime().exec(str);
    

    But it doesn't replace anything at all when I print str, am I missing something ?