| | |
| | | |
| | | typedef void* cffmpeg; |
| | | |
| | | cffmpeg c_ffmpeg_create(const int, const char *logfile); |
| | | cffmpeg c_ffmpeg_create(); |
| | | cffmpeg c_ffmpeg_create2(const char *logfile); |
| | | |
| | | void c_ffmpeg_destroy(const cffmpeg h); |
| | | void c_ffmpeg_run(const cffmpeg h, const char *input); |
| | | |
| | |
| | | |
| | | int pid = getpid(); |
| | | file_path_ = dir_ + "/" + sole::uuid4().base62() + "-" + std::to_string(pid) + ".mp4"; |
| | | auto ret = out_->JustWriter(in_->getStream(AVMEDIA_TYPE_VIDEO), in_->getStream(AVMEDIA_TYPE_AUDIO), file_path_.c_str()); |
| | | |
| | | auto v = in_->getStream(AVMEDIA_TYPE_VIDEO); |
| | | if (!v){ |
| | | return -2; |
| | | } |
| | | AVStream *a = in_->getStream(AVMEDIA_TYPE_AUDIO); |
| | | if (!audio){ |
| | | a = NULL; |
| | | } |
| | | auto ret = out_->JustWriter(v, a, file_path_.c_str()); |
| | | if (ret){ |
| | | logIt("start record file: %s", file_path_.c_str()); |
| | | return 0; |
| | |
| | | } |
| | | #endif |
| | | |
| | | #ifndef LIB_CFFMPEG |
| | | #include "csrc/all.hpp" |
| | | #endif |
| | | #include "csrc/wrapper.hpp" |
| | | |
| | | using namespace cffmpeg_wrap; |
| | | |
| | | cffmpeg c_ffmpeg_create(const int log, const char *logfile){ |
| | | bool logit = false; |
| | | if (log != 0) logit = true; |
| | | return new Wrapper(logit, logfile); |
| | | cffmpeg c_ffmpeg_create(){ |
| | | |
| | | return new Wrapper(); |
| | | } |
| | | |
| | | cffmpeg c_ffmpeg_create2(const char *logfile){ |
| | | return new Wrapper(logfile); |
| | | } |
| | | |
| | | void c_ffmpeg_destroy(const cffmpeg h){ |
| | |
| | | namespace cffmpeg_wrap{ |
| | | using namespace buz; |
| | | |
| | | Wrapper::Wrapper(const bool logit, const char *logfile) |
| | | Wrapper::Wrapper() |
| | | :input_url_("") |
| | | ,scale_w_(0) |
| | | ,scale_h_(0) |
| | |
| | | ,stream_(nullptr) |
| | | ,decoder_(nullptr) |
| | | ,rec_(new rec) |
| | | ,logit_(false) |
| | | { |
| | | makeTheWorld(); |
| | | if (logit){ |
| | | logif::CreateLogger(logfile, true); |
| | | } |
| | | |
| | | Wrapper::Wrapper(const char *logfile) |
| | | :input_url_("") |
| | | ,scale_w_(0) |
| | | ,scale_h_(0) |
| | | ,scale_f_(SWS_POINT) |
| | | ,audio_(false) |
| | | ,gb_(0) |
| | | ,cpu_(0) |
| | | ,run_dec_(false) |
| | | ,thread_(nullptr) |
| | | ,stop_stream_(false) |
| | | ,stream_(nullptr) |
| | | ,decoder_(nullptr) |
| | | ,rec_(new rec) |
| | | ,logit_(true) |
| | | { |
| | | makeTheWorld(); |
| | | logif::CreateLogger(logfile, true); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | logIt("WRAPPER EXCEPTION: ", e.what()); |
| | | } |
| | | if (logit_) |
| | | logif::DestroyLogger(); |
| | | } |
| | | |
| | |
| | | |
| | | class Wrapper{ |
| | | public: |
| | | explicit Wrapper(const bool logit, const char *logfile); |
| | | Wrapper(); |
| | | explicit Wrapper(const char *logfile); |
| | | ~Wrapper (); |
| | | private: |
| | | std::unique_ptr<ffwrapper::FormatIn> init_reader(const char* input); |
| | |
| | | rec* rec_; |
| | | // 录像请求缓存,等待runstream后添加 |
| | | std::function<void()> fn_rec_lazy_; |
| | | bool logit_; |
| | | }; |
| | | |
| | | uint8_t* Decode(const char *file, const int gb, int *w, int *h); |
| | |
| | | // New 2nd new |
| | | func New(conf Config) *GoFFMPEG { |
| | | |
| | | var l *C.char |
| | | |
| | | logit := 0 |
| | | f := C.wrap_fn_create(C.int(logit), l) |
| | | f := C.wrap_fn_create() |
| | | |
| | | if f == nil { |
| | | return nil |
| | |
| | | lf := C.CString(logfile) |
| | | defer C.free(unsafe.Pointer(lf)) |
| | | |
| | | logit := 1 |
| | | f := C.wrap_fn_create(C.int(logit), lf) |
| | | f := C.wrap_fn_create2(lf) |
| | | if f == nil { |
| | | return nil |
| | | } |
| | |
| | | if(lib){ |
| | | fn_create = (lib_cffmpeg_create)dlsym(lib, "c_ffmpeg_create"); |
| | | release_if_err(fn_create, lib); |
| | | fn_create2 = (lib_cffmpeg_create)dlsym(lib, "c_ffmpeg_create2"); |
| | | release_if_err(fn_create2, lib); |
| | | fn_destroy = (lib_cffmpeg_destroy)dlsym(lib, "c_ffmpeg_destroy"); |
| | | release_if_err(fn_destroy, lib); |
| | | fn_run = (lib_cffmpeg_run)dlsym(lib, "c_ffmpeg_run"); |
| | |
| | | } |
| | | } |
| | | |
| | | cffmpeg wrap_fn_create(const int log, const char *logfile){ |
| | | return fn_create(log, logfile); |
| | | cffmpeg wrap_fn_create(){ |
| | | return fn_create(); |
| | | } |
| | | |
| | | cffmpeg wrap_fn_create2(const char *logfile){ |
| | | return fn_create2(logfile); |
| | | } |
| | | |
| | | void wrap_fn_destroy(const cffmpeg h){ |
| | |
| | | |
| | | typedef void* cffmpeg; |
| | | |
| | | typedef cffmpeg(*lib_cffmpeg_create)(const int, const char*); |
| | | typedef cffmpeg(*lib_cffmpeg_create)(); |
| | | typedef cffmpeg(*lib_cffmpeg_create2)(const char*); |
| | | typedef void (*lib_cffmpeg_destroy)(const cffmpeg); |
| | | typedef void (*lib_cffmpeg_run)(const cffmpeg, const char*); |
| | | typedef void (*lib_cffmpeg_scale)(const cffmpeg, const int, const int, const int); |
| | |
| | | typedef void*(*lib_cffmpeg_decode)(const char*, const int, int*, int*); |
| | | |
| | | static lib_cffmpeg_create fn_create = NULL; |
| | | static lib_cffmpeg_create2 fn_create2 = NULL; |
| | | static lib_cffmpeg_destroy fn_destroy = NULL; |
| | | static lib_cffmpeg_run fn_run = NULL; |
| | | static lib_cffmpeg_scale fn_scale = NULL; |
| | |
| | | libcffmpeg init_libcffmpeg(const char *so_file); |
| | | void release_libcffmpeg(libcffmpeg lib); |
| | | |
| | | cffmpeg wrap_fn_create(const int log, const char *logfile); |
| | | cffmpeg wrap_fn_create(); |
| | | cffmpeg wrap_fn_create2(const char *logfile); |
| | | void wrap_fn_destroy(const cffmpeg h); |
| | | void wrap_fn_run(const cffmpeg h, const char* input); |
| | | void wrap_fn_scale(const cffmpeg h, const int wid, const int hei, const int flags); |