FFMPEG读取内存中的h264数据进行推流

 序言

    本实例是通过将本地的h264文件数据读取到内存中,再将该内存中h264数据进行rtmp推流。

 

#include 
#include 
#ifdef __cplusplus
extern "C"
{
#endif

#include "libavformat/avformat.h"
#include "libavutil/mathematics.h"
#include "libavutil/time.h"
#include "libavutil/mathematics.h"

#ifdef __cplusplus

};
#endif
#define BUF_SIZE 3110400
FILE* pfile;

int read_packet(void *opaque,uint8_t *buf,int buf_size)
{
    printf("in read_packet\n");
    if(!feof(pfile)){
        int n = fread(buf,1,buf_size,pfile);
        printf("n= %d\n",n);
        return n;
    }
    else
    {
        printf("read failed\n");
        return -1;
    }
}

static double r2d(AVRational r)
{
    return r.num == 0 || r.den == 0 ? 0. : (double)r.num/(double)r.den;
}

int main()
{
    av_register_all();
    avformat_network_init();
    
    pfile = fopen("./cuc_ieschool.flv","rb");
    if(pfile == NULL)
    {
        return -1;
    }    

你可能感兴趣的:(ffmpeg)