RTMP---实例---从内存中读取并rtmp传送

//FFMPEG抓取摄像头数据并保存100帧上传至rtmp服务器
//编译指令:	gcc b.c -o a.out -Iinclude  -L/home/sambashare/ffmpeg-for-debugging/lib -lavcodec -lavformat -lavdevice -lavutil -lswscale
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavdevice/avdevice.h"
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>

char* input_name= "video4linux2";
char* file_name = "/dev/video0";
char* out_file = "11yuv420.yuv";//使用专用软件打开时如果打开时的格式与实际不符合会出错(按照错误的方式解读)

static AVFormatContext *ifmt_ctx;
static AVFormatContext *ofmt_ctx;

typedef struct StreamContext {
   
	AVCodecContext *dec_ctx;
	AVCodecContext *enc_ctx;
} StreamContext;

static StreamContext *stream_ctx = NULL;
const char* jpeg_file = "cuc_view_encode.jpg";
unsigned int g_stream_index = -1;

void release_frame(AVFrame *frame)
{
   
	if(frame){
   
		av_frame_unref(frame);
		av_frame_free(&frame);
	}
}

void release_packet(AVPacket *packet)
{
   
	if(packet){
   
		av_packet_unref(packet);
		av_packet_free(&packet);
	}
}

//打开输入文件并获取其中各个码流的stream_ctx[?]->dec_ctx
int open_input_file()
{
   
	int i = 0;
	int ret = -1;
	int videoindex = -1;
	ifmt_ctx = NULL;//里面有?个码流--对应stream_ctx[?]

	if((ret = avformat_open_input (&ifmt_ctx, file_name, NULL, NULL)) < 0) {
   av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");return ret;}
	//av_dump_format(ifmt_ctx,0,file_name,0);
	if((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {
   av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");return;}
	stream_ctx = av_mallocz_array(ifmt_ctx->nb_streams, sizeof(*stream_ctx));//申请连续的多个结构体
	if (!stream_ctx){
   return AVERROR(ENOMEM);}
	
	//获取stream_ctx[?]->dec_ctx
	for (i = 0; i < ifmt_ctx->nb_streams; i++)//获取stream_ctx[?]->dec_ctx
	{
   
		AVStream *stream = ifmt_ctx->streams[i];
		AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);//if (!dec) {av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i);return AVERROR_DECODER_NOT_FOUND;}
		
		AVCodecContext *codec_ctx <
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值