2016-10-28 155 views
0

我试图用下面的代码创建一个使用FFmpeg的RTP音频流。当我的Windows 10的机器上运行,我得到如下回应:Stream#0:0:Unknown:none(pcm_s16be)

Output #0, rtp, to 'rtp://127.0.0.1:8554': 
    Stream #0:0: Audio: pcm_s16be, 8000 Hz, mono, s16, 128 kb/s 
SDP dump: 
================= 
v=0 
o=- 0 0 IN IP4 127.0.0.1 
s=No Name 
c=IN IP4 127.0.0.1 
t=0 0 
a=tool:libavformat 57.25.101 
m=audio 8554 RTP/AVP 96 
b=AS:128 
a=rtpmap:96 L16/8000/1 
ret = 0 

,但在Linux上(#57〜14.04.1 Ubuntu的),FFmpeg的对待流为 “未知”:

Output #0, rtp, to 'rtp://127.0.0.1:8554': 
    Stream #0:0: Unknown: none (pcm_s16be) 
SDP dump: 
================= 
v=0 
o=- 0 0 IN IP4 127.0.0.1 
s=No Name 
c=IN IP4 127.0.0.1 
t=0 0 
a=tool:libavformat 57.57.100 
m=application 8554 RTP/AVP 3 

有谁知道为什么会出现这种情况?任何形式的帮助将不胜感激。

#include <math.h> 
extern "C" 
{ 
#include <libavutil/opt.h> 
#include <libavcodec/avcodec.h> 
#include <libavutil/channel_layout.h> 
#include <libavutil/common.h> 
#include <libavutil/imgutils.h> 
#include <libavutil/mathematics.h> 
#include <libavutil/samplefmt.h> 
#include <libavformat/avformat.h> 
} 

/* 
* Audio encoding example 
*/ 
static void audio_encode_example(const char *filename) 
{ 
    int ret; 
    AVCodec *outCodec = NULL; 
    AVCodecContext *outCodecCtx = NULL; 
    AVFormatContext *outFormatCtx = NULL; 
    AVStream * outAudioStream = NULL; 
    AVFrame *outFrame = NULL; 

    ret = avformat_alloc_output_context2(&outFormatCtx, NULL, "rtp", filename); 
    if (!outFormatCtx || ret < 0) 
    { 
    fprintf(stderr, "Could not allocate output context"); 
    } 

    outFormatCtx->flags |= AVFMT_FLAG_NOBUFFER | AVFMT_FLAG_FLUSH_PACKETS; 
    outFormatCtx->oformat->audio_codec = AV_CODEC_ID_PCM_S16BE; 
    // outFormatCtx->audio_codec_id = AV_CODEC_ID_PCM_S16BE; 
    // outFormatCtx->oformat->video_codec = AV_CODEC_ID_NONE; 
    // outFormatCtx->oformat->data_codec = AV_CODEC_ID_PCM_S16BE; 

    /* find the encoder */ 
    outCodec = avcodec_find_encoder(outFormatCtx->oformat->audio_codec); 
    if (!outCodec) { 
    fprintf(stderr, "Codec not found\n"); 
    exit(1); 
    } 

    outAudioStream = avformat_new_stream(outFormatCtx, outCodec); 
    if (!outAudioStream) 
    { 
    fprintf(stderr, "Cannot add new audio stream\n"); 
    exit(1); 
    } 

    outAudioStream->time_base.den = 8000; 
    outAudioStream->time_base.num = 1; 
    outCodecCtx = outAudioStream->codec; 
    outCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; 

    /* select other audio parameters supported by the encoder */ 
    outCodecCtx->sample_rate = 8000; 
    outCodecCtx->channel_layout = AV_CH_LAYOUT_MONO; 
    outCodecCtx->channels = 1; 

    /* open it */ 
    if (avcodec_open2(outCodecCtx, outCodec, NULL) < 0) { 
    fprintf(stderr, "Could not open codec\n"); 
    exit(1); 
    } 
    outCodecCtx->frame_size = 372; 

    av_dump_format(outFormatCtx, 0, filename, 1); 

    char buff[10000] = { 0 }; 
    ret = av_sdp_create(&outFormatCtx, 1, buff, sizeof(buff)); 
    printf("SDP dump:\n" 
      "=================\n" 
      "%s", buff); 
    /* 
    Running the program returns the following: 

    Output #0, rtp, to 'rtp://127.0.0.1:8554': 
     Stream #0:0: Unknown: none (pcm_s16be) 
    SDP dump: 
    ================= 
    v=0 
    o=- 0 0 IN IP4 127.0.0.1 
    s=No Name 
    c=IN IP4 127.0.0.1 
    t=0 0 
    a=tool:libavformat 57.57.100 
    m=application 8554 RTP/AVP 3 

    */ 

    exit(1); 
} 


int main(int argc, char **argv) 
{ 
    const char *output; 

    av_register_all(); 
    avformat_network_init(); // for network streaming 

    audio_encode_example("rtp://127.0.0.1:8554"); 

    return 0; 
} 

回答

0

我能够使它从av_sdp_create不顾输出工作:

v=0 
o=- 0 0 IN IP4 127.0.0.1 
s=No Name 
c=IN IP4 127.0.0.1 
t=0 0 
a=tool:libavformat 57.25.101 
m=audio 8554 RTP/AVP 97 
b=AS:256 
a=rtpmap:97 L16/8000/1 

我不禁感到给我一个SDP文件av_sdp_create使我在大雁追逐那不起作用。

相关问题