I try to display RTSP stream using Gstreamer in my WPF application.
So I did so far:
installed GStreamer into loal folder F:/gstreamer
Created new WPF application
Added glib-sharp and gstreamer-sharp as dependencies.
The code below I use to init the library:
Gst.Application.Init(); // (1)
mainLoop = new GLib.MainLoop();
mainGLibThread = new System.Threading.Thread(mainLoop.Run);
mainGLibThread.Start();
Element uriDecodeBin = ElementFactory.Make("playbin", "uriDecodeBin0"); // (2)
Unable to load DLL 'libgstreamer-1.0-0.dll': The specified module could not be found.
on line (1). If I copy all the gstreamer dlls into bin/Debug folder the exception gone but ElementFactory.Make in line (2) always returns null without any exception. If I try to do something like
Parse.Launch(#"videotestsrc ! videoconvert ! autovideosink")
to test the library functionality I get error:
no element "videotestsrc"
but if I run it from command line:
gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink
that works as expected.
So my question - how to get GStreamer-sharp work?
Change path to GStream and add this code before start
string path = #"G:\gstreamer\1.0\x86\"; // path to your gstream
string pluginpath = #"G:\gstreamer\1.0\x86\lib\gstreamer-1.0\"; // path to your gstream
string registry = System.IO.Path.Combine(path, "registry.bin");
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + path);
Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", pluginpath + ";" + Environment.GetEnvironmentVariable("GST_PLUGIN_PATH"));
Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH_1_0", pluginpath + ";" + Environment.GetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH_1_0"));
Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH", pluginpath + ";" + Environment.GetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH"));
Environment.SetEnvironmentVariable("GST_DEBUG", "*:4");
Environment.SetEnvironmentVariable("GST_DEBUG_FILE", System.IO.Path.Combine(path, "gstreamer.log"));
Environment.SetEnvironmentVariable("GST_REGISTRY", registry);
Related
I have a problem here and i need some help.
I work on a C# software in WPF, i have finished it, the program compile but do not run.
I've tried to search the problem using step by step run and it end on this line
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = Application.StartupPath + #"\Logs\" + DateTime.Now.DayOfYear + ".txt" };
and
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
and i got this error : " Attempt to read or write protected memory. This often indicates that another memory is corrupted "
that happen randomly during execution but mostly while running theses lines of code.
If you got a solution i'll take it !
The WPF Application class does not have a StartupPath property.
You could add System.Windows.Forms as project reference and use System.Windows.Forms.Application.StartupPath
Alternative:
string appPath = System.Reflection.Assembly.GetExecutingAssembly()
.GetModules()[0].FullyQualifiedName;
string appDir = Path.GetDirectoryName(appPath);
To debug your code with finer granularity, you could rewrite it:
var fileName = Application.StartupPath;
fileName += #"\Logs\";
fileName += DateTime.Now.DayOfYear
fileName += ".txt";
var logfile = new NLog.Targets.FileTarget("logfile");
logFile.FileName = fileName;
I am getting below error:
"could not find a part of the path"
This is happening only when I ran published web API. But the same code is working fine.
Below is that code:
string fileName = string.Format(#"C:\\Reports\\AttendanceReport " + start.ToString("d") + " To " + end.ToString("d") + ".xlsx");
FileInfo excelFile = new FileInfo(fileName.ToString());
excel.SaveAs(excelFile);
*file is created if I running code locally. But not working for published code.
In C# i got a random Win32Exception. I am a high experiened programmer with C# but this is random! The file "quickbms.exe" does exist!
When i did this:
commandPrompt.StartInfo.FileName = "start";
commandPrompt.StartInfo.Arguments = "\"" + Application.ExecutablePath + "\\src\\quickbms.exe\" -o \"src\\overworld.bms\" \"savegame_d.dat\" \"src\\xbla\\Savegame_Files\\regions\"";
commandPrompt.Start();
commandPrompt.WaitForExit();
(commandPrompt = System.Diagnostics.Process)
and this happened (Customized Exception Window used):
http://gyazo.com/9ebe6832f6200669d20c0c4e96e95a9c
A lot of you will say "The file don't exist" BUT IT DOES!
http://gyazo.com/a976d29109775512695c4bcc177ef5ad
The problem is your "start" argument.
commandPrompt.StartInfo.FileName = "start";
There is no windows-command named start. Win+R + "start" = error
You will get the exact same error if you remove the Arguments row.
You should call the file directly in Filename not inte the argument.
commandPrompt.StartInfo.FileName = "\"" + Application.ExecutablePath + "\\src\\quickbms.exe\";
commandPrompt.StartInfo.Arguments = "-o \"src\\overworld.bms\" \"savegame_d.dat\" \"src\\xbla\\Savegame_Files\\regions\"";
commandPrompt.Start();
commandPrompt.WaitForExit();
The odd thing is that something like System.IO.File.Delete() works
and the file gets deleted but will give "access to path is denied error" for .Move() operation.
All files are located in the same folder, user "Network service" has all
full control rights for the folder and all subfolders in it etc.
Folders are located in the project directory and can be seen in solution explorer.
Exception Details: System.UnauthorizedAccessException: Access to the path is denied.
foreach(var info in FileActions.Where(x => x.OldSortOrder != x.SortOrder))
{
string FileToRename;
string NewName;
string OldFilePath;
string OldFileThumbPath;
FileToRename = info.ProductID + "/" + info.OldSortOrder + "-" + info.ImageID + ".jpg";
NewName = info.SortOrder + "-" + info.ImageID + ".jpg";
OldFilePath = System.Web.HttpContext.Current.Request.MapPath("~/Content/ProductImages/" + FileToRename);
OldFileThumbPath = System.Web.HttpContext.Current.Request.MapPath("~/Content/ProductImages/" + info.ProductID + "/thumbs/" + FileToRename);
System.IO.File.Move(OldFilePath, NewName);
System.IO.File.Move(OldFileThumbPath, NewName);
}
Its because you map the path for the first files but not for the NewName.
So did not have the full path to know what to rename/move the file, and needs the full path to work correctly.
With out the path this is probably try to move it on the default folder of the asp.net pool that is probably don't have this permissions.
So the code will be
NewName = System.Web.HttpContext.Current.Request.MapPath("~/Content/ProductImages/"
+ info.SortOrder + "-" + info.ImageID + ".jpg" );
and debug this lines to see if the directories and files are all correct.
I have a return a c# code to save a file in the server folder and to retrieve the saved file from the location. But this code is working fine in local machine. But after hosting the application in IIS, I can save the file in the desired location. But I can't retrieve the file from that location using
Process.Start
What would be the problem? I have searched in google and i came to know it may be due to access rights. But I don't know what would be exact problem and how to solve this? Any one please help me about how to solve this problem?
To Save the file:
string hfBrowsePath = fuplGridDocs.PostedFile.FileName;
if (hfBrowsePath != string.Empty)
{
string destfile = string.Empty;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\\\";
if (!Directory.Exists(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)))
Directory.CreateDirectory(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1));
FileInfo FP = new FileInfo(hfBrowsePath);
if (hfFileNameAutoGen.Value != string.Empty)
{
string[] folderfiles = Directory.GetFiles(FilePath);
foreach (string fi in folderfiles)
File.Delete(fi);
//File.Delete(FilePath + hfFileNameAutoGen.Value);
}
hfFileNameAutoGen.Value = PONumber + FP.Extension;
destfile = FilePath + hfFileNameAutoGen.Value;
//File.Copy(hfBrowsePath, destfile, true);
fuplGridDocs.PostedFile.SaveAs(destfile);
}
To retrieve the file:
String filename = lnkFileName.Text;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\";
FileInfo fileToDownload = new FileInfo(FilePath + "\\" + filename);
if (fileToDownload.Exists)
Process.Start(fileToDownload.FullName);
It looks like folder security issue. The folder in which you are storing the files, Users group must have Modify access. Basically there is user(not sure but it is IIS_WPG) under which IIS Process run, that user belongs to Users group, this user must have Modify access on the folder where you are doing read writes.
Suggestions
Use Path.Combine to create folder or file path.
You can use String.Format to create strings.
Create local variables if you have same expression repeating itself like FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)
Hope this works for you.
You may have to give permissions to the application pool that you are running. see this link http://learn.iis.net/page.aspx/624/application-pool-identities/
You can also use one of the built-in account's "LocalSystem" as application pool identity but it has some security issue's.