簡體   English   中英

如何使用JavaCV接收RTP流?

[英]How can I recieve an RTP stream with JavaCV?

我正在嘗試從RTP服務器(當前用於測試的VLC)流式傳輸視頻並用Java對其進行解碼。 為此,我使用JavaCV解碼傳入的流。 這是我到目前為止的內容:

try {
    grabber = new FFmpegFrameGrabber("rtp://localhost:5004/test");
    grabber.setFormat("h264");
    grabber.setFrameRate(30.0);
    grabber.start();
    Java2DFrameConverter converter = new Java2DFrameConverter();
    while (true) {
        Frame frame = grabber.grab();
        imageToDraw = frame != null ? converter.convert(frame) : null;
        // goes off to paint a widget on a window, see https://git.io/fhZSr for more context
        repaint();
    }
} catch (Exception e) {
    // TODO: Discover what circumstances cause this
    e.printStackTrace(System.out);
}

在VLC上,我的流設置如下設置:

  • 目標流:RTP / TS(地址localhost ,端口5004和流名稱test 。)
  • 啟用轉碼功能,預設為“視頻-H.264 + MP3(TS)”:
    • MPEG-TS封裝
    • 具有MPEG音頻的h.264視頻
  • 流所有基本流均已關閉。

我可以使用這些設置(使用“客戶端” VLC從rtp://localhost:5004/test接收)將一個VLC實例流式傳輸到另一個實例,它工作得很好。 (唯一的問題是由於測試機性能較弱,不適合對高分辨率視頻進行轉碼。)

切換到Java,我所看到的就是到處都是灰色的灰色幀。 控制台也一直在尖叫。 一些代碼片段(完整日志太長了,不足以構成合理的帖子,但是如果您確實需要,可以在這里找到):

[h264 @ 0x7f6c4c3502c0] cabac decode of qscale diff failed at 8 12
[h264 @ 0x7f6c4c3502c0] error while decoding MB 8 12, bytestream 670
[h264 @ 0x7f6c4c3502c0] concealing 421 DC, 421 AC, 421 MV errors in P frame

[h264 @ 0x7f6c4c3502c0] Reference 4 >= 2
[h264 @ 0x7f6c4c3502c0] error while decoding MB 25 8, bytestream 416
[h264 @ 0x7f6c4c3502c0] concealing 556 DC, 556 AC, 556 MV errors in B frame

[h264 @ 0x7f6c4c3502c0] Reference 5 >= 4
[h264 @ 0x7f6c4c3502c0] error while decoding MB 21 1, bytestream 6042
[h264 @ 0x7f6c4c3502c0] concealing 826 DC, 826 AC, 826 MV errors in P frame
[h264 @ 0x7f6c4c3502c0] Invalid NAL unit 8, skipping.
[above line repeats 5x]
[h264 @ 0x7f6c4c3502c0] top block unavailable for requested intra mode
[h264 @ 0x7f6c4c3502c0] error while decoding MB 3 0, bytestream 730
[h264 @ 0x7f6c4c3502c0] concealing 836 DC, 836 AC, 836 MV errors in P frame

我明顯在做錯什么嗎?

我假設您必須告訴FFmpegFrameGrabber正確的格式和代碼。 由於您正在發送MPEG-2傳輸流,因此您的格式不是H.264。 嘗試將格式(setFormat)設置為“ mpegts”。 用於某些H.264解碼器的視頻編解碼器和用於某些MPEG-2第三層解碼器(MP3)的音頻編解碼器。

假定錯誤消息是由H.264解碼器嘗試讀取MEPG-2傳輸流產生的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM