gpt4 book ai didi

networking - 具有多个网络接口(interface)的 FFmpeg 多播

转载 作者:行者123 更新时间:2023-12-04 23:02:36 27 4
gpt4 key购买 nike

我在 FFmpeg 上有 java-application 作为包装器。我需要捕获 mp2 多播流,将其转换为 mp3 并将转换后的多播流发送到另一个地址。
它运作良好。但现在我有两个网络接口(interface)。其中一个用于互联网/本地网络(eth1)。需要配置第二个网络接口(interface) (eth2) 来捕获和发送多播流。

但 ffmpeg 默认尝试从第一个网络接口(interface)捕获。我可以在 tcpdump 中看到数据包,但 ffmpeg 没有从 eth2 捕获它。

如何指定流捕获接口(interface)和流发送接口(interface)?

最佳答案

这已通过 smcroute 实用程序解决。

应用程序属性:

smcroute.config.file                        = /etc/smcroute.conf

路由配置.java:
public class RoutingConfig {

private final File file;

public RoutingConfig(String filename) {
this.file = new File(filename);
}

public List<RoutingRecord> read() throws IOException {
List<String> lines = Files.readAllLines(file.toPath());
return lines.stream().map(RoutingRecord::new).collect(Collectors.toList());
}

public void write(List<RoutingRecord> records) throws IOException {
List<String> lines = records.stream().map(RoutingRecord::toString).collect(Collectors.toList());
Files.write(file.toPath(), lines);
}
}

路由记录.java:
public class RoutingRecord {

private String sourceInterface;
private String multicastAddress;
private String sourceMulticastAddress;
private List<String> destinationInterfaces;

public RoutingRecord() {
}

public RoutingRecord(String line) {

String[] words = line.split(" ");

this.sourceInterface = words[2];
this.multicastAddress = words[4];
this.sourceMulticastAddress = words[6];
this.destinationInterfaces = new ArrayList<>(Arrays.asList(words).subList(8, words.length));
}

public RoutingRecord(String sourceInterface,
String multicastAddress,
String sourceMulticastAddress,
List<String> destinationInterfaces
) {
this.sourceInterface = sourceInterface;
this.multicastAddress = multicastAddress;
this.sourceMulticastAddress = sourceMulticastAddress;
this.destinationInterfaces = destinationInterfaces;
}

public String getSourceInterface() {return sourceInterface;}

public String getMulticastAddress() {return multicastAddress;}

public String getSourceMulticastAddress() {return sourceMulticastAddress;}

public List<String> getDestinationInterfaces() {return destinationInterfaces;}

public String getDestinationInterfacesLine() {return String.join(", ", destinationInterfaces);}

public RoutingRecord setSourceInterface(String sourceInterface) {
this.sourceInterface = sourceInterface;
return this;
}

public RoutingRecord setMulticastAddress(String multicastAddress) {
this.multicastAddress = multicastAddress;
return this;
}

public RoutingRecord setSourceMulticastAddress(String sourceMulticastAddress) {
this.sourceMulticastAddress = sourceMulticastAddress;
return this;
}

public RoutingRecord setDestinationInterfaces(List<String> destinationInterfaces) {
this.destinationInterfaces = destinationInterfaces;
return this;
}

@Override
public String toString() {
return "mroute from " + sourceInterface + " " +
"group " + multicastAddress + " " +
"source " + sourceMulticastAddress + " " +
"to " + String.join(" ", destinationInterfaces);
}

RoutingServiceImpl.java:
@Service
public class RoutingServiceImpl implements RoutingService {

private final Environment environment;

@Autowired
public RoutingServiceImpl(Environment environment) {
this.environment = environment;
}

@Override
public List<RoutingRecord> getRoutingLines() throws IOException {
String filename = environment.getProperty("smcroute.config.file");
RoutingConfig routingConfig = new RoutingConfig(filename);
return routingConfig.read();
}

@Override
public void saveRoutingLines(List<RoutingRecord> records) throws IOException {
String filename = environment.getProperty("smcroute.config.file");
RoutingConfig routingConfig = new RoutingConfig(filename);
routingConfig.write(records);
}

@Override
public void saveRoutingLine(RoutingRecord routingRecord) throws IOException {
String filename = environment.getProperty("smcroute.config.file");
RoutingConfig routingConfig = new RoutingConfig(filename);

List<RoutingRecord> records = routingConfig.read();
records.add(routingRecord);

routingConfig.write(records);
}

@Override
public void applyRoutes() throws IOException {

Runtime rt = Runtime.getRuntime();

rt.exec(new String[] {
"service",
"smcroute",
"restart"
});
}
}

关于networking - 具有多个网络接口(interface)的 FFmpeg 多播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52036826/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com