Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Debugging in Visual Studio without Pdb files (C++ Access Voilation)

    2 décembre 2016, par Prakash M

    I built OpenCV binaries(.dll) using Cmake & visual studio which generated .pdb file which helped me to find the issue in code (Partially!)

    How this Crash is being caused. .
    I'm using a software with which we can set internet download speed limit (transfer rate) for any particular program.

    Now if i connect IP camera to the code below, i noticed that my app needs around 100Kb/s of internet usage (transfer rate) - only then i can watch live stream seamlessly. Lets say i cut down (set) my application internet usage to 10Kb/s [This is the reason behind crash] in this case, i should be able to see a new frame once in 4+ seconds.

    I'm getting access violation error probably because (cap>>img;) cap is trying to reach a location in ram & get the frame but there is no frame YET because its still being downloaded due to low internet speed.
    Clearly the pointer is reaching some location in ram to grab a frame which is not yet present.

    Some interesting behaviour . . .

    Void OpenCamera()
    {
        VideoCapture cap("http://192.168.1.3:8080/video?x.xmjpeg");
        Mat img;
        while(true)
        {
          try
          {
            if(cap.isOpened()) //also tried grab + retrieve, crashes at grab
            cap>>img; //code crashes here
          }
          catch(...)
          {
            cout<<"Camera Disconnected"<code>

    If i use the entire code in same class (within same header file), there is no problem at all(new frame is displayed after 4+ seconds without crashing the program) but if i put the code into a separate class(different header file), then call the function to open camera from a class object, then it crashes if internet speed is cut down.
    weird behavior - if i debug step by step, it never crashes!

    when i build opencv library with ffmpeg , i get .pdb file only for opencv (opencv_world310.pdb)- so no issue debugging using call stack but i do not get pdb for ffmpeg (because Opencv_ffmpeg.dll is precompiled and that is where its crashing)

    hence its getting hard to debug, building ffmpeg doesn't produce pdb file cause its built using MSYS
    so is it possible to debug with what we have?

    I'm including snapshot from visual studio debugging, some of the variables that will help in understanding:

    typedef int (*CvGrabFrame_Plugin)( void* capture_handle );      [cap_ffmpeg_api.cpp]
    protected: void* ffmpegCapture;                                 [cap_ffmpeg.cpp]
    static CvGrabFrame_Plugin icvGrabFrame_FFMPEG_p = 0;            [cap_ffmpeg.cpp]
    

    enter image description here

    Exception thrown at 0x0A0AF6F0 (opencv_ffmpeg310.dll) in Sample.exe: 0xC0000005: Access violation reading location 0x00000020. If there is a handler for this exception, the program may be safely continued.

    in source code i included below line & compiled & used it in project - didn't work, crashed again! if(ffmpegCapture) - null pointer check

    can we make some changes at line 214 in [cap_ffmpeg.cpp] to avoid crash?
    other header files are just one folder up.

    Update: I noticed that program crashes immediately when i limit internet consumption speed. I'm using C++/Cli(winforms, target dot net Framework = 4.6), i have CameraClass (in separate header file) & main function in (separate header file)
    Main function has below code

    CameraClass ^CC = gcnew CameraClass();
    CC->OpenCamera();
    

    Some clash between .net memory handling & C++ memory handling?

  • Android - FFmpeg gives an error while extract MP3 from video

    2 décembre 2016, par Urvashi Patel

    I want to execute FFmpeg command for extract audio in MP3 format from video that is in asset folder of the app. For more, refer http://writingminds.github.io/ffmpeg-android-java/

    String sourceFilePath = "file:///android_asset/SampleVideo.mp4";
    destFilePath = mp3File.getAbsolutePath();
    
    FFmpeg ffmpeg = FFmpeg.getInstance(MainActivity.this);
        try {
    
            String cmd[] = new String[]{"/data/data/com.example.bansi_vasundhara.videotomp3_demo/files/ffmpeg", "-i", sourceFilePath, "-vn", "-acodec copy", destFilePath};
    
            ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
    
                @Override
                public void onStart() {
                    Log.e("gc", "Command Started");
                }
    
                @Override
                public void onProgress(String message) {
                    Log.e("gc", "onProgress" + message);
                }
    
                @Override
                public void onFailure(String message) {
                    Log.e("gc", "onFailure command" + message);
                }
    
                @Override
                public void onSuccess(String message) {
                    Log.e("gc", "onSuccess command" + message);
                }
    
                @Override
                public void onFinish() {
                    Log.e("gc", "onFinish command");
                }
            });
    
        } catch (FFmpegCommandAlreadyRunningException e) {
            // Handle if FFmpeg is already running
            e.printStackTrace();
        }
    

    but i get an error. please suggest any solution.

    java.io.IOException: Error running exec(). Command: [/data/data/com.example.bansi_vasundhara.videotomp3_demo/files/ffmpeg, /data/data/com.example.bansi_vasundhara.videotomp3_demo/files/ffmpeg, -i, file:///android_asset/SampleVideo.mp4, -vn, -acodec copy, /storage/sdcard0/VideoToMP3/SampleMP3.mp3] Working Directory: null Environment: null at java.lang.ProcessManager.exec(ProcessManager.java:211) at java.lang.Runtime.exec(Runtime.java:173) at java.lang.Runtime.exec(Runtime.java:128) at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10) at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38) at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.io.IOException: No such file or directory at java.lang.ProcessManager.exec(Native Method) at java.lang.ProcessManager.exec(ProcessManager.java:209)

  • What is the FFMPEG packet UDP format to unpack with Go ?

    2 décembre 2016, par ThetraNetwork

    How can you unpack UDP packets sent from ffmpeg?

    I wrote a script to listen to UDP packets and write them into file, but the file is invalid and almost twice the size.

    This is how I send the data:

    ffmpeg -i video.mp4 -c:a aac -ar 48000 -ab 196k \
     -ac 2 -strict -2 -c:v libx264 -vb 500k -r 25 -s 320x240 \
     -ss 00.000 -f mp4 -movflags frag_keyframe+empty_moov \ udp://127.0.0.1:1936
    

    This is the code in Go. It should simply write the video into a new video file:

    package main
    
    import (
      "net"
      "os"
    )
    
    func main(){
      var buf []byte = make([]byte, 512)
      addr, _ := net.ResolveUDPAddr("udp", ":1936")
      conn, _ := net.ListenUDP("udp", addr)
      defer conn.Close()
    
      os.Create("new_video.mp4")
      f, _ := os.OpenFile("new_video.mp4", syscall.O_WRONLY, 0644)
      defer f.Close()
    
    
      for {
        n, _ := conn.Read(buf)
        f.Write(buf[0:n])
        buf = make([]byte, 512)
      }
    }
    

    Thanks

    Updated

    I changed the format to mp4 but the file is still invalid.

  • how to use the pts in ffmpeg

    2 décembre 2016, par Allan

    I have a library with can provide video data and PTS. The library head file Like this:

     /**
     * \brief           Write mirror video H.264 frame to player.
     * \param p_src     Pointer to source buffer.
     * \param size      H.264 frame size. (unit: byte)
     * \param ptsValue  PTS value.
     * \return          Copied size. (unit: byte)
     */
    int (*WriteMirrorVideoData)(const std::string& ip, const void *p_src, int size, double ptsValue);
    

    As you see, the library give me video frame buffer address and PTS.

    I use FFMpeg to decode video data correctly.

    My question is how to control the display time by ptsValue which provided by library.

    Did I need to set the ptsValue to AVFrame? then FFMPeg can control the display time itself. Or I need to control the display by my own code?

    I am a newer to FFMpeg. please help me. Thank you very much!

  • Crop MP3 to first 30 seconds

    2 décembre 2016, par Cheekysoft

    Original Question

    I want to be able to generate a new (fully valid) MP3 file from an existing MP3 file to be used as a preview -- try-before-you-buy style. The new file should only contain the first n seconds of the track.

    Now, I know I could just "chop the stream" at n seconds (calculating from the bitrate and header size) when delivering the file, but this is a bit dirty and a real PITA on a VBR track. I'd like to be able to generate a proper MP3 file.

    Anyone any ideas?

    Answers

    Both mp3split and ffmpeg are both good solutions. I chose ffmpeg as it is commonly installed on linux servers and is also easily available for windows. Here's some more good command line parameters for generating previews with ffmpeg

    • -t chop after specified number of seconds
    • -y force file overwrite
    • -ab set bitrate e.g. -ab 96k
    • -ar set sampling rate e.g. -ar 22050 for 22.05kHz
    • -map_meta_data : copy track metadata from infile to outfile

    instead of setting -ab and -ar, you can copy the original track settings, as Tim Farley suggests, with:

    • -acodec copy