当前位置:网站首页>ffmpeg通过rtsp获取h264码流
ffmpeg通过rtsp获取h264码流
2022-08-09 15:43:00 【weixin_45090728】
ffmpeg通过rtsp获取h264码流
处理过程
通过VLC播放器将本地文件进行rtsp推流,使用ffmpeg打开URL地址获取h264。
VLC rtsp推流
点击“媒体”,选择“流”

点击“添加”选择需要推流的文件,然后点击下面的“串流”

点击“下一步”,选择“RTSP",再点击”添加“,设置端口号和名称,默认的ip是电脑本机ip


点击”下一个“,设置推流格式为h264


然后点击“下一个”,点击“流”后即可推流
测试的话,可以使用VLC媒体中的打开网络串流进行播放,若能成功播放则推流成功。

ffmpeg获取rtsp
获取其实很简单的,只给出代码,packet结构体中的data和size就是一帧h264数据(头部包含NALU)
extern "C"{
#include <stdio.h>
#include <signal.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
}
static volatile int flag_quit=0;
void signal_quit_handler(int sig)
{
flag_quit=1;
signal(SIGINT,SIG_DFL);
}
int rtsp_get_h264_test()
{
signal(SIGINT,signal_quit_handler);
AVFormatContext* format_context;
int video_index;
AVPacket *packet;
char file_path[]="rtsp://192.168.1.7:8554/live";
avformat_network_init();
format_context=avformat_alloc_context();
AVDictionary* options=NULL;
av_dict_set(&options,"buffer_size","102400",0);
av_dict_set(&options,"max_delay","500000",0);
av_dict_set(&options,"timeout","20000000",0);
av_dict_set(&options,"rtsp_transport","udp",0);
if(avformat_open_input(&format_context,file_path,NULL,&options)<0)
{
printf("Couldn't open input stream.\n");
return -1;
}
printf("Open stream success!\n");
if(avformat_find_stream_info(format_context,NULL)<0)
{
printf("Couldn't find stream information.\n");
return -1;
}
video_index=-1;
video_index=av_find_best_stream(format_context,AVMEDIA_TYPE_VIDEO,-1,-1,NULL,0);
if(video_index==-1)
{
printf("Couldn't find a stream video.\n");
return -1;
}
packet=av_packet_alloc();
while(!flag_quit)
{
if(av_read_frame(format_context,packet)>=0)
{
if(packet->stream_index==video_index){
printf("packet size %d\n",packet->size);
for(int i=0;i<8;i++)
{
printf("%d ",packet->data[i]);
}
printf("\n");
}
}
}
av_packet_free(&packet);
avformat_close_input(&format_context);
return 0;
}
int main(int argc, char **argv) {
printf("printf ffmpeg configuration: ");
printf("%s\n", avcodec_configuration());
rtsp_get_h264_test();
return 0;
}

其它
- 使用tcp打开的话会提示不支持
- 打开流后结束程序时最好关闭,不然会影响下一次的使用
边栏推荐
- The Chinese Academy of Sciences slaps Google in the face: ordinary computers catch up with quantum superiority, and can solve calculations that would have taken 10,000 years in a few hours...
- 六.数组越界问题引出对栈区内存的探索
- 知识点滴 - 如何写项目总结
- 良匠-手把手教你写NFT抢购软(三)
- ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
- shopee引流方式有哪些,商家如何为自己店铺做引流?
- 线性表重点之链表
- 网络——虚拟专用网和地址转换NAT
- IDEA启动缓慢原因(一)
- 网络——IPv6 vs IPv4
猜你喜欢

Nacos注册中心 Feign远程调用 Gateway服务网关

网络——IPV4地址(三)

网络——IPv6(一)

Using Prometheus skillfully to extend the kubernetes scheduler

Detailed explanation of three pieces in C language

How bad can a programmer be?

Heap series_0x09: Example of heap corruption (illegal access + uninitialized + heap handle mismatch)

一个程序员的水平能差到什么程度?

网络——介质访问控制

Chapter 2: Creating Interactive Maps (2.4-2.6)
随机推荐
The second chapter: create an interactive map (2.1 2.3)
5G NR Paging 寻呼
uniapp project construction
网络——IPV4地址(二)
[Server data recovery] Data recovery case of file system data loss caused by SAN LUN mapping error
C语言循环结构之万恶之源goto语句
Selenium的安装
[1413. Stepwise summation to get the minimum value of positive numbers]
七.getchar 和 scanf
巧用Prometheus来扩展kubernetes调度器
MySQL 5.5系列安装步骤教程(图解版)
NFT+IDO预售代币合约模式系统开发
【嵌入式入门篇】嵌入式0基础沉浸式刷题篇1
August 9, 2022: Build .NET apps in C# -- use the Visual Studio Code debugger to interactively debug .NET apps (won't, fail)
Three ways to find prime numbers
网络——涉及的相关协议和设备汇总
视频聊天源码——一对一直播如何提高直播质量?
How bad can a programmer be?
Nacos Jaspyt配置加密设置
【Chinese and English Catalog】Introduction