VlcControl not streaming properly - c#

I'm using VlcDotNet to stream video and I faced a strange issue recently. When I stream video from my webcamera with VLC player I can perfectly watch it. But when I try to stream it using VlcControl I get an error that VLC couldn't connect to the source. I'm using the same options in VLC and VlcControl:
:sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ffmpeg{mux=flv},dst=:10177/} :sout-keep
Maybe I missing something, please look at my code:
if (Environment.Is64BitOperatingSystem)
{
VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;
}
else
{
VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86;
VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_X86;
}
//Set the startup options
VlcContext.StartupOptions.IgnoreConfig = true;
VlcContext.StartupOptions.LogOptions.LogInFile = true;
VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.None;
VlcContext.CloseAll();
VlcContext.Initialize();
VlcControl player = new VlcControl();
var media = new LocationMedia("dshow://");
media.AddOption(":sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ffmpeg{mux=flv},dst=:10177/} :sout-keep");
player.Media = media;
player.Play();
Console.WriteLine("Translation started...");
Console.ReadLine();

I think Vlc could not connect to your webcam because you didn't pass it the name of the camera
i tried it and i got
:dshow-vdev=USB2.0 Camera :dshow-adev= :live-caching=300
try at as another aption but make sure to change the camera name
PS. you can find this option, when you open Open Capture device --> tick the Show More Options
i think this will solve your problem :)

Related

Exception when playing wave with WaveOutEvent of NAudio

In my WPF application, I want to play mp3 and wave files with WaveOutEvent from NAudio. It works fine with mp3s, but I get a NullReferenceException in NAudio.Core "The object reference has not been set to an object instance." when I run it with a wave-file. The exception occures after the player was started with _player.Play();
Here is my code:
using (AudioFileReader afr = new AudioFileReader(_filename))
{
OffsetSampleProvider osp = new OffsetSampleProvider(afr);
osp.SkipOver = currentCursorPosition;
osp.Take = PlaybackDuration;
WaveOutEvent player = new WaveOutEvent();
player.Init(osp);
player.Play();
}
Exception.Source = NAudio.Core
Exception.StackTrace = bei NAudio.Wave.WaveFileReader.get_Position()
Modul is NAudio.Core.dll, version 2.01.0.0
Any idea what might be wrong and how to solve this?
Thanks in advance,
Frank
The Play method only begins playback. You're then disposing the AudioFileReader before it has finished playing the file.

C# Vlc Forms volume stabilization problem

I am using Vlc.DotNet.Forms package in my project. I open one video on form. Everything okay. But If I want to open a video again. When I change the volume, the volume of both videos changes.
My Code Example:
public VlcControl control;
public void Player(string url,int volume){
this.control = new VlcControl();
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
control.BeginInit();
control.VlcLibDirectory = libDirectory;
control.Dock = DockStyle.Fill;
control.EndInit();
this.Controls.Add(control);
control.SetMedia(new Uri(#"" + url + ""));
control.Audio.Volume=volume;
control.Play();
}
For example,
Player("C:\\test\video1.mp4",50);
Player("C:\\test\video2.mp4",75);
The first video opens and the volume becomes 50. Then when I open the second video, the volume of both videos is 75.
I use these packages
VideoLAN.LibVLC.Windows (Version 3.0.0) https://www.nuget.org/packages/VideoLAN.LibVLC.Windows
Vlc.DotNet.Forms (Version 3.0.0) https://github.com/ZeBobo5
It seems that the previous answer did not work for me, instead I used the following:
vlcControl.Play();
var directsound = vlcControl.Audio.Outputs.All.FirstOrDefault(x => x.Name == "directsound");
if (directsound != null)
{
vlcControl.Audio.Outputs.Current = directsound;
vlcControl.Audio.IsMute = true;
}
Setting the directsound just after having started the player.
You can then toggle mute with:
vlcControl.Audio.ToggleMute();
Setting the volume is similar with:
vlcControl.Audio.Volume = 50;
This seems to be a known issue of libvlc 3.x.
The workaround is to use a different audio output. In Vlc.DotNet, you can do so like this:
control.VlcMediaplayerOptions = new []{ "--aout=directsound" };
Before control.EndInit();.
References:
https://forum.videolan.org/viewtopic.php?t=147229
https://github.com/ZeBobo5/Vlc.DotNet/issues/524

Where to put media resource and start media player?

I want to play a song in a Xamarin app using the standard android media player.
I've got two questions that i haven't been able to answer myself:
Here do I put the media file (.mp3-file) or how do i link to the file (it's also saved on my SD-Card) I tried saving it in the raw-folder, but that doesn't seem to work
How do I correctly launch the player? Either my code doesn't work or the player doesn't find the file because it isn't stored correctly.
However, that's the method I use to prepare the media player:
protected MediaPlayer player;
public void StartPlayer() {
if (player == null) {
player = new MediaPlayer();
player.SetDataSource("Ressources.raw.test");
player.Prepare();
player.Start();
text = "Running";
} else {
player.Reset();
player.SetDataSource("Ressources.raw.test");
player.Prepare();
player.Start();
}
}
I tried saving it in the raw-folder, but that doesn't seem to work
You can't directly use string "Ressources.raw.test" as the DataSource. If you need play a song from Resource/Raw folder, here is two solutions.
Solution 1:
You could try using MediaPlayer.Create(Context context, int resid)
method:
Convenience method to create a MediaPlayer for a given resource id. On success, prepare() will already have been called and must not be called again.
Usageļ¼š
MediaPlayer player = MediaPlayer.Create(this, Resource.Raw.test);
player.Start();
Solution 2:
Convert your Resource/Raw/test path to Android.Net.Uri:
player = new MediaPlayer();
Android.Net.Uri uri = Android.Net.Uri.Parse("android.resource://" + PackageName + "/" + Resource.Raw.test);
player.SetDataSource(this, uri2);
player.Prepare();
player.Start();
how do I link to the file (it's also saved on my SD-Card)
Solution:
Try using SetDataSource (Context context, Uri uri) method, for example:
player = new MediaPlayer();
//My file path is Path == file:///storage/emulated/0/netease/cloudmusic/Music/love.MP3
var uri = Android.Net.Uri.Parse("file://" + Android.OS.Environment.ExternalStorageDirectory + "/netease/cloudmusic/Music/love.MP3");
player.SetDataSource(this, uri);
player.Prepare();
player.Start();

Control Widows Media Device Flash Light

I am trying to create a simple application which will have the functionality to switch on and off the flash light in a Windows Media Device.
I have initialized the camera as following:
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var rearCamera = devices.FirstOrDefault(item => item.EnclosureLocation != null &&
item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
if (rearCamera != null)
{
DeviceName.Content = rearCamera.Name;
FlashButton.Visibility = System.Windows.Visibility.Visible;
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = rearCamera.Id
});
LowLagPhotoCapture lowLagCaptureMgr = null;
// Image properties
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// Create LowLagPhotoCapture object
lowLagCaptureMgr = await mediaCapture.PrepareLowLagPhotoCaptureAsync(imgFormat);
}
And to switch on the flash I have written the following code:
var MyVideoDeviceController = mediaCapture.VideoDeviceController;
var MyTorch = MyVideoDeviceController.TorchControl;
var MyFlash = MyVideoDeviceController.FlashControl;
if (MyTorch.Supported)
{
MyTorch.PowerPercent = 100;
MyTorch.Enabled = true;
}
else
{
if (MyFlash.Supported)
{
MyFlash.PowerPercent = 100;
MyFlash.Enabled = true;
}
else
{
MessageBox.Show("No Flash and Torch Support", "Flash and Torch");
}
}
But seems both TorchControl and FlashControl are not supported in the code. I am not sure if am using the right APIs too. I am trying to run this on a Motion F5m - Tablet PC
Thanks in advance
The TorchControl is used for constant video light, so if you're taking a photograph, it's not the most appropriate control to use. One reason is that on many devices, video light will be dimmer than a photo flash, but especially because on some devices, the torch will only turn on while a video recording is in progress. Depending on the capabilities of the device, this may interfere with the ability to take photos.
You have the right idea setting MyFlash.Enabled = true, but just to be safe, I would also set MyFlash.Auto = false, so that the flash will fire each time, and not only when it's dark.
The CameraManualControls sample on the Microsoft GitHub repository shows you how to use the Flash and Torch controls, and many more. It targets Windows 10, though, so if you're on 8.1 you'll have to adapt the code or upgrade your tablet.
Now, all of the above is assuming that the device you're running your app on has flash support in the first place. When you say that the controls are not supported, that means that the camera driver on the device is not advertising the capability to Windows. I assume that the built-in Microsoft Camera app doesn't allow you to use the flash either?
I see the manufacturer of your tablet lists an "Illuminator Light" on their camera specs list, but there is a chance that the only way to control it is through their proprietary application. In that case you'd have to reach out to them for support.

Can't open a mpg-File for capture using EmguCV with C#

I'm trying to open a mpg-File using emguCV. I use the following code:
if (instance == null)
{
lock (m_lock)
{
try
{
instance = new Capture(0); // capture from camera works fine if a camera is connected
}
catch (NullReferenceException)
{
String sFileName = #"C:\tmp\MarkerMovie.mpg";
try
{
if (File.Exists(sFileName))
{
instance = new Capture(sFileName); // here the exception is thrown
}
else
{
MessageBox.Show("No Camera and no Video-File found");
}
}
catch (NullReferenceException)
{
MessageBox.Show("Couldn't open Video: "+sFileName);
}
}
}
}
If a webcam is connected everything works fine, but when I unplug the webcam the line instance = new Capture(sFileName); throws a NullReferenceException:
Message = "Unable to create capture from C:\tmp\MarkerMovie.mpg"
I debugged and found the reason is in the constructor of capture. The following command always returns a Null-Pointer:
_ptr = CvInvoke.cvCreateFileCapture(fileName);
I could open the same video using C++ using this code:
cap = cvCaptureFromFile("C:\\tmp\\MarkerMovie.mpg");
I'm new to openCV, so I'm not sure which information you need to help me. I installed emguCV yesterday from http://sourceforge.net/projects/emgucv/ on a Windows XP computer. The installer-version is x86_2.3.0.1416. I included opencv_core231.dll, opencv_highgui231.dll and opencv_imgproc231.dll to my project.
Does somebody know how I can make this code working?
Let me know if you need more information.
Thanks.
I had the same problem and adding the opencv_ffmpeg.dll to the project seems to solve it. (Found in the bin directory in the Emgu CV directory) I have tried it on the project that you posted and it seems to be working too. Hope it helps.
With EmguCV in C#, you need to put the opencv_ffmpeg.dll, for example: opencv_ffmpeg2410.dll, be careful if you have x86 or 64 bits

Categories

Resources