2016-10-28 190 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使我在大雁追逐那不起作用。

相關問題