video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-09-16 927a49bc04984400cb9b968e41d299cc977e4988
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
#include "stream.hpp"
 
#include "ffmpeg/data/CodedData.hpp"
 
namespace cffmpeg_wrap{
    stream::stream(){
 
    }
    stream::~stream(){
 
    }
 
    int stream::SetPacket(std::shared_ptr<ffwrapper::CodedData> data){
        if (data){
            std::lock_guard<std::mutex> locker(mutex_avpkt_);
            list_avpkt_.push_back(data);
            return list_avpkt_.size();
        }
        return 0;
    }
 
    void stream::GetPacket(unsigned char **pktData, int *size, int *key){
        std::lock_guard<std::mutex> l(mutex_avpkt_);
        if(list_avpkt_.empty()){
            return;
        }
        auto data = list_avpkt_.front();
        auto pkt = data->getAVPacket();
        *key = pkt.flags & AV_PKT_FLAG_KEY;
        *size = pkt.size;
        *pktData = (unsigned char *)malloc(*size);
        memcpy(*pktData, pkt.data, pkt.size);
 
        list_avpkt_.pop_front();
    }
}