首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Xuggler对RTP包中的媒体文件进行编码

如何用Xuggler对RTP包中的媒体文件进行编码
EN

Stack Overflow用户
提问于 2014-01-10 19:22:37
回答 1查看 878关注 0票数 12

我正在用java构建一个RTSP流媒体服务器,但我不确定如何实现正确的RTP打包。

然后发送出去。

谁能给我提供一个实际的例子,告诉我如何以最独立于输入格式的方式将IPacket编码成正确的rtp有效负载?在这方面的文档有点缺乏。

EN

回答 1

Stack Overflow用户

发布于 2015-07-25 13:29:52

我见过一个使用javax.media实现RTP服务器的代码。

代码语言:javascript
复制
class MediaConvertion {
private MediaLocator mediaLocator = null;

private DataSink dataSink = null;

private Processor mediaProcessor = null;

private static final Format[] FORMATS = new Format[] { new AudioFormat(
        AudioFormat.DVI_RTP) };

private static final ContentDescriptor CONTENT_DESCRIPTOR = new ContentDescriptor(
        ContentDescriptor.RAW_RTP);

public MediaConvertion(String url) throws IOException,
        NoProcessorException, CannotRealizeException, NoDataSinkException,
        NoDataSinkException {
    mediaLocator = new MediaLocator(url);
}

public void setDataSource(DataSource ds) throws IOException,
        NoProcessorException, CannotRealizeException, NoDataSinkException {

    mediaProcessor = Manager.createRealizedProcessor(new ProcessorModel(ds,
            FORMATS, CONTENT_DESCRIPTOR));
    dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(),
            mediaLocator);
}

public void startTransmitting() throws IOException {
    mediaProcessor.start();
    dataSink.open();
    dataSink.start();
}

public void stopTransmitting() throws IOException {
    dataSink.stop();
    dataSink.close();
    mediaProcessor.stop();
    mediaProcessor.close();
}
}

public class MediaConverterExample extends Frame implements ActionListener {

Button st_stream;
static MediaConvertion mdcon;

public static void main(String args[]) throws IOException,
        NoProcessorException, CannotRealizeException, NoDataSinkException,
        MalformedURLException, NoDataSourceException {
    Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
    Format input2 = new AudioFormat(AudioFormat.MPEG);
    Format output = new AudioFormat(AudioFormat.LINEAR);
    PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder",
            new Format[] { input1, input2 }, new Format[] { output },
            PlugInManager.CODEC);
    File mediaFile = new File(args[1]);
    DataSource source = Manager.createDataSource(new MediaLocator(mediaFile
            .toURL()));
    mdcon = new MediaConvertion(args[0]);
    mdcon.setDataSource(source);
    new MediaConverterExample();
}

public MediaConverterExample() {
    st_stream = new Button("Start Streaming");
    add(st_stream);
    st_stream.addActionListener(this);
    setVisible(true);
    setSize(200, 300);

}

public void actionPerformed(ActionEvent ae) {
    try {
        mdcon.startTransmitting();
    } catch (Exception e) {
    }
}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21043048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档