libVLC, vlcj, RTSP, and sout



我正在尝试通过http将RTSP流转码为mpeg4流,以便在视频标签中的网页上使用。我使用的是vlcj和本地安装的32位版本的VLC。我原以为我有正确的sout设置,但完成后出现了以下错误。

[414c24e8] stream_out_standard stream out error: no mux specified or found by extension
[414c24e8] stream_out_standard stream out error: no mux specified or found by extension
[414d47e8] main stream output error: stream chain failed for `transcode{vcodec=mp4v, vb=1024, acodec=none}:standard{dst=std{access=http,mux=ts,dst=127.0.0.1:5555}}

我在方法调用的options参数中发送的sout是:

:sout=#transcode{vcodec=mp4v, vb=1024, acodec=none}:standard{dst=std{access=http,mux=ts,dst=127.0.0.1:5555}}

我做错了什么?


2021年12月30日更新

这解决了我的一个问题。我仍然需要计算出各种选项才能传递到该方法中。谢谢你的帮助。


2021年12月29日更新:

以下是我用来验证概念的代码,用于测试目的和可行性。

/*
* This Java source file was generated by the Gradle 'init' task.
*/
package aes.video.transcoder;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.base.MediaPlayer;
public class App {
private static final int EMPTY = 0;
private static final String CAMERA_TEST_URL = "rtsp://xxx.xxx.xxx.xxx:###/media/video1";
private static final char SOUT_SEPERATOR = ':';
private static final char LEFT_BRACE = '{';
private static final char RIGHT_BRACE = '}';
private static final String SOUT="sout=#";

private MediaPlayerFactory factory;
private MediaPlayer mediaPlayer;
private final StringBuilder sb;

public App() {
sb = new StringBuilder(256);
}

public static void main(String[] args) {
App app = new App();
app.transcodeTest(args);
}

public void transcodeTest(String[] args) {
StringBuilder sbl = new StringBuilder(256);
factory = new MediaPlayerFactory();
mediaPlayer = factory.mediaPlayers().newEmbeddedMediaPlayer();

String media = CAMERA_TEST_URL;
String format = formatHttpStream("127.0.0.1", 5555);
String transcode = formatTranscodeString();
sbl.append(SOUT_SEPERATOR);
sbl.append(SOUT);
sbl.append(transcode);
sbl.append(SOUT_SEPERATOR);
sbl.append(format);
String[] options = {sbl.toString()};
System.out.println(options[0]);
mediaPlayer.media().play(CAMERA_TEST_URL, options);

factory.release();
}

private String formatHttpStream(String serverAddress, int serverPort) {
sb.setLength(EMPTY);
//        sb.append(":sout=#duplicate{dst=std{access=http,mux=ts,");
sb.append("standard{dst=std{access=http,mux=ts,");
sb.append("dst=");
sb.append(serverAddress);
sb.append(':');
sb.append(serverPort);
sb.append(RIGHT_BRACE);
sb.append(RIGHT_BRACE);
return sb.toString();
}

private String formatTranscodeString() {
sb.setLength(EMPTY);
sb.append("transcode");
sb.append(LEFT_BRACE);
sb.append("vcodec=mp4v,");
sb.append(" vb=1024,");
sb.append(" acodec=none");
sb.append(RIGHT_BRACE);
return sb.toString();
}
}

Gradle构建文件为:

/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.8.2/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use JCenter for resolving dependencies.
jcenter()
}
dependencies {

// https://mvnrepository.com/artifact/uk.co.caprica/vlcj
implementation 'uk.co.caprica:vlcj:4.7.1'
implementation 'uk.co.caprica:vlcj:4.7.1:sources'
implementation 'uk.co.caprica:vlcj:4.7.1:javadoc'

// Use JUnit test framework.
testImplementation 'junit:junit:4.13'
// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
}
application {
// Define the main class for the application.
mainClass = 'aes.video.transcoder.App'
}

这只是一个概念验证测试,不会在生产中使用。我认为我使用的sout模块字符串有问题。

流选项需要在数组中传递,而不是像您使用的那样在一个带有分隔符的字符串中传递。

这是你所拥有的一个片段:

String[] options = {sbl.toString()};
System.out.println(options[0]);
mediaPlayer.media().play(CAMERA_TEST_URL, options);

此处options的初始化不正确。

在有SOUT_SEPARATOR的情况下,实际上需要在数组中传递单独的字符串元素。

我还建议查看GitHub上的vlcj测试源或vlcj示例项目,其中有一些示例可以格式化转码字符串并将其作为媒体选项正确传递。

相关内容

  • 没有找到相关文章

最新更新