相关疑难解决方法(0)

使用FFmpeg libavformat记录RTSP流

我正在尝试使用FFmpeg libavformat记录来自Axis相机的RTSP流.我可以从文件中获取视频,然后将其保存到另一个文件,这没关系.但相机发送奇怪的数据,FPS为100,相机每隔4帧发送一次,因此结果FPS约为25.但是libavformat设置数据包dts/pts为90000 fps(默认值?),新文件流有100fps.结果是一小时视频,只有100帧.

这是我的代码

#include <stdio.h>
#include <stdlib.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>


int main(int argc, char** argv) {

    AVFormatContext* context = avformat_alloc_context();
    int video_stream_index;

    av_register_all();
    avcodec_register_all();
    avformat_network_init();

    //open rtsp
    if(avformat_open_input(&context, "rtsp://195.200.199.8/mpeg4/media.amp",NULL,NULL) != 0){
        return EXIT_FAILURE;
    }

    if(avformat_find_stream_info(context,NULL) < 0){
        return EXIT_FAILURE;
    }

    //search video stream
    for(int i =0;i<context->nb_streams;i++){
        if(context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
            video_stream_index = i;
    }

    AVPacket packet;
    av_init_packet(&packet);

    //open output file
    AVOutputFormat* fmt = av_guess_format(NULL,"test2.avi",NULL);
    AVFormatContext* oc = avformat_alloc_context();
    oc->oformat = fmt;
    avio_open2(&oc->pb, "test.avi", AVIO_FLAG_WRITE,NULL,NULL);

    AVStream* stream=NULL;
    int …
Run Code Online (Sandbox Code Playgroud)

c ffmpeg rtsp-client libavformat

16
推荐指数
2
解决办法
3万
查看次数

标签 统计

c ×1

ffmpeg ×1

libavformat ×1

rtsp-client ×1