| | |
| | | ,func_rec_info_(nullptr) |
| | | ,thrd_(nullptr) |
| | | ,error_occured_(false) |
| | | ,audio_(false) |
| | | { |
| | | // logIt("RECODER ID: %s", id_.c_str()); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | int Recorder::init_writer(){ |
| | | int Recorder::init_writer(const bool audio){ |
| | | if (out_) { |
| | | delete out_; |
| | | } |
| | |
| | | return -1; |
| | | } |
| | | |
| | | out_ = new FormatOut(in_->getStream(), "mp4"); |
| | | out_ = new FormatOut(in_->getFPS(), "mp4"); |
| | | AVStream *vs = in_->getStream(0); |
| | | AVStream *as = in_->getStream(1); |
| | | if (!vs) return -1; |
| | | if (audio && !as) logIt("there is no audio"); |
| | | |
| | | std::vector<AVStream*> in; |
| | | in.push_back(vs); |
| | | if (audio && as) in.push_back(as); |
| | | |
| | | file_path_ = dir_ + "/" + sole::uuid4().base62() + ".mp4"; |
| | | auto ret = out_->JustWriter(in_->getStream(), file_path_.c_str()); |
| | | auto ret = out_->JustWriter(in, file_path_.c_str()); |
| | | if (ret){ |
| | | return 0; |
| | | } |
| | |
| | | end_writer(); |
| | | } |
| | | |
| | | int Recorder::Run(const char* output, const int mind, const int maxd){ |
| | | int Recorder::Run(const char* output, const int mind, const int maxd, const bool audio){ |
| | | |
| | | dir_ = output; |
| | | int ret = init_writer(); |
| | | int ret = init_writer(audio); |
| | | if(ret != 0){ |
| | | logIt("recorder init writer error"); |
| | | return -1; |
| | |
| | | minduration = fps * mind; |
| | | end_frame = minduration; |
| | | } |
| | | |
| | | audio_ = audio; |
| | | |
| | | // logIt("minduration %d maxduration %d curduration %d", minduration, maxduration, end_frame); |
| | | |
| | |
| | | |
| | | if(id_frame_ == -1){ |
| | | //wait I |
| | | if (!audio_ && in_->isAudioPkt(pkt.data->getAVPacket())){ |
| | | return 0; |
| | | } |
| | | |
| | | if (list_pkt_.empty()) { |
| | | AVPacket &avpkt = pkt.data->getAVPacket(); |
| | | if (!(avpkt.flags & AV_PKT_FLAG_KEY)){ |
| | |
| | | bool i = false; |
| | | for (auto &p : lst){ |
| | | if (!i){ |
| | | if (!audio_ && in_->isAudioPkt(p.data->getAVPacket())){ |
| | | continue; |
| | | } |
| | | AVPacket &avpkt = p.data->getAVPacket(); |
| | | if (!(avpkt.flags & AV_PKT_FLAG_KEY)){ |
| | | continue; |