FFmpeg的多播具有多个网络接口

问题描述 投票:1回答:1

我有Java的应用程序上FFmpeg的包装。我需要捕捉MP2组播流,将其转换为MP3和发送转换后的组播流到另一个地址。它工作得很好。但现在我有两个网络接口。而对于互联网其中一个/局域网络(eth1的)。需要配置第二个网络接口(ETH2)来捕获和发送组播流。

但是ffmpeg的尝试默认情况下从第一个网络接口捕捉到。我可以看到tcpdump的数据包,但ffmpeg的不从ETH2捕捉到它。

我怎么可以指定流捕获和接口接口流发送?

networking ffmpeg multicast
1个回答
0
投票

这是由smcroute程序解决。

application.properties:

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

routing config.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);
    }
}

routing record.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);
    }

routing service imp了.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"
        });
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.