【问题标题】:Reading a UDP stream by ffmpeg libavcodec通过 ffmpeg libavcodec 读取 UDP 流
【发布时间】:2014-01-28 10:56:36
【问题描述】:

我想使用 ffmpeg libavcodec 从 UDP 地址(如 udp://:1500)读取视频流。我正在使用此代码:

char *url = "udp://:1500";
char *format = "mpegts";

AVInputFormat *fmt = NULL;
AVFormatContext *oc = NULL;

int res;

fmt = av_find_input_format(format);
res = avformat_open_input(&oc, url, fmt , NULL);
if(res!=0){
     printf("Could not open the stream\n");
     exit(1);
}

但是当我运行这段代码时,程序在执行 res = avformat_open_input(&oc, url, fmt , NULL); 后永远停止。

你知道是什么问题吗?

【问题讨论】:

    标签: ffmpeg udp libavcodec


    【解决方案1】:

    我的信息流是用这个创建的:

    ffmpeg -f v4l2 -input_format h264 -video_size 640x480 -framerate 30 -i /dev/video0 -preset ultrafast -tune zerolatency -vcodec copy -f h264 udp://machine:1500
    

    您的代码在我更改后对我有用

    char *format = "mpegts";
    

    char *format = "h264";
    

    我的猜测是您的信息流不是您认为的格式。

    事实上,当我完全删除 fmt 变量并改为传递 NULL 时,libav 为我发现了格式。

    另请参阅:Code that starts the same but has a lot more comments.

    【讨论】:

      猜你喜欢
      • 2010-11-11
      • 2013-07-23
      • 2012-07-30
      • 2014-02-20
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      相关资源
      最近更新 更多