video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-05-06 70008056eb8983dae4ee2c960c043ae69191d03e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "VideoProp.hpp"
 
extern "C"{
#include <libavutil/opt.h>
}
 
namespace ffwrapper{
    VideoProp::VideoProp()
    :url_("")
    ,transcode_(false)
    ,rtsp_tcp_(false)
    ,fps_(25)
    ,bit_rate_(400)
    ,width_(0)
    ,height_(0)
    ,quality_(3)
    ,udp_port_x_(5000)
    ,udp_port_y_(65000)
    ,gpu_acc_(true)
    ,sample_aspect_ratio_(AVRational{0,1})
    {}
 
    VideoProp::~VideoProp()
    {}
 
    bool VideoProp::rtspStream(){
        if(url_.find("rtsp://") != 0){
            return false;
        }
        return true;
    }
 
    AVDictionary* VideoProp::optsFormat(){
        if(url_.find("rtsp://") != 0){
            return NULL;
        }
 
        AVDictionary *avdic = NULL;
        char option_key2[]="max_delay";
        char option_value2[]="500000";
        av_dict_set(&avdic,option_key2,option_value2,0);
 
        char option_key1[] = "stimeout";
        char option_value1[] = "500000";
        av_dict_set(&avdic, option_key1, option_value1, 0);
 
        av_dict_set(&avdic, "buffer_size", "1024000", 0);
 
        char option_key[]="rtsp_transport";
 
        if(rtsp_tcp_){
            char option_value[]="tcp";
            av_dict_set(&avdic,option_key,option_value,0);
        }else{
            char option_value[]="udp";
            av_dict_set(&avdic,option_key,option_value,0);
 
            char opt_key1[] = "min_port";
            av_dict_set_int(&avdic, opt_key1, udp_port_x_,0);
            char opt_key3[] = "max_port";
            av_dict_set_int(&avdic, opt_key3, udp_port_y_,0);
        }
 
        return avdic;
    }
 
    std::string VideoProp::preset(){
 
        char *preset = "veryfast";
        switch(quality_){
        case 1:
            preset = "ultrafast";
            break;
        case 2:
            preset = "superfast";
            break;
        case 3:
            preset = "veryfast";
            break;
        case 4:
            preset = "faster";
            break;
        case 5:
            preset = "fast";
            break;
        case 6:
            preset = "medium";
            break;
        case 7:
            preset = "slow";
            break;
        case 8:
            preset = "slower";
            break;
        case 9:
            preset = "veryslow";
            break;
        default:
            break;
        }
 
        return preset;
    }
 
    std::string VideoProp::filter_desc(){
        char spec[64] = {0};
 
        // snprintf(spec, sizeof(spec),"scale=%d:%d", width_, height_);
        snprintf(spec, sizeof(spec),"fps=fps=%d,scale=%d:%d", fps_, width_, height_);
        // snprintf(spec, sizeof(spec),"fps=fps=%d", fps_);
 
        return std::string(spec);
    }
 
}