문제

I'm writing a Java program to stream a video file to a Java client I'm writing. I have a working version of this using a gst-launch command:

$ gst-launch-0.10 -v filesrc location="beauty.mp4" 
! decodebin2 
! queue 
! jpegenc 
! rtpjpegpay 
! udpsink host=127.0.0.1 port=5000 sync=true

and it successfully streams to a client using this command:

$ gst-launch-0.10 -v udpsrc uri="udp://127.0.0.1:5000" 
! "application/x-rtp, 
    media=(string)video, 
    clock-rate=(int)90000, 
    encoding-name=(string)JPEG, 
    payload=(int)96, 
    ssrc=(uint)2156703816, c
    lock-base=(uint)1678649553, 
    seqnum-base=(uint)31324" 
! rtpjpegdepay 
! jpegdec 
! ffmpegcolorspace 
! autovideosink

When trying to convert this to Java, though, I can't seem to send a single byte. Here's what I have:

public static void main(String[] args) {
    System.out.println("Starting testserver on port 45001...");
    try {
        startStreaming();
        Thread.sleep(50000);
    } catch(Exception e) {
        e.printStackTrace();
    }
}

private static void startStreaming() {
    // create the pipeline here
    Gst.init();
    Pipeline pipe = new Pipeline("pipeline");
    Element fileSrc = ElementFactory.make("filesrc", "source");
    fileSrc.set("location", "videos/beauty.mp4");
    Element decoder = ElementFactory.make("decodebin2", "decoder");
    Element queue = ElementFactory.make("queue", "queue");
    Element encoder = ElementFactory.make("jpegenc", "encoder");
    Element payloader = ElementFactory.make("rtpjpegpay", "payloader");
    Element sink = ElementFactory.make("udpsink", "sink");
    sink.set("host", "127.0.0.1");
    sink.set("port", "45001");
    sink.set("sync", "true");
    pipe.addMany(fileSrc, decoder, queue, encoder, payloader, sink);
    Element.linkMany(fileSrc, decoder, queue, encoder, payloader, sink);

    pipe.setState(State.PLAYING);
}

I first tried playing this stream with a similarly-constructed Java pipeline, but after nothing happened I tried reading the stream with a simple gst-launch command:

$ gst-launch-0.10 udpsrc uri="udp://127.0.0.1:45001" ! fakesink dump=1

and no bytes were ever received. What might be causing this? I don't get any runtime errors and this pipeline works just fine on the command line.

도움이 되었습니까?

해결책

Got it! I ended up making a PlayBin2 to decode the file, then making a new Bin element containing the encoder, payloader, and UDP sink and setting it as the video sink of the Playbin. I'm not entirely sure why this worked and using the decodebin2 didn't, but whatever. It works.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top