Windows上使用FFmpeg实现本地视频推送模拟海康协议rtsp视频流

场景

Nginx搭建RTMP服务器+FFmpeg实现海康威视摄像头预览:

Nginx搭建RTMP服务器+FFmpeg实现海康威视摄像头预览_nginx rtmp 海康摄像头_霸道流氓气质的博客-CSDN博客

上面记录的是使用FFmpeg拉取海康协议摄像头的rtsp流并推流到流媒体服务器。

如果在其它业务场景下需要本地的视频文件模拟海康的rtsp流协议格式进行推流。

注:

博客:
霸道流氓气质_C#,架构之路,SpringBoot-CSDN博客

实现

1、参考如下搭建FFmpeg

Windows上搭建Nginx RTMP服务器并使用FFmpeg实现本地视频推流:

Windows上搭建Nginx RTMP服务器并使用FFmpeg实现本地视频推流_nginx-rtmp-win_霸道流氓气质的博客-CSDN博客

然后在ffmpeg.exe的目录下新建bat文件。

2、修改bat内容为

ffmpeg.exe -re  -stream_loop -1  -i D:\test\22.mp4 -c copy -rtsp_transport tcp -f rtsp rtsp://username:password@RTSP流媒体服务器ip:1554/h264/ch01/main/av_stream
pause

注意这里的本地视频路径以及rtsp流媒体服务器ip和端口1554已经配置的用户名username和密码password根据自己

实际情况修改。这里rtsp流媒体服务器搭建省略。

3、运行bat

4、使用VLC等拉流测试

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是一个使用FFmpeg实现本地摄像头实时推流RTSP服务器的C代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <libavutil/opt.h> #include <libavformat/avformat.h> #include <libavutil/mathematics.h> #include <libavdevice/avdevice.h> #include <libavcodec/avcodec.h> #define STREAM_DURATION 60.0 #define STREAM_FRAME_RATE 25 /* 25 images/s */ #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */ int main(int argc, char **argv) { AVFormatContext *pFormatCtx = NULL; AVOutputFormat *pOutputFmt = NULL; AVStream *pStream = NULL; AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; AVDictionary *options = NULL; AVFrame *pFrame = NULL; int ret, i, x, y; int frame_count = 0, video_outbuf_size; FILE *f = NULL; /* Initialize libavcodec, and register all codecs and formats. */ av_register_all(); avdevice_register_all(); /* Open video input device */ AVInputFormat *inputFmt = av_find_input_format("video4linux2"); if ((ret = avformat_open_input(&pFormatCtx, "/dev/video0", inputFmt, NULL)) < 0) { fprintf(stderr, "Could not open input device\n"); return ret; } /* Retrieve stream information */ if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { fprintf(stderr, "Could not find stream information\n"); return -1; } /* Find the first video stream */ for (i = 0; i < pFormatCtx->nb_streams; i++) { if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { pStream = pFormatCtx->streams[i]; break; } } if (!pStream) { fprintf(stderr, "Could not find video stream\n"); return -1; } /* Open output URL */ if ((ret = avformat_alloc_output_context2(&pFormatCtx, NULL, "rtsp", "rtsp://localhost:8554/test")) < 0) { fprintf(stderr, "Could not allocate output context\n"); return ret; } pOutputFmt = pFormatCtx->oformat; /* Add the video stream using the default format codec */ pCodec = avcodec_find_encoder(pOutputFmt->video_codec); if (!pCodec) { fprintf(stderr, "Codec not found\n"); return -1; } pCodecCtx = avcodec_alloc_context3(pCodec); if (!pCodecCtx) { fprintf(stderr, "Could not allocate codec context\n"); return -1; } /* Set stream parameters */ pCodecCtx->codec_id = pOutputFmt->video_codec; pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO; pCodecCtx->bit_rate = 400000; pCodecCtx->width = pStream->codecpar->width; pCodecCtx->height = pStream->codecpar->height; pCodecCtx->time_base = (AVRational){1, STREAM_FRAME_RATE}; pCodecCtx->pix_fmt = STREAM_PIX_FMT; /* Set the encoder's options */ av_dict_set(&options, "preset

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

霸道流氓气质

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值