Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg and 0 second audio latency for audio through wowza in flv format

    8 décembre 2015, par Aaron

    how can I get ffmpeg to stream audio with no latency? ironically I have video working faster than audio. my Wowza is tuned for low latency and works. the following audio line gives me 1 second latency, the flash player is already 0 buffer size.

       ffmpeg -re -rtbufsize 1k  -f dshow -channels 1 -ar 22100 -i audio="Microphone (Realtek High Definition Audio)" -strict -2 
    -codec:a aac -b:a 8k  -ar 16000  -f  flv -rtmp_buffer 0 -rtmp_live live rtmp://blah
    
  • How to minimize usage of CPU/memory by ffmpeg when converting video mp4 h264

    8 décembre 2015, par Programmer

    I am using ffmpeg for video conversion to convert video in h264 format but it takes 100% CPU and memory resources that effect the server performance. below is my code that convert the video please help me on this but video must convert in h264 format.

    Public Function ConvertVideo() As Boolean
        Dim path = CurrentVideoPath
        Dim fileName = CurrentVideoName
        Dim retVal As Boolean = False
        Try
            'Form1.tmrConversion.Stop()
            '------------------
            ' fileName = IO.Path.GetFileNameWithoutExtension(fileName) + ".mp4"
            _mHandler = New MediaHandler()
            '------------------
            If (File.Exists(SourcePath + path + fileName)) Then
                newFileName = DateTime.Now.ToFileTime().ToString()
                'videoClassObj.UpdateStatus("Converting")
                '------------------
                'MessageBox.Show(DestinationPath + path + fileName)
                'videoClassObj.UpdateStatus("Done")
                ' Return True
                '------------------
                _mHandler.FFMPEGPath = Application.StartupPath & "\ffmpeg\bin\ffmpeg.exe"
                _mHandler.InputPath = SourcePath + path
                _mHandler.OutputPath = DestinationPath + path
                If (Not Directory.Exists(DestinationPath + path)) Then
                    Directory.CreateDirectory(DestinationPath + path)
                End If
                _mHandler.FileName = fileName
                _mHandler.OutputFileName = newFileName
                _mHandler.Parameters = " -fpre """ & Application.StartupPath & "\\ffmpeg\presets\\libx264-ipod640.ffpreset" & """"
                _mHandler.BackgroundProcessing = True
                Dim extension = IO.Path.GetExtension(fileName)
    
                _mHandler.BackgroundProcessing = True
                _mHandler.VCodec = "libx264"
                Dim infoupload As VideoInfo = _mHandler.Get_Info()
                _mHandler.OutputExtension = ".mp4"
                If String.IsNullOrEmpty(infoupload.SamplingRate.Trim) Then
                    _mHandler.Audio_SamplingRate = 44100
                Else
                    _mHandler.Audio_SamplingRate = infoupload.SamplingRate.Trim().Split(" ")(0)
                End If
    
    
                _mHandler.Height = infoupload.Height
                _mHandler.Width = infoupload.Width
                'if (not extension.tolower().equals(".avi")) then
                '    _mhandler.video_bitrate = infoupload.video_bitrate.trim().split(" ")(0)
                'end if
                If String.IsNullOrEmpty(infoupload.Audio_Bitrate.Trim) Then
                    _mHandler.Audio_Bitrate = 128
                Else
                    _mHandler.Audio_Bitrate = infoupload.Audio_Bitrate.Trim().Split(" ")(0)
                End If
    
    
                Dim info As VideoInfo = _mHandler.ProcessMedia()
    
                If (info.ErrorCode = 0) Then
                    While (_mHandler.vinfo.ProcessingCompleted < 100)
                        Console.WriteLine("Converting............")
    
                    End While
    
                    Dim Name = IO.Path.GetFileNameWithoutExtension(CurrentVideoName)
                    Name = Name & ".mp4"
    
                    Dim topath = DestinationPath + CurrentVideoPath
                    Dim ffmpegpath As String = Application.StartupPath & "\ffmpeg\bin\ffmpeg.exe"
                    Dim presetPath As String = Application.StartupPath & "\\ffmpeg\presets\\libx264-ipod640.ffpreset"
    
                    Dim resolution As String = CompressVideosToHD(newFileName + ".mp4", topath)
                    MoveHDfile(topath + IO.Path.GetFileNameWithoutExtension(newFileName))
    
    
    
                    retVal = True
    
                Else
                    retVal = False
                End If
    
            End If
        Catch ex As Exception
            'writeErrorLog(ex, "", "ConvertVideo", "")
            'frmConversion.UpdateStatus("Stopped")
            retVal = False
        Finally
            'Form1.tmrConversion.Start()
        End Try
    
        Return retVal
    End Function
    
  • Synchronize video subtitle with text-to-speech voice

    8 décembre 2015, par Ahmad

    I try to create a video of a text in which the text is narrated by text-to-speech.

    To create the video file, I use the VideoFileWriter of Aforge.Net as the following:

    VideoWriter = new VideoFileWriter();
    
    VideoWriter.Open(CurVideoFile, (int)(Properties.Settings.Default.VideoWidth),
        (int)(Properties.Settings.Default.VideoHeight), 25, VideoCodec.MPEG4, 800000);
    

    To read aloud the text I use SpeechSynthesizer class and write the output to a wave stream

    AudioStream = new FileStream(CurAudioFile, FileMode.Create);
    synth.SetOutputToWaveStream(AudioStream);
    

    I want to highlight the word is spoken in the video, so I synchronize them by the SpeakProgress event:

        void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
        {
    
            curAuidoPosition = e.AudioPosition;
            using (Graphics g = Graphics.FromImage(Screen))
            {
                 g.DrawString(e.Text,....); 
            }                    
            VideoWriter.WriteVideoFrame(Screen, curAuidoPosition);
        }
    

    And finally, I merge the video and audio using ffmpeg

    using (Process process = new Process())
    {
              process.StartInfo.FileName = exe_path;
              process.StartInfo.Arguments = string.Format(@"-i ""{0}"" -i ""{1}"" -y -acodec copy -vcodec copy ""{2}""",
                                               avi_path, mp3_path, output_file);
    ......
    

    The problem is that for some voices like Microsoft Hazel, Zira and David, the video is not synchronized with the audio, and the audio is much faster than the shown subtitle. In windows 7, it works for Mircrosoft Sam

    How can I synchronize them so that it works for any text-to-speech voices?

  • How to insert a key frame(Iframe) to a h.264 video stream in ffmpeg C++ api ?

    8 décembre 2015, par fcjy

    I have a real time video stream, and want to cut some video clips from it by accurate timestamp(pts).

    When I receiver an avpacket, I decode it, and do something and cache the avpacket. I don't want to re-encode all avpackets, it cost cpu resource.

    There are many gop structure in H.264 stream, usually we should cut the video begin at the key frame, and end at the key frame. Otherwise the front some frames in the video clip would display error.

    Now I use av_write_frame to make avpacket to video. But sometimes the length of gop is very long, such as it could be 250, 8.3s(30 frame per second). It means the distance between two I-frame could be 250 frames. The video clip is short, I don't want to add too many unused frames.

    How should I do? I think i should insert a i-frame at the start position of video clip. Could I change a p-frame to i-frame?

    Thanks your reading!

  • send point to point video stream using ffmpeg with rtsp (c++)

    8 décembre 2015, par seleciii44

    I need to send a h264 encoded video stream to a(only one) specific IP address with RTSP protocol on a windows PC with C++. I'm trying to use the FFMPEG library.

    I used the example in this post and i can play the stream as:

    ffplay -rtsp_flags listen -i rtsp://127.0.0.1:8554/live.sdp

    The problem is, according to the solution of post i need a server. Where -rtsp_flags listen option of ffplay behaves like a server.

    On the other hand, according to StreamingGuide of ffmpeg i can send a point to point stream like:

    ffmpeg -i INPUT -acodec libmp3lame -ar 11025 --f rtp rtp://host:port
    

    This is fine and works well. But i need to use rtsp. According to StreamingGuide again,

    Another option is to use RTP (which by default uses UDP) but by specifying it use TCP:

    ffmpeg -i input -f rtsp -rtsp_transport tcp rtsp://localhost:8888/live.sdp
    

    which seems to be what i'm looking for. Yet the ffmpeg tool seems to be doing nothing when i try this method (don't know why i need tcp,but udp does not work neither). Why is that?

    FFMPEG protocols documentation, says that i need to use a media server to send the video.

    • Why would i need a media server to just send the video stream to another PC or whatever?
    • If i need a media server, how does the IP Camera sends the stream?
    • If i have no option but to use a media server, could some one please recommend a server for Windows 7?
      • ffserver is only for linux
      • live555mediaServer seems to be used for local files or am i wrong?
      • ..?

    Best regards,
    Gokhan.