/* * 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 #include "data_sink_fd.h" #include "plugin/plugin_manager_v2.h" namespace OHOS { namespace MediaAVCodec { int AVMuxerFFmpegDemo::DoAddTrack(int32_t &trackIndex, std::shared_ptr trackDesc) { int32_t tempTrackId = 0; ffmpegMuxer_->AddTrack(tempTrackId, trackDesc); if (tempTrackId < 0) { std::cout<<"AVMuxerFFmpegDemo::DoAddTrack failed! trackId:"<SetDataSink(std::make_shared(outFd_)); 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) { if (ffmpegMuxer_ != nullptr && ffmpegMuxer_->WriteSample(trackIndex, sample) == Status::OK) { return 0; } return -1; } std::shared_ptr AVMuxerFFmpegDemo::CreatePlugin(Plugins::OutputFormat format) { static const std::unordered_map table = { {Plugins::OutputFormat::DEFAULT, Plugins::MimeType::MEDIA_MP4}, {Plugins::OutputFormat::MPEG_4, Plugins::MimeType::MEDIA_MP4}, {Plugins::OutputFormat::M4A, Plugins::MimeType::MEDIA_M4A}, {Plugins::OutputFormat::MP3, Plugins::MimeType::MEDIA_MP3}, }; auto plugin = Plugins::PluginManagerV2::Instance().CreatePluginByMime(Plugins::PluginType::MUXER, table.at(format)); if (plugin == nullptr) { return nullptr; } return std::reinterpret_pointer_cast(plugin); } } // namespace MediaAVCodec } // namespace OHOS