int RollPollingWorker::EncodeFrame(AVFrame* frame) { if (avcodecsendframe(ocodecctx,…
- User
int RollPollingWorker::EncodeFrame(AVFrame* frame) { if (avcodec_send_frame(ocodec_ctx_, frame) < 0) return -1;
AVPacket* enc_pkt = av_packet_alloc(); int ret = 0; while (ret >= 0) { ret = avcodec_receive_packet(ocodec_ctx_, enc_pkt); if (ret < 0) { if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) ret = 0; break; } enc_pkt->stream_index = 0; enc_pkt->pts = enc_pkt->dts = (frame_cnt_++) * 40; enc_pkt->duration = 0; enc_pkt->pos = -1; //std::cerr << "muxing frame: pts " << enc_pkt->pts << " duration " << enc_pkt->duration << "\n"; ret = av_interleaved_write_frame(ofmt_ctx_, enc_pkt); av_packet_unref(enc_pkt); if (ret < 0) { ErrorL << Prefix() << " write packet to output file failed \n"; break; } } av_packet_free(&enc_pkt); return ret;}
int RollPollingWorkerPool::StartWorker(const std::string input, const std::string output) { std::shared_ptr worker = std::make_shared(); if (!worker->Start(input, output)) { return -1; }
std::weak_ptr<RollPollingWorker> weak_worker = worker; auto task = [weak_worker](int64_t unused){ auto worker = weak_worker.lock(); if (worker) worker->Runnable(); }; std::lock_guard<std::mutex> lock(mutex_); worker_list_[output] = worker; return 0;}
int RollPollingWorkerPool::StopWorker(const std::string url) { std::lock_guardstd::mutex lock(mutex_); auto it = worker_list_.find(url); return it != worker_list_.end() ? it->second->Stop() : -1; }
int RollPollingWorkerPool::PollingStart(const std::vectorstd::string inputsurl, const std::string outputurl) { std::vectorstd::string inputs = inputsurl ; // for (int i = 1; i < (argc - 1); i++) // inputs.push_back(argv[i]); // std::string output = argv[argc - 1]; std::string output = outputurl;
mediakit::RollPollingWorker worker; if (worker.Start(inputs[0], output) < 0) return -1; auto f = [&](){ worker.Runnable(); }; std::thread task(f); task.detach(); size_t idx = 1; while (worker.IsRunning()) { std::this_thread::sleep_for(std::chrono::milliseconds(10000)); if (idx >= 4) break; if (inputs.size() > 1) { std::string tmp = inputs[idx % inputs.size()]; std::cerr << "change input file to [" << tmp << "\n"; worker.UpdateInput(tmp); idx++; } } worker.Stop(); //task.join(); return 0;}给这些代码加上注释
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.