// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
#include "FFMPEGMediaTracks.h"
#include "FFMPEGMediaPrivate.h"
#include "LambdaFunctionRunnable.h"
#include "FFMPEGMediaSettings.h"
#include "FFMPEGDecoder.h"
#include "FFMPEGFrame.h"
#include "IMediaOptions.h"
#include "MediaHelpers.h"
#include "Misc/ScopeLock.h"
#include "UObject/Class.h"
#include "IMediaBinarySample.h"
#include "IMediaEventSink.h"
#if WITH_ENGINE
#include "Engine/Engine.h"
#endif
#include "FFMPEGMediaBinarySample.h"
#include "FFMPEGMediaOverlaySample.h"
#include "FFMPEGMediaAudioSample.h"
#include "FFMPEGMediaTextureSample.h"
extern "C" {
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavutil/imgutils.h"
#include "libavutil/hwcontext.h"
#include "libavutil/time.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
}
#define MAX_QUEUE_SIZE (15 * 1024 * 1024)
#define MIN_FRAMES 30
/* polls for possible required screen refresh at least this often, should be less than 1/fps */
#define REFRESH_RATE 0.01
/* AV sync correction is done if above the maximum AV sync threshold */
#define AV_SYNC_THRESHOLD_MAX 0.1
/* no AV sync correction is done if below the minimum AV sync threshold */
#define AV_SYNC_THRESHOLD_MIN 0.04
/* AV sync correction is done if above the maximum AV sync threshold */
#define AV_SYNC_THRESHOLD_MAX 0.1
/* If a frame duration is longer than this, it will not be duplicated to compensate AV sync */
#define AV_SYNC_FRAMEDUP_THRESHOLD 0.1
#define EXTERNAL_CLOCK_MIN_FRAMES 2
#define EXTERNAL_CLOCK_MAX_FRAMES 10
/* external clock speed adjustment constants for realtime sources based on buffer fullness */
#define EXTERNAL_CLOCK_SPEED_MIN 0.900
#define EXTERNAL_CLOCK_SPEED_MAX 1.010
#define EXTERNAL_CLOCK_SPEED_STEP 0.001
/* Minimum audio buffer size, in samples. */
#define AUDIO_MIN_BUFFER_SIZE 512
/* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
#define AUDIO_MAX_CALLBACKS_PER_SEC 30
/* no AV correction is done if too big error */
#define AV_NOSYNC_THRESHOLD 10.0
/* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
#define AUDIO_DIFF_AVG_NB 20
/* maximum audio speed change to get correct sync */
#define SAMPLE_CORRECTION_PERCENT_MAX 10
#define LOCTEXT_NAMESPACE "FFMPEGMediaTracks"
/* FFFMPEGMediaTracks structors
*****************************************************************************/
FFFMPEGMediaTracks::FFFMPEGMediaTracks()
: AudioSamplePool(new FFFMPEGMediaAudioSamplePool)
, FormatContext(NULL)
, MediaSourceChanged(false)
, SelectedAudioTrack(INDEX_NONE)
, SelectedCaptionTrack(INDEX_NONE)
, SelectedMetadataTrack(INDEX_NONE)
, SelectedVideoTrack(INDEX_NONE)
, SelectionChanged(false)
, VideoSamplePool(new FFFMPEGMediaTextureSamplePool)
, CurrentRate(0.0f)
, CurrentState (EMediaState::Closed)
, LastState (EMediaState::Closed)
, CurrentTime(FTimespan::Zero())
, Duration(FTimespan::Zero())
, ShouldLoop(false)
, bPrerolled(false)
, imgConvertCtx(NULL)
, readThread(nullptr)
, audioThread(nullptr)
, videoThread(nullptr)
, subtitleThread(nullptr)
, displayThread(nullptr)
, audioStream(NULL)
, videoStream(NULL)
, subTitleStream(NULL)
, video_ctx(NULL)
, hw_device_ctx(NULL)
, hw_frames_ctx(NULL)
, swrContext(NULL)
, aborted(false)
, displayRunning(false)
, step(false)
, seekReq(false)
, seekPos(0)
, seekRel(0)
, seekFlags(0)
, queueAttachmentsReq(false)
, videoStreamIdx(-1)
, audioStreamIdx(-1)
, subtitleStreamIdx(-1)
, forceRefresh(false)
, frameDropsLate(0)
, frameDropsEarly(0)
, frameTimer(0.0)
, maxFrameDuration(0.0)
, realtime(false)
, audioBuf(NULL)
, audioBuf1(NULL)
, audioBufSize(0)
, audioBuf1Size(0)
, audioClockSerial(0)
, audioClock(0)
, audioCallbackTime(0)
, audioDiffAvgCoef(0)
, audioDiffThreshold(0)
, audioDiffAvgCount(0)
, audioDiffCum(0)
, totalStreams(0)
, currentStreams(0)
, hwAccelPixFmt(AV_PIX_FMT_NONE)
, hwAccelDeviceType(AV_HWDEVICE_TYPE_NONE){
}
FFFMPEGMediaTracks::~FFFMPEGMediaTracks()
{
Shutdown();
delete AudioSamplePool;
AudioSamplePool = nullptr;
delete VideoSamplePool;
VideoSamplePool = nullptr;
}
/* FFFMPEGMediaTracks interface
*****************************************************************************/
void FFFMPEGMediaTracks::AppendStats(FString &OutStats) const
{
FScopeLock Lock(&CriticalSection);
// audio tracks
OutStats += TEXT("Audio Tracks\n");
if (AudioTracks.Num() == 0)
{
OutStats += TEXT("\tnone\n");
}
else
{
for (const FTrack& Track : AudioTracks)
{
OutStats += FString::Printf(TEXT("\t%s\n"), *Track.DisplayName.ToString());
OutStats += TEXT("\t\tNot implemented yet");
}
}
// video tracks
OutStats += TEXT("Video Tracks\n");
if (VideoTracks.Num() == 0)
{
OutStats += TEXT("\tnone\n");
}
else
{
for (const FTrack& Track : VideoTracks)
{
OutStats += FString::Printf(TEXT("\t%s\n"), *Track.DisplayName.ToString());
OutStats += TEXT("\t\tNot implemented yet");
}
}
}
void FFFMPEGMediaTracks::ClearFlags()
{
FScopeLock Lock(&CriticalSection);
MediaSourceChanged = false;
SelectionChanged = false;
}
void FFFMPEGMediaTracks::GetEvents(TArray<EMediaEvent>& OutEvents) {
EMediaEvent Event;
while (DeferredEvents.Dequeue(Event))
{
OutEvents.Add(Event);
}
}
void FFFMPEGMediaTracks::GetFlags(bool& OutMediaSourceChanged, bool& OutSelectionChanged) const
{
FScopeLock Lock(&CriticalSection);
OutMediaSourceChanged = MediaSourceChanged;
OutSelectionChanged = SelectionChanged;
}
void FFFMPEGMediaTracks::Initialize(AVFormatContext* ic, const FString& Url)
{
Shutdown();
UE_LOG(LogFFMPEGMedia, Verbose, TEXT("Tracks: %p: Initializing (media source %p)"), this, ic);
FScopeLock Lock(&CriticalSection);
MediaSourceChanged = true;
SelectionChanged = true;
if (!ic)
{
CurrentState = EMediaState::Error;
return;
}
if (pictq.Init(&videoq, VIDEO_PICTURE_QUEUE_SIZE, 1) < 0) {
Shutdown();
CurrentState = EMediaState::Error;
return ;
}
realtime = IsRealtime(ic) != 0;
if (subpq.Init(&subtitleq, SUBPICTURE_QUEUE_SIZE, 0) < 0) {
Shutdown();
CurrentState = EMediaState::Error;
return;
}
if (sampq.Init(&audioq, SAMPLE_QUEUE_SIZE, 1) < 0) {
Shutdown();
CurrentState = EMediaState::Error;
return;
}
vidclk.Init(&videoq);
audclk.Init(&audioq);
extclk.Init(&extclk);
this->FormatContext = ic;
audioClockSerial = -1;
CurrentState = EMediaState::Preparing;
//
bool AllStreamsAdded = true;
for (int i = 0; i < (int)ic->nb_streams; i++) {
AVStream *st = ic->streams[i];
bool streamAdded = AddStreamToTracks(i, false, Info);
AllStreamsAdded &= streamAdded;
if ( streamAdded) {
totalStreams++;
}
enum AVMediaType type = st->codecpar->codec_type;
st->discard = AVDISCARD_ALL;
}
if (!AllStreamsAdded)
{
UE_LOG(LogFFMPEGMedia, Verbose, TEXT("Tracks %p: Not all available streams were added to the track collection"), this);
}
int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
Duration = duration * 10;
maxFrameDuration = (ic->iformat->flags & AVFMT_TS_DISCONT) ? 10.0 : 3600.0;
SetRate(0.0f);
DeferredEvents.Enqueue(EMediaEvent::MediaOpened);
//Start the read thread
aborted = false;
const auto Settings = GetDefault<UFFMPEGMediaSettings>();
sychronizationType = Settings->SyncType;
readThread = LambdaFunctionRun
没有合适的资源?快使用搜索试试~ 我知道了~
FFMPEGMedia:虚幻FFMPEG插件,支持更多视频格式和Alpha视频
共997个文件
h:898个
so:29个
dll:16个
2星 需积分: 42 32 下载量 163 浏览量
2021-02-06
02:27:28
上传
评论 2
收藏 73.04MB ZIP 举报
温馨提示
FFMPEG媒体插件,用于虚幻引擎 一个让您将FFMPEG库用作媒体播放器的插件 特征: 在Windows和Mac上均可使用 支持硬件加速编解码器 支持带有Alpha的视频 如何使用 该插件适用于Unreal 4.26 您可以将存储库克隆到<Game>/Plugins/或者如果需要,可以将git子模块用于自己的git存储库。 另外,如果您希望使插件可用于所有项目,则可以复制到Engine/Plugins/ 。 不要忘记运行UE4的“ Generate Project Files来说明这些更改! 按照以下步骤但出于对使用自动播放器的偏爱,请在播放器替代中选择FFMPEGPlayer,以进行
资源详情
资源评论
资源推荐
收起资源包目录
FFMPEGMedia:虚幻FFMPEG插件,支持更多视频格式和Alpha视频 (997个子文件)
overlay.cl 4KB
unsharp.cl 3KB
avgblur.cl 2KB
convolution.cl 2KB
FFMPEGMediaTracks.cpp 83KB
FFMPEGMediaPlayer.cpp 17KB
FFMPEGMediaModule.cpp 8KB
FFMPEGDecoder.cpp 6KB
FFMPEGMediaFactoryModule.cpp 6KB
FFMPEGPacketQueue.cpp 4KB
FFMPEGFrameQueue.cpp 3KB
FFMPEGFrame.cpp 3KB
FFMPEGClock.cpp 2KB
CondWait.cpp 857B
LambdaFunctionRunnable.cpp 604B
FFMPEGMediaFactoryClasses.cpp 488B
FFMPEGMedia.Build.cs 6KB
FFMPEGMediaFactory.Build.cs 1KB
vf_scale_cuda.cu 10KB
vf_thumbnail_cuda.cu 3KB
avcodec-58.dll 11.8MB
avcodec-58.dll 10.7MB
avfilter-7.dll 3.72MB
avformat-58.dll 3.25MB
avfilter-7.dll 2.94MB
avformat-58.dll 2.63MB
avutil-56.dll 1.21MB
swscale-5.dll 1.1MB
avutil-56.dll 1016KB
swscale-5.dll 876KB
avdevice-58.dll 725KB
swresample-3.dll 590KB
avdevice-58.dll 578KB
postproc-55.dll 513KB
swresample-3.dll 472KB
postproc-55.dll 420KB
libavcodec.58.dylib 16.94MB
libavfilter.7.dylib 2.89MB
libavformat.58.dylib 2.41MB
libswscale.5.dylib 862KB
libavutil.56.dylib 469KB
libswresample.3.dylib 146KB
libpostproc.55.dylib 142KB
libavdevice.58.dylib 66KB
.gitignore 154B
twinvq_data.h 678KB
ralfdata.h 612KB
rv34vlc.h 249KB
avcodec.h 207KB
wmavoice_data.h 184KB
generic_macros_msa.h 147KB
avformat.h 115KB
ulti_cb.h 113KB
clearvideodata.h 108KB
amrnbdata.h 102KB
amrwbdata.h 99KB
svq1_cb.h 97KB
atrac3plus_data.h 91KB
g723_1.h 81KB
vp3data.h 80KB
evrcdata.h 76KB
wmadata.h 72KB
sheervideodata.h 68KB
intrax8huf.h 57KB
options_table.h 52KB
swscale_internal.h 44KB
tscc2data.h 43KB
wavpackenc.h 43KB
avfilter.h 41KB
mpegvideo.h 38KB
aacsbrdata.h 38KB
opt.h 35KB
aaccoder_twoloop.h 35KB
h264_mvpred.h 35KB
binkdata.h 33KB
vp8data.h 33KB
rv40vlc2.h 33KB
pixfmt.h 32KB
sipr16kdata.h 32KB
dolby_e.h 32KB
avio.h 31KB
h264dsp_mips.h 31KB
aacsbr_mips.h 30KB
cookdata.h 28KB
frame.h 28KB
wmaprodata.h 28KB
aacps_fixed_tablegen.h 26KB
qdm2data.h 26KB
fft_vsx.h 26KB
h264dec.h 25KB
internal.h 25KB
signature.h 25KB
vorbis_enc_data.h 25KB
mpegaudiodectab.h 23KB
mem.h 23KB
hwcontext.h 22KB
rtsp.h 22KB
snow.h 21KB
swresample.h 21KB
avresample.h 21KB
共 997 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
小马甲不小
- 粉丝: 21
- 资源: 4714
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- foldcraftlauncher_262944.apk
- 珍藏多年的基于matlab实现潮流计算程序源代码集合,包含多个潮流计算程序.rar
- 使用FPGA实现串-并型乘法器
- 基于matlab实现针对基于双曲线定位的DV-Hop算法中误差误差出一种基于加权双曲线定位的DV-Hop改进算法.rar
- 基于matlab实现由遗传算法开发的整数规划,车辆调度问题.rar
- 电视家7.0(对电视配置要求高).apk
- 免费计算机毕业设计-基于JavaEE的医院病历管理系统设计与实现(包含论文+源码)
- 手机端 我的世界融合植物大战僵尸版.apk
- 植物大战僵尸 · 戴夫的老年生活 手机版.apk
- Runcraft · 我的世界跑酷游戏 手机端.apk
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3