/* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "avmuxer_ffmpeg_demo.h" #include #include #include #include namespace { const char *FFMPEG_REGISTER_FUNC_NAME = "register_FFmpegMuxer"; const char *FFMPEG_UNREGISTER_FUNC_NAME = "unregister_FFmpegMuxer"; const char *FFMPEG_LIB_PATH = "/libav_codec_plugin_FFmpegMuxer.z.so"; } namespace OHOS { namespace MediaAVCodec { namespace Plugin { Status AVMuxerFFmpegDemo::FfmpegRegister::AddPlugin(const PluginDefBase& def) { auto& tempDef = (MuxerPluginDef&)def; std::cout<<"find plugin apiVersion:"<(tempDef.pluginType); std::cout<<" |name:"<()) { } int AVMuxerFFmpegDemo::DoAddTrack(int32_t &trackIndex, MediaDescription &trackDesc) { int32_t tempTrackId = 0; ffmpegMuxer_->AddTrack(tempTrackId, trackDesc); if (tempTrackId < 0) { std::cout<<"AVMuxerFFmpegDemo::DoAddTrack failed! trackId:"<plugins.size() == 0) { std::cout<<"regist muxers failed!"<plugins) { if (plugin.pluginType == PluginType::MUXER) { auto prob = plugin.sniffer(plugin.name, outputFormat_); if (prob > maxProb) { maxProb = prob; pluginDef = plugin; } } } if (pluginDef.creator == nullptr) { std::cout<<"no plugins matching output format - "<< outputFormat_ <SetRotation(0); AddAudioTrack(audioParams_); AddVideoTrack(videoParams_); AddCoverTrack(coverParams_); ffmpegMuxer_->Start(); WriteCoverSample(); WriteTrackSample(); ffmpegMuxer_->Stop(); long long testTimeEnd = GetTimestamp(); std::cout << "muxer used time: " << testTimeEnd - testTimeStart << "us" << std::endl; } void AVMuxerFFmpegDemo::DoRunMultiThreadCase() { std::cout<<"ffmpeg plugin demo is not support multi-thread write!"< sample, AVCodecBufferInfo info, AVCodecBufferFlag flag) { if (ffmpegMuxer_ != nullptr && ffmpegMuxer_->WriteSample(trackIndex, sample->GetBase(), info, flag) == Status::NO_ERROR) { return 0; } return -1; } int AVMuxerFFmpegDemo::GetFfmpegRegister() { std::string libPath = AV_CODEC_PLUGIN_PATH; libPath += FFMPEG_LIB_PATH; dlHandle_ = ::dlopen(libPath.c_str(), RTLD_NOW | RTLD_LOCAL); if (dlHandle_ == nullptr) { std::cout<<"AVMuxerFFmpegDemo::GetFfmpegRegister dlHandle_ is nullptr!"<