From 3fbfd75b813dda4af1d505f5a1e7c2543ed68f49 Mon Sep 17 00:00:00 2001 From: reego-fr Date: Mon, 1 Aug 2016 22:56:32 +0200 Subject: [PATCH] Enable uncompressed video frames deinterlacing --- FFmpegInterop/Source/FFmpegInteropMSS.cpp | 3 +++ .../UncompressedVideoSampleProvider.cpp | 24 +++++++++++++++++++ .../Source/UncompressedVideoSampleProvider.h | 4 +++- .../Win10/FFmpegInterop/FFmpegInterop.vcxproj | 12 +++++----- .../FFmpegInterop.Windows.vcxproj | 12 +++++----- .../FFmpegInterop.WindowsPhone.vcxproj | 8 +++---- 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/FFmpegInterop/Source/FFmpegInteropMSS.cpp b/FFmpegInterop/Source/FFmpegInteropMSS.cpp index 334517c7..ab43742d 100644 --- a/FFmpegInterop/Source/FFmpegInteropMSS.cpp +++ b/FFmpegInterop/Source/FFmpegInteropMSS.cpp @@ -24,6 +24,7 @@ #include "UncompressedAudioSampleProvider.h" #include "UncompressedVideoSampleProvider.h" #include "shcore.h" +#include extern "C" { @@ -451,6 +452,8 @@ HRESULT FFmpegInteropMSS::CreateVideoStreamDescriptor(bool forceVideoDecode) videoProperties->PixelAspectRatio->Numerator = avVideoCodecCtx->sample_aspect_ratio.num; videoProperties->PixelAspectRatio->Denominator = avVideoCodecCtx->sample_aspect_ratio.den; } + + videoProperties->Properties->Insert(MF_MT_INTERLACE_MODE, (uint32)_MFVideoInterlaceMode::MFVideoInterlace_MixedInterlaceOrProgressive); } // Detect the correct framerate diff --git a/FFmpegInterop/Source/UncompressedVideoSampleProvider.cpp b/FFmpegInterop/Source/UncompressedVideoSampleProvider.cpp index 7634a602..1cf5bd5d 100644 --- a/FFmpegInterop/Source/UncompressedVideoSampleProvider.cpp +++ b/FFmpegInterop/Source/UncompressedVideoSampleProvider.cpp @@ -18,6 +18,7 @@ #include "pch.h" #include "UncompressedVideoSampleProvider.h" +#include extern "C" { @@ -100,6 +101,27 @@ UncompressedVideoSampleProvider::~UncompressedVideoSampleProvider() } } +MediaStreamSample^ UncompressedVideoSampleProvider::GetNextSample() +{ + MediaStreamSample^ sample = MediaSampleProvider::GetNextSample(); + + if (sample != nullptr) + { + if (m_interlaced_frame) + { + sample->ExtendedProperties->Insert(MFSampleExtension_Interlaced, TRUE); + sample->ExtendedProperties->Insert(MFSampleExtension_BottomFieldFirst, m_top_field_first ? FALSE : TRUE); + sample->ExtendedProperties->Insert(MFSampleExtension_RepeatFirstField, FALSE); + } + else + { + sample->ExtendedProperties->Insert(MFSampleExtension_Interlaced, FALSE); + } + } + + return sample; +} + HRESULT UncompressedVideoSampleProvider::WriteAVPacketToStream(DataWriter^ dataWriter, AVPacket* avPacket) { // Convert decoded video pixel format to NV12 using FFmpeg software scaler @@ -130,6 +152,8 @@ HRESULT UncompressedVideoSampleProvider::DecodeAVPacket(DataWriter^ dataWriter, if (frameComplete) { avPacket->pts = av_frame_get_best_effort_timestamp(m_pAvFrame); + m_interlaced_frame = m_pAvFrame->interlaced_frame == 1; + m_top_field_first = m_pAvFrame->top_field_first == 1; } } diff --git a/FFmpegInterop/Source/UncompressedVideoSampleProvider.h b/FFmpegInterop/Source/UncompressedVideoSampleProvider.h index 2b621e9f..86dea6ca 100644 --- a/FFmpegInterop/Source/UncompressedVideoSampleProvider.h +++ b/FFmpegInterop/Source/UncompressedVideoSampleProvider.h @@ -31,7 +31,7 @@ namespace FFmpegInterop { public: virtual ~UncompressedVideoSampleProvider(); - + virtual MediaStreamSample^ GetNextSample() override; internal: UncompressedVideoSampleProvider( FFmpegReader^ reader, @@ -46,6 +46,8 @@ namespace FFmpegInterop SwsContext* m_pSwsCtx; int m_rgVideoBufferLineSize[4]; uint8_t* m_rgVideoBufferData[4]; + bool m_interlaced_frame; + bool m_top_field_first; }; } diff --git a/FFmpegInterop/Win10/FFmpegInterop/FFmpegInterop.vcxproj b/FFmpegInterop/Win10/FFmpegInterop/FFmpegInterop.vcxproj index 47909a65..08ceaf04 100644 --- a/FFmpegInterop/Win10/FFmpegInterop/FFmpegInterop.vcxproj +++ b/FFmpegInterop/Win10/FFmpegInterop/FFmpegInterop.vcxproj @@ -129,7 +129,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -147,7 +147,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -165,7 +165,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -183,7 +183,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -201,7 +201,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -219,7 +219,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) diff --git a/FFmpegInterop/Win8.1/FFmpegInterop.Windows/FFmpegInterop.Windows.vcxproj b/FFmpegInterop/Win8.1/FFmpegInterop.Windows/FFmpegInterop.Windows.vcxproj index b7cc7a87..fe67e154 100644 --- a/FFmpegInterop/Win8.1/FFmpegInterop.Windows/FFmpegInterop.Windows.vcxproj +++ b/FFmpegInterop/Win8.1/FFmpegInterop.Windows/FFmpegInterop.Windows.vcxproj @@ -123,7 +123,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -141,7 +141,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -159,7 +159,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -177,7 +177,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -195,7 +195,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -213,7 +213,7 @@ Console - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;runtimeobject.lib;mfuuid.lib;%(AdditionalDependencies) false $(SolutionDir)ffmpeg\Build\Windows8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) diff --git a/FFmpegInterop/Win8.1/FFmpegInterop.WindowsPhone/FFmpegInterop.WindowsPhone.vcxproj b/FFmpegInterop/Win8.1/FFmpegInterop.WindowsPhone/FFmpegInterop.WindowsPhone.vcxproj index d18c33ce..331fddf4 100644 --- a/FFmpegInterop/Win8.1/FFmpegInterop.WindowsPhone/FFmpegInterop.WindowsPhone.vcxproj +++ b/FFmpegInterop/Win8.1/FFmpegInterop.WindowsPhone/FFmpegInterop.WindowsPhone.vcxproj @@ -87,7 +87,7 @@ Console false - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;mfuuid.lib;%(AdditionalDependencies) $(SolutionDir)ffmpeg\Build\WindowsPhone8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -104,7 +104,7 @@ Console false - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;mfuuid.lib;%(AdditionalDependencies) $(SolutionDir)ffmpeg\Build\WindowsPhone8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -121,7 +121,7 @@ Console false - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;mfuuid.lib;%(AdditionalDependencies) $(SolutionDir)ffmpeg\Build\WindowsPhone8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories) @@ -138,7 +138,7 @@ Console false - avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;%(AdditionalDependencies) + avcodec.lib;avdevice.lib;avfilter.lib;avformat.lib;avutil.lib;swresample.lib;swscale.lib;shcore.lib;mfuuid.lib;%(AdditionalDependencies) $(SolutionDir)ffmpeg\Build\WindowsPhone8.1\$(PlatformTarget)\bin;%(AdditionalLibraryDirectories)