Code Monkey home page Code Monkey logo

flyleaf's Introduction

Flyleaf v3.7: Media Player .NET Library for WinUI 3/WPF/WinForms (based on FFmpeg/DirectX)

alt text


Notes

  1. FlyleafLib's releases will be on NuGet
  2. Compiled samples will be on GitHub releases
  3. Documentation will be on Wiki and Samples within the solution

[Overview]

Play Everything (Audio, Videos, Images, Playlists over any Protocol)

  • Extends FFmpeg's supported protocols and formats with additional plugins (YoutubeDL, TorrentBitSwarm)
  • Accepts Custom I/O Streams and Plugins to handle non-standard protocols / formats

Play it Smoothly (Even with high resolutions 4K / HDR)

  • Coded from scratch to gain the best possible performance with FFmpeg & DirectX using video acceleration and custom pixel shaders
  • Threading implementation with efficient cancellation which allows fast open, play, pause, stop, seek and stream switching

Develop it Easy

  • Provides a DPI aware, hardware accelerated Direct3D Surface (FlyleafHost) which can be hosted as normal control to your application and easily develop above it your own transparent overlay content
  • All the implementation uses UI notifications (PropertyChanged / ObservableCollection etc.) so you can use it as a ViewModel directly
  • For WPF provides a Control (FlyleafME) with all the basic UI sub-controls (Bar, Settings, Popup menu) and can be customized with style / control template overrides

[Features]

FFmpeg

  • HLS Live Seeking Might the 1st FFmpeg player which does that
  • Pached for HLS issue Use recommended FFmpeg libraries which can be found on GitHub releases
  • Capture Devices Pass the format, input and options with a single Url eg. fmt://gdigrab?desktop&framerate=30
  • Supports FFmpeg v5+

Playback

  • Open / Play / Pause / Stop
  • Speed / Reverse / Zero-Low Latency
  • Seek Backward / Forward (Short / Large Step)
  • Seek to Time / Seek to Frame / Seek to Chapter / Frame Stepping

Video

  • Enable / Disable
  • Device Preference
  • Aspect Ratio (Keep / Fill / Custom)
  • Deinterlace (Bob)
  • HDR to SDR (Aces / Hable / Reinhard) [BT2020 / SMPTE 2084 to BT709]
  • Pan Move / Zoom / Rotate / HFlip-VFlip (Replica Renderer/Interactive Zoom)
  • Record / Snapshot
  • Video Acceleration
  • Video Filters (Brightness / Contrast / Hue / Saturation)
  • Video Processors (Flyleaf / D3D11)
  • VSync
  • Zero-Copy

Audio

  • Enable / Disable
  • Device Preference
  • Add / Remove Delay (Short / Large Step)
  • Volume (Up / Down / Mute)
  • Languages support System's default languages as priorities for audio streams

Subtitles

  • Enable / Disable
  • Add / Remove Delay (Short / Large Step)
  • Advanced Character Detection and Convert to UTF-8 SubtitlesConverter plugin
  • Languages support System's default languages as priorities for subtitles streams

UI Control (FlyleafHost)WPF / WinUI & WinForms (Partially)

  • Attach / Detach
  • Activity / Idle Mode
  • Drag Move (Self / Owner)
  • Drag & Drop Swap
  • Drag & Drop Open
  • Full / Normal Screen
  • Resize / Resize & Keep Ratio
  • Z-Order

UI Control (FlyleafME) WPF Only

  • Flyleaf Bar Control / Slider
  • Flyleaf Popup Menu
  • Flyleaf Settings Dialog
  • Color Themes Based on Material Design in XAML
  • Style / Control Template Customization

Plugins

  • OpenSubtitlesOrg Search & Download for online Subtitles
  • SubtitlesConverter Detect & Convert the input's charset to UTF-8
  • TorrentBitSwarm Play a media from torrent without the need to download it completely
  • YoutubeDL Play web media that are not accessible directly with HTTP(s)

Misc.

  • Mouse & Key Bindings All the implementation supports customizable mouse & key bindings which can be assigned to an embedded or a custom actions (find defaults here)
  • Audio Player Can be used as an audio player only without the need of UI Control
  • Downloader / Remuxer The library can be used also for downloading & remuxing
  • Extractor The library can be used also for extracting video frames (supports also by X frames Step)

[Thanks to]

Flyleaf wouldn't exist without them!

flyleaf's People

Contributors

akateleplan avatar brandon689 avatar coldays avatar robvdpol avatar shjung-nextk avatar signumnova avatar surgeonix avatar xmine64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flyleaf's Issues

About RTSP

when I use the rtsp url,it can't play it?

Additional useful/required events

Hi,

can you add some events of player as: OnTimeChanged (for trackbar), OnFinished (for play next file), OnError (for write error log to file), OnStateChanged (Playing, Pause, Error,...) , OnDisconnected, OnNewFrame,...

AudioPlayer can not initialize when no audio device

Hi,

When PC dont have any audio output device (speaker, headphone,...) your app can not start because AudioPlayer can not initialize.
Maybe you need add a function to AudioPlayer constructor:

if (deviceEnum.HasDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia))
{
//
}

ảnh

Can I use your repo to pick up frames from one MP4 video?

Hello:
I have one MP4 format video (C:\Videos\1.mp4), which contains 1000 frames.
If I want to pick up frames every 100 frames, in my case, I want to pick up the first frame, the 100th, 200th, 300th, 400th, 500th, 600th, 700th, 800th, 900th and the last frame, and put them into one array of images.
Then use ImageMagick to find the image similarity between the first frame and other frames and find which is the first frame which is more than 10% different from the first frame.
One good example for this is the basketball score board, which will change after a few seconds or a few minutes, but there is no way to know when the score change will happen. In the worst case from my college experience, one women basket ball game ended with score: 4-0, it means it changes only twice (from 0-0 to 2-0, and from 2-0 to 4-0). But most other games will change very quickly.
Let me know if I can do this with your repo?
If yes, give me some code sample.
Thanks,

[Bug] Connecting or removing a Bluetooth causes the player to crash

Describe the bug
When playing a video and switching to/from a bluetooth device, the player stops playing the video and the application hangs.

To Reproduce
Steps to reproduce the behavior:

  1. Open the WPF sample
  2. Play a video
  3. Connect/disconnect a bluetooth audio device
  4. The player should freeze

Expected behavior
The player doesn't freeze and the audio is transferred to or from the bluetooth audio device.

Additional context
I have determined the issue is most likely caused by this line:


That line hangs when connecting or disconnecting a bluetooth device, it seems like there might be a deadlock in there somewhere.
If I comment that line out, the issue disappears completely. I have also tried to put a lock around it, which seems to sometimes fix the issue when connecting the bluetooth device, but never when disconnecting. I have also looked on the internet and there it is also suggested this might be a threading/deadlock issue, so the solution should probably be searched for in that area.

I will do some investigation myself to see if I can fix this issue, but if anyone has any ideas let me know.

VIDEO_MAX_QUEUE_SIZE or VIDEO_MIX_QUEUE_SIZE

Please check:

// We use 3 * max queue size for live streaming (currently live stream means duration = 0 | possible check if hls?)
// We need to ensure that we have also enough Audio Samples (for embedded audio stream) - is it possible to calculate this?
while (type == AVMEDIA_TYPE_VIDEO && dec.isRunning && dec.player.vFrames.Count > (dec.player.Duration == 0 ? dec.player.VIDEO_MIX_QUEUE_SIZE * 3 : dec.player.VIDEO_MIX_QUEUE_SIZE))
Thread.Sleep(5);

Application volume is always set to 100 (for Flyleaf and all other windows applications started when Flyleaf running)

Describe the bug
Originally found in Race Control( robvdpol/RaceControl#195 and robvdpol/RaceControl#196), traced back to Flyleaf.
This bug has two sides to it.
With Windows Volume Mixer you can set the volume level for each individual application.

Problem 1:
When you set Flyleaf's volume in the mixer to something and reopen Flyleaf, the volume is always set back to 100.

Problem 2:
When Flyleaf is open the above problem also occurs for every other application you open which uses the same sound source.
This only happens to applications which get start after Flyleaf was started, so applications which were already running do not get reset.

To Reproduce
Steps to reproduce the behavior:

  1. Open an application, for this example Chrome
  2. Play something with sound through Chrome so that Windows recognizes it as sound output in the volume mixer
  3. Set the volume to something other than 100, for example to 30
  4. Open Flyleaf
  5. Close Chrome
  6. Open Chrome
  7. Play something with sound again.
  8. The volume is now reset to 100 because Flyleaf is open and now controlling all new audio sessions

Expected behavior
The expected behaviour is that the default behaviour for set volumes for the different application in the volume mixer do not get affected by Flyleaf.

Screenshots
Start situation:
image
After reproduction:
image

Additional context
Upon investigation in the code the problems occurs in AudioMaster.cs in the OnSessionCreated delegate:

device.AudioSessionManager.OnSessionCreated += (o, newSession) =>
{
if (session != null) { session.UnRegisterEventClient(this); session.Dispose(); }
session = new AudioSessionControl(newSession);
session.RegisterEventClient(this);
session.SimpleAudioVolume.Volume = 1;
Raise(nameof(VolumeSession));
Raise(nameof(MuteSession));
};

Here the volume will always be set to 1 (100);
session.SimpleAudioVolume.Volume = 1;

Once Flyleaf is running every new audio session will be caught by NAudio. This causes problem 2.
You can test this by setting a breakpoint in the above function and starting a any new application (which uses audio) while it is debugging.

I feel like it is not necessary to set the volume here since the default volume for windows applications will be set to 100 anyway.

A different way to fix this is to not handle the audio events which are not coming from Flyleaf (or applications which implement Flyleaf), but I think not setting the volume to 1 is way simpler for now.

Delay when play live stream

Hi,

when play rtsp stream from camera, MediaRouter delay 15 seconds compare with VideoPlayer_HWAcceleration in Tutorials folder.
image

left is MediaRouter, right is VideoPlayer_HWAcceleration
this is rtsp url if you want to test: rtsp://admin:[email protected]:24554/Src/mediainput/stream_1

Memory leak problem

I tried to create a player in the background code. I found that every time I created it, the memory could not be released normally.
How can I improve it?
Thank you.

using FlyleafLib 3.1.0 from nuget

MainWindow.xaml:

<Window
    x:Class="FlyleafLib.Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Button Click="ButtonNew_OnClick">
            Create New Instance
            (1. each click leak some memory,
            2. click in quick succession the program crashes )
        </Button>

        <ContentControl
            x:Name="ContentControl"
            Grid.Row="1"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch" />
    </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using FlyleafLib.Controls.WPF;
using FlyleafLib.MediaPlayer;

namespace FlyleafLib.Test
{
    public partial class MainWindow
    {
        public Player Player { get; set; }

        public MainWindow()
        {
            InitializeComponent();

            Master.RegisterFFmpeg(":2");
        }

        private FlyleafLib.Controls.WPF.VideoView _videoView;

        private FlyleafLib.MediaPlayer.Player _player;

        private FlyleafLib.Controls.WPF.Flyleaf _flyleaf;

        private async void ButtonNew_OnClick(object sender, RoutedEventArgs e)
        {
            _player?.Stop();
            await Task.Run(() => _player?.Dispose());

            _videoView = new VideoView();
            _videoView.UpdateDefaultStyle();
            _videoView.ApplyTemplate();

            _flyleaf           = new Flyleaf();
            _videoView.Content = _flyleaf;

            Config config = new Config();
            config.demuxer.VideoFormatOpt.Add("probesize",       (50 * (long) 1024 * 1024).ToString());
            config.demuxer.VideoFormatOpt.Add("analyzeduration", (10 * (long) 1000 * 1000).ToString());
            _player = new Player(config);

            _videoView.BeginInit();

            _player.Control   = _videoView.FlyleafWF;
            _videoView.Player = _player;
            _flyleaf.Player   = _player;

            ContentControl.Content = _videoView;

            _player.Open(@"VIDEO FILE");

            _player.Play();
        }
    }
}

Quite a number of issues using your repo in C# console project.

I have done the following in order to use your repo in C# console project (target .NET 5.0)
Download and unzip ffmpeg full build file from this URL:
https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z
Copy the unzipped folder to C:\Program Files
Edit System PATH variable to add ffmpeg binary path.
I have installed nuget packages:
PM> Install-Package FFmpeg.AutoGen -Version 4.4.0
PM> Install-Package NAudio.Wasapi -Version 2.0.0
PM> Install-Package SharpDX.Mathematics -Version 4.2.0
PM> Install-Package FlyleafLib -Version 3.1.12
PM> Install-Package FlyleafLib.Controls.WPF -Version 1.1.4
Before going further, I found the following warnings:
For both FlyleafLib & FlyleafLib.Controls.WPF, I saw yellow color icon next to the both, showing:
Warning NU1701 Package 'FlyleafLib 3.1.12' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.
Warning NU1701 Package 'FlyleafLib.Controls.WPF 1.1.4' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.
For the above warnings, can you please make new nuget package to target .NET 5.0?

I have written the following C# code, trying to download one M3U8 URL to local hard drive.

using FlyleafLib;
using FlyleafLib.MediaFramework.MediaDemuxer;
using System;
using System.Threading.Tasks;

namespace FlyleafDownloadTest1
{
class Program
{
public const string FFMPEG_Binary = @"C:\Program Files\ffmpeg-4.4-full_build\bin";
public const string Output_File1 = @"C:\Videos\FFMPEG\Download1.mp4";

    private static void Downloader1_DownloadCompleted(object sender, bool success)
    {
        if (success)
        {
            Console.WriteLine("Partial/Live Download Completed!");
        }
        else
            Console.WriteLine("Download Failed!");
    }
    static async Task Main(string[] args)
    {
        Master.RegisterFFmpeg(FFMPEG_Binary);
        DemuxerBase Downloader1 = new VideoDemuxer(new Config(), 1);
        Downloader1.DownloadCompleted += Downloader1_DownloadCompleted;
        string url1 = @"https://www.rmp-streaming.com/media/big-buck-bunny-360p.mp4";
        if (Downloader1.Open(url1) != 0) 
        { Console.WriteLine("Could not open url input"); return; }
        Downloader1.EnableStream(Downloader1.VideoStreams[0]);
        if (Downloader1.AudioStreams.Count != 0) 
            Downloader1.EnableStream(Downloader1.AudioStreams[0]);
        Downloader1.Download(Output_File1);
        await Task.Delay(10000);
        if (Downloader1.Url.Contains("bunny"))
            Downloader1.Stop();
        Console.WriteLine("Done!");
    }
}

}

I just want to see if I can use your repo to download M3U8 URL to local hard disk in C# console project, without using any GUI interface. I think this could be very basic usage, if successful, I can use it somewhere else, like WinForm project. But I don’t like WPF, as there are too many restrictions.
However, when I run my code, I got a lot of this type errors:
System.Exception
HResult=0x80131500
Message=Failed to register FFmpeg libraries
Source=FlyleafLib
StackTrace:
at FlyleafLib.Master.RegisterFFmpeg(String absolutePath, Int32 verbosity)
at FlyleafDownloadTest1.Program.

d__3.MoveNext() in C:\FlyleafDownloadTest1\Program.cs:line 24

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
DllNotFoundException: Unable to load DLL 'avformat.58 under C:\Program Files\ffmpeg-4.4-full_build\bin': The specified module could not be found.

I have tried to search such files and copy them to C:\Program Files\ffmpeg-4.4-full_build\bin, but this types of error seem never end.
This is what I can see inside the full build of FFMPEG:
C:\Users\John>ffmpeg -version
ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100

C:\Users\John>

From my understanding, the full build seem contain all necessary modules your repo needs, but maybe in different format.
Please check and let me know how I can proceed with my simple project.
Thanks,

Infinite Loop in Media Buffer

When I start Playing Udp stream video and After 5 minutes of streaming the App enter Infinite Loop in Media Buffer function that has been called in Screamer() function in this part

if (requiresBuffering)
                {
                    totalBytes = decoder.VideoDemuxer.TotalBytes + decoder.AudioDemuxer.TotalBytes + decoder.SubtitlesDemuxer.TotalBytes;
                    videoBytes = decoder.VideoDemuxer.VideoBytes + decoder.AudioDemuxer.VideoBytes + decoder.SubtitlesDemuxer.VideoBytes;
                    audioBytes = decoder.VideoDemuxer.AudioBytes + decoder.AudioDemuxer.AudioBytes + decoder.SubtitlesDemuxer.AudioBytes;

                    MediaBuffer();
                    requiresBuffering = false;
                    if (seeks.Count != 0) continue;
                    if (vFrame == null) { Log("MediaBuffer() no video frame"); break; }
                }

vFrame is null and no statement is true in this part

else
                {
                    if (!decoder.VideoDecoder.IsRunning && !isVideoSwitch) { Log("[SCREAMER] Video Exhausted"); shouldStop= true; }
                    if (vFrame != null && !gotAudio && (!decoder.AudioDecoder.IsRunning || decoder.AudioDecoder.Demuxer.Status == MediaFramework.MediaDemuxer.Status.QueueFull)) { 
                        Log("[SCREAMER] Audio Exhausted"); gotAudio  = true; }
                }

Can not start on VMware

Hi,

I am trying to run your application on VMware (Window Server 2016) but application can not start.
After debug, i found an error at: videoDevice1 = device.QueryInterface(); in Initialize() method in MediaRenderer.cs
Maybe the cause is dont have any monitor connected with that PC.
image

Seeking on Torrent Streaming crashes

Thread Abort on AVIO Contexts will make the decoder read invalid bytes and crashes the whole session (need to implement proper abort for decoder)

Technical question about audio sync

Hello.

First of all, thank you for your great project.

We are currently working on a video player project, and trying to use this project as a baseline.

I understand the video sync method with pts, but I don't understand how you synchronize audio with pts.

Can you explain how to sync audio?

The code block I don't understand is

if (decoder.hasAudio)
{
// Audio Sync
if (Math.Abs((audioDelayTicks - delayTicks) / 10000) > 220)
{
if (curTicks + audioExternalDelay < decoder.aStreamInfo.startTimeTicks || curTicks + audioExternalDelay > decoder.aStreamInfo.durationTicks)
audioDelayTicks = -10000000; // Force Resync Later (Audio Paused)
else if (ResynchAudio(curTicks - audioExternalDelay)) audioDelayTicks = delayTicks;
}
// Audio Frames [Callback]
if ( aFrames.Count > 0) SendAudioFrames();
}

Create a video player user control

Hi,

I want to play multi streams at same time so i am reading your sample to trying create a user control base on your frmControl.cs but not success.
Can you tell me the way to do this ?
If yes, can you add a method to get current frame (or save as jpeg file) from video/stream ?

Application can not start because there is an error at videoDevice1 = device.QueryInterface<VideoDevice1>()

Hi,

On some PCs, application will crash at:
videoDevice1 = device.QueryInterface();
videoContext1 = device.ImmediateContext.QueryInterface();
image

you can change to:
videoDevice1 = device.QueryInterfaceOrNull();
videoContext1 = device.ImmediateContext.QueryInterfaceOrNull();

and check:
if (videoDevice1 != null)
{
videoDevice1.CreateVideoProcessorEnumerator(ref vpcd, out vpe);
videoDevice1.CreateVideoProcessor(vpe, 0, out videoProcessor);
}

if (videoDevice1 != null)
videoDevice1.CreateVideoProcessorOutputView((Resource)textureRGB, vpe, vpovd, out vpov);

or only create videoDevice1 on HW Decoding mode.

Zoom/Pan

Hi
Does Flyleaf have an ability to Zoom/Pan on Video ?
If not, can I request that it be considered ?

Create VertexShader base on DirectX version

Hi,

I am testing your project on some PCs, application can not start if DirextX version is 10.0.
So, I modified like that in Initialize() and it worked:

string vertexProfile = "vs_5_0";
string pixelProfile = "ps_5_0";
if (device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_1 ||
device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_2 ||
device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_3 ||
device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_10_0 ||
device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_10_1)
{
vertexProfile = "vs_4_0_level_9_1";
pixelProfile = "ps_4_0_level_9_1";
}

            var VertexShaderByteCode = ShaderBytecode.Compile(Properties.Resources.VertexShader, "main", vertexProfile, ShaderFlags.Debug);

var PixelShaderByteCode = ShaderBytecode.Compile(Properties.Resources.PixelShader, "main", pixelProfile, ShaderFlags.Debug);
var PixelShaderByteCodeYUV = ShaderBytecode.Compile(Properties.Resources.PixelShader_YUV, "main", pixelProfile, ShaderFlags.Debug);

Can I use your repo to merge video files into one mp4 file?

Hello:
I have 2 video files, they are using the same video format (I can ignore the audio for now). They are like: C:\Videos\A.mp4, and C:\Videos\B.mp4.
I want to know if I can use your repo to merge the A.mp4 and B.mp4 to make a new video file, called: C:\Videos\Merge.mp4?
I think I can use FFMPEG command to do this, but as I have many of such files, like a few hundreds, so I want to have some program to make the process faster.
Please share some code samples, if possible.
Thanks,

Memory leak

Hi,

With 1 video: 3840x2160, 15 fps, duration 15 minute.
First time open this video: the memory consumption from 218 to 228 MB. After video finished, memory still 228 MB
Second time: memory increase from 228-> 239 MB,...
....

Master.cs: LoadPlugins failed

Hi,

I dont know why but if you paste code below in any where of WinForms Sample (Basic),
FlyleafLib can not initiate:
code:

    [StructLayout(LayoutKind.Explicit)]
    public struct UNION_DVR_DETAIL
    {
        [FieldOffset(0)]
        public STRUCT_DVR_PLATE dvrPlate;

        [FieldOffset(0)]
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
        public byte res;
    }

    [StructLayoutAttribute(LayoutKind.Sequential)]
    public struct STRUCT_DVR_PLATE
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string plate;

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 112)]
        public byte[] res;
    }

Error:
image

Seem there is an error here in LoadPlugins():

image

other recommend:
using Application.StartupPath instead of Environment.CurrentDirectory
baecause Environment.CurrentDirectory can change during execution.

image

How to extract all frames from a MP4 video file?

Hello:
I can’t find a C# code sample on how to extract all frames from one MP4 video file. (C:\Videos\1.mp4).
I want to extract all the frames from the MP4 video file and save them (in PNG format) in one local folder. (C:\VideoFrames).
Please advise!
My OS is Windows 10 (Version 21H1), IDE is Visual Studio 2019 (version 16.10.4)

Release memory and clear screen when video finished

Hi,

Issue:

  1. Start programe => memory ~ 32MB
  2. Play 4K video file => memory ~ 200 MB
  3. Video Finished: memory still ~ 200 MB and last frame still display

To test I am create a method Close() on MediaDecoder.cs and Stop() on MediaRouter.cs but when press a key to stop video, the memory only reduce at 144 MB.

How to release all memory when stop video or video finished and clear screen (black color) at the end ?

// MediaRouter.cs
public void Stop()
{
decoder.Close();

        Close();
    }

// MediaDecoder.cs
public void Close()
{
video?.Dispose();
video = null;
audio?.Dispose();
audio = null;
if (swsCtx != null)
{
sws_freeContext(swsCtx);
swsCtx = null;
}
if (vCodecCtx != null)
{
avcodec_close(vCodecCtx);
vCodecCtx = null;
}
if (aCodecCtx != null)
{
avcodec_close(aCodecCtx);
aCodecCtx = null;
}
}

How to use this repo to download m3u8 live stream URL and save to local hard drive?

Hello:
I happen to find your repo, and it seems to be interesting. However, as it is rather complicated,
I can’t figure out yet how to download multiple M3U8 videos and save to local hard drive.
For example, I have the following 2 M3U8 videos in the URL:
http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
I want to launch 2 clients to download them at the same time, when finished, I want to save the files as local files: C:\1.mp4 and C:\2.mp4 and stop or dispose the client.
Please show me how I can do this with C#.
By the way, I am using Windows 10 Version 21H1, and Visual Studio 2019 Version 16.10.4.
Thanks,

bug

default value of Decoder.MaxVideoFames
(Environment.ProcessorCount)
is less then MinVideoFrames

Reduce decoding and rendering frame rate for lower resource

Hi,

can i reduce decoding and rendering frame rate for lower CPU and GPU usage ?
ex: if frame rate of video source is 30 fps, im only need decode and display at 10, 15 fps, other frames will discard.
on my old PC (core i5 2400, AMD Radeon R7 200), for display rtsp stream from IP camera, it take ~50 % GPU:
image

Crash if start/stop continous

Hi,

I am test on WinForms Sample (Basic) by Add a button for player.Open(rtsp url) and a button on for player.Stop():
image
image

Presenting frames in the correct time

Hello, I would like to thank you for this awesome project, I've learned a lot from this!

I'm fairly new to FFmpeg programming, in the tutorial project, you are using Thread.Sleep() to simulate video FPS. However I still don't understand how did you manage to display/present each frame in the correct time?

I'm aware there's pts field in AVFrame. But I have very little idea on how to use this properly. So my current attempt is by utilizing StopWatch to present frame which is very ugly, CPU intensive and inaccurate.

// Wait until stopwatch reaches position
var position = frame.pts * av_q2d(stream.time_base) * 1000; // in ms
while (sw.ElapsedMilliseconds < position)
{
}

DisplayFrame();

Any assistance / explanation you can provide would be greatly appreciated!

How I can play video file from a certain starting time?

Hello:
I have one video file (C:\Videos\1.mp4), which has duration of 3 minutes. I want to start play the video from 1 minute, so the total play time will be 2 minute.
Let me know how I can use your repo to do this? I mean I skip the first 1 minute video in the mp4 file?
Thanks,

Can't play video with image attachments (ffmpeg recognizes them as video streams)

Format : Matroska
Format version : Version 4 / Version 2
File size : 1.68 GiB
Duration : 1 h 50 min
Overall bit rate : 2 191 kb/s
Writing application : mkvmerge v42.0.0 ('Overtime') 64-bit
Writing library : libebml v1.3.10 + libmatroska v1.5.2
Cover : Yes
Attachments : cover.jpg / small_cover.jpg / cover_land.jpg / small_cover_land.jpg

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : [email protected]
Format settings, CABAC : Yes
Format settings, RefFrames : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 1 h 50 min
Bit rate : 2 000 kb/s
Width : 1 920 pixels
Height : 800 pixels
Display aspect ratio : 2.40:1
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.054
Stream size : 1.53 GiB (91%)
Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

Audio
ID : 3
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : HE-AAC / LC
Codec ID : A_AAC
Duration : 1 h 50 min
Bit rate : 192 kb/s
Channel(s) : 6 channels
Channel positions : Front: L C R, Side: L R, LFE
Sampling rate : 48.0 kHz / 24.0 kHz
Frame rate : 23.438 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 151 MiB (9%)
Language : English
Default : No
Forced : No

Can’t play video file in WinForm App for Windows 10 using the repo.

I have done the following in order to use your repo in C# WinForm project (target .NET 5.0)
Download and unzip ffmpeg full build file from this URL:
https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z
Copy the unzipped folder to C:\Program Files
Edit System PATH variable to add ffmpeg binary path.
Also copy the lib (all the *.DLL), and change project file to use the following target item:
net5.0-windows
I have installed nuget packages:
PM> Install-Package FFmpeg.AutoGen -Version 4.4.0
PM> Install-Package NAudio.Wasapi -Version 2.0.0
PM> Install-Package SharpDX.Mathematics -Version 4.2.0
PM> Install-Package FlyleafLib -Version 3.1.14
PM> Install-Package FlyleafLib.Controls.WPF -Version 1.1.4
Then in Form1 designer, open toolbox, and drag one Flyleaf (Flyleaflib.controls) to the Form1 designer.
The following is the code from Form1.designer.cs:

namespace FlyleafPlayerForm
{
partial class Form1
{
///


/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

    /// <summary>
    ///  Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    ///  Required method for Designer support - do not modify
    ///  the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.flyleaf1 = new FlyleafLib.Controls.Flyleaf();
        this.SuspendLayout();
        // 
        // flyleaf1
        // 
        this.flyleaf1.BackColor = System.Drawing.Color.Black;
        this.flyleaf1.Location = new System.Drawing.Point(28, 12);
        this.flyleaf1.Name = "flyleaf1";
        this.flyleaf1.Size = new System.Drawing.Size(760, 465);
        this.flyleaf1.TabIndex = 0;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(800, 503);
        this.Controls.Add(this.flyleaf1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.ResumeLayout(false);

    }

    #endregion

    private FlyleafLib.Controls.Flyleaf flyleaf1;
}

}

The following is the C# code for Form1.cs:
using FlyleafLib;
using System;
using System.Windows.Forms;
using FlyleafLib.MediaPlayer;

namespace FlyleafPlayerForm
{
public partial class Form1 : Form
{
public const string FFMPEG_Binary = @"C:\Program Files\ffmpeg-4.4-full_build\bin";
public const string Video_File1 = @"C:\Videos\1.mp4";

    private static Player player1;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Master.RegisterFFmpeg(FFMPEG_Binary);
        Config config = new();
        config.demuxer.VideoFormatOpt.Add("probesize", (50 * (long)1024 * 1024).ToString());
        config.demuxer.VideoFormatOpt.Add("analyzeduration", (10 * (long)1000 * 1000).ToString());
        player1 = new Player(config)
        {
            Control = flyleaf1
        };
        player1.Open(Video_File1);
        player1.Play();
    }
}

}

I can compile my code, but when I run it, I saw only the black screen on the player, I can’t see any video file is being played.
Let me know if I made any mistake.
However, I can’t use WPF project, as there are many restrictions, one of which is difficult to use SQL server database, but I have to use SQL server database, as all the video file locations are stored in the database.
Please advise,
Thanks,

Can I add the FlyleafPlayer as a user control in a WinForms project?

Hello:
I found the latest version of Flyleaf release from this URL:
https://github.com/SuRGeoNix/Flyleaf/releases/download/v3.1.14/Flyleaf_v3.1.14.7z
I can download and unzip the compressed folder, and I can run FlyleafPlayer.exe (file version 1.0.0.0) and drag one video file and drop into it, so the player will play the video.
It looks well.
However, what I want is that I can insert such Player as a WinForms user control, and I can add one textbox, which I can input a local video file name, then and one button, which I can click on the button, so the Flyleaf Player user control can play the video file which is retrieved from textbox, as I can see from the FlyleafPlayer.exe interface, there are seeker control, I can use to play the video from anywhere I want.
But how I can add it as a user control to the Visual Studio Designer’s toolbox? (Visual Studio 2019)
Thanks,

Frame delay

Hi,

I am using your code to display live stream from IP camera (rtsp url). It's work fine but not realtime. Compare with VLC, your program delay about 1 -> 3 seconds.
How to avoid this ?

ảnh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.