Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • javafx show FFmpegFrameGrabber javacv

    26 mai 2017, par Anastasia Sisordia

    I use org.bytedeco.javacv. Created

    FFmpegFrameGrabber streamGrabber = new FFmpegFrameGrabber(filename);
    

    When I use CanvasFrame i just grab the streamGrabber and convert this frame to BufferedImage and show this image canvas.showImage(bi);

    And this works perfect.

    But if I want to show this image inside the GridPane , I convert BufferedImage to javafx.scene.image.Image :

     Image image= SwingFXUtils.toFXImage(bi, null);
    

    And my programm catch OutOfMemoryError .

    May I add Frame (org.bytedeco.javacv.Frame) or BufferedImage to my GridPane without conver to image? What need to do?

  • Muting ffmpeg warnings when loading video with OpenCV

    26 mai 2017, par cbuchart

    I'm using OpenCV to process a set of MPEG videos. For some of them following warning is displayed when reading a frame or seeking (it is printed by the ffmpeg library).

    [mpeg2video @ 026b0d20] warning: first frame is no keyframe

    The thing is that such messages are printed together other valid output of my application and they are bothering final users. Is there any way to suppress such warning messages programmatically, other than re-coding the videos with an external tool?

    I'm already muting the standard output and error, as well as using a custom (dummy) OpenCV error handler. Below a MCVE for testing.

    PS: I understand the warning and actually the full project handles those scenarios so videos are correctly read.


    Example code to reproduce the problem

    #include 
    #include core/core.hpp>
    #include highgui/highgui.hpp>
    
    int handleError(int status, const char* func_name,
                    const char* err_msg, const char* file_name,
                    int line, void* userdata)
    {
      return 0;
    }
    
    int main()
    {
      std::cout << "Start!" << std::endl;
    
      cv::VideoCapture reader;
      if (!reader.open("Sample.mpg")) {
        std::cout << "Failed opening video" << std::endl;
        return 0;
      }
    
      cv::redirectError(handleError);
    
      std::cout.setstate(std::ios_base::failbit);
      std::cout << "std::cout mute test..." << std::endl; // OK, muted
    
      std::cerr.setstate(std::ios_base::failbit);
      std::cerr << "std::cerr mute test..." << std::endl; // OK, muted
    
      cv::Mat tmpImage;
      try {
        tmpImage = tmpImage * tmpImage; // OK, OpenCV error muted
      } catch (...) {}
    
      // Here the warning is printed
      reader.read(tmpImage);
    
      std::cout.clear();
      std::cerr.clear();
      std::cout << "Finished!" << std::endl;
    
      return 0;
    }
    

    The Sample.mpg video can be downloaded from the Internet Archive: https://archive.org/download/ligouHDR-HC1_sample1/Sample.mpg

    This is the current output of the program:

    enter image description here


    I'm using VS 2010 and OpenCV 2.4.10. Following DLLs are the only ones with the executable (no other OpenCV-related DLL is reachable in the PATH).

    • opencv_core2410.dll
    • opencv_ffmpeg2410.dll
    • opencv_highgui2410.dll
  • FFMPEG streaming in OSX via NSTask : Unknown input format : avfoundation

    26 mai 2017, par Swati

    If i try to execute ffmpeg commands on terminal, things work fine however If i use ffmpeg binary in my xcode project and run ffmpeg command via NSTask then i get error.

    Code:

    NSString *str = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ffmpeg-new"];
    
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:str];
    
    NSArray *array = [NSArray arrayWithObjects:
    @"-f",@"avfoundation",
    @"-framerate",@"30",
    @"-i",@"0:0",
    @"-vcodec",@"h264",
    @"-acodec",@"aac",
    @"-ab",@"64000",
    @"-ar",@"48000",
    @"-ac",@"2",
    @"-f",@"flv",@"rtmp://url",nil];
    
    [task setArguments:array];
    [task launch];
    [task waitUntilExit];
    

    Error : unknown input format : avfoundation

  • WriteToUDP only works on same machine

    26 mai 2017, par Anderson Scouto da Silva

    This script is intended to capture the output of ffmpeg and write to a UDP address.

    It works correctly as I open the VLC 233.10.10.13:1234 and runs normally, but out of this computer the stream is not played, it's as if the stream does not exit from the machine to the multicast network, but on the same PC it works normally, I run the script go and open the VLC to run, it works perfectly.

    To take the doubts that might be some problem in the interfaces, I made a VLC stream by capturing 233.1.1.13:1234 and exiting to 233.10.10.13:1234 and I can run anywhere outside the machine where VLC is, for example, in another VLC on another machine. It just does not work in the script I wrote on go.

    Can anyone help?

    package main
    
    import (
        "os/exec"
        "io"
        "strings"
        "net"
        "net/url"
        "os"
        "github.com/juju/loggo"
    )
    
    const (
        BUFFER = 40 * 1024
        DEBUG = true
    )
    
    func verificaErro(e error) {
        if e != nil {
            logger.Errorf(e.Error())
        }
    }
    
    var logger loggo.Logger
    
    
    func main() {
        initLogger()
    
        dir, _ := os.Getwd()
    
        // conexão UDP
        conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4zero, Port: 0})
        verificaErro(err)
        err = conn.SetWriteBuffer(BUFFER)
        verificaErro(err)
    
        inputSource := dir + "/in/teste-4k.mp4"
        inputSource = normalizeInputSource(inputSource)
    
        inputCodec := probeInputCodec(inputSource)
        outputCodec := probeOutputCodec(inputCodec)
    
        cmdName := "ffmpeg"
        argsPipe1 := []string{
            "-hide_banner",
            "-loglevel", "panic",
            "-re",
            "-i",
            inputSource,
            "-preset",
            "superfast",
            "-c:v",
            inputCodec,
            "-crf",
            "0",
            "-c",
            "copy",
            "-f", outputCodec, "pipe:1",
        }
    
        cmdPipe1 := exec.Command(cmdName, argsPipe1...)
    
        logger.Debugf(strings.Join(argsPipe1, " "))
    
        stdoutPipe1, err := cmdPipe1.StdoutPipe()
        verificaErro(err)
        err2 := cmdPipe1.Start()
        verificaErro(err2)
    
        chunk := make([]byte, BUFFER)
        for {
            nr, err5 := stdoutPipe1.Read(chunk)
            logger.Debugf("Lido %d bytes\n", nr)
    
            if nr > 0 {
                validData := chunk[:nr]
    
                nw, err6 := conn.WriteToUDP(validData, &net.UDPAddr{IP: net.IP{233, 10, 10, 13}, Port: 1234})
                logger.Debugf("Escrito %d bytes\n", nw)
                verificaErro(err6)
            }
    
            if err5 != nil {
                // fim do arquivo
                if err5 == io.EOF {
                    break
                }
                logger.Errorf("Erro = %v\n", err5)
                continue
            }
        }
    }
    
    func probeInputCodec(input string) string {
        cmdName := "ffprobe"
        args := []string{
            "-v", "error",
            "-select_streams", "v:0", "-show_entries",
            "stream=codec_name", "-of", "default=noprint_wrappers=1:nokey=1",
            input,
        }
    
        out, err := exec.Command(cmdName, args...).Output()
        verificaErro(err)
    
        return strings.TrimSpace(string(out))
    
    }
    
    func probeOutputCodec(inputCode string) string {
        switch inputCode {
        case "h264":
            return "mpegts"
        case "mpeg4":
            return "mpeg4"
        }
    
        return "mpegts"
    }
    
    func normalizeInputSource(inputSource string) (string) {
        isFile := false
        if _, err := os.Stat(inputSource); err == nil {
            isFile = true
        }
        if isFile {
            return inputSource
        }
    
        u, err := url.Parse(inputSource)
        verificaErro(err)
    
        if u.Scheme != "udp" && u.Scheme != "tcp" {
            errorMessage := "A entrada deve ser uma URL UDP/TCP ou um arquivo existente"
            logger.Errorf(errorMessage)
            os.Exit(1)
        }
    
        q := u.Query()
    
        if u.Scheme == "udp" {
            q.Set("overrun_nonfatal", "1")
            q.Set("fifo_size", "1000000")
            q.Set("buffer_size", "26214400")
        }
    
        u.RawQuery = q.Encode()
    
        return u.String()
    }
    
    func initLogger() {
        logger = loggo.GetLogger(loggo.DefaultWriterName)
        if DEBUG {
            logger.SetLogLevel(loggo.DEBUG)
        } else {
            logger.SetLogLevel(loggo.ERROR)
        }
    }
    
  • can hls play fragment mp4 formed by rtp data

    26 mai 2017, par hui zhang

    I have a rtp stream, and I record it to several fragment mp4(fmp4) files divide by I-Frame. (I first record it as mp4, and set the right pts. then use ffmpeg transform it to fragment to fmp4 )

    ffmpeg -re -i infile.ext -f mp4 -movflags frag_keyframe+empty_moov output.mp4)

    I want to play these fmp4 in hls, I set the m3u8 file manually. And try to play, browser get the fmp4 file successfully. But not able to played on browser.
    I don't know where is wrong? Could any one help me ?