inconsistent thumbnail with ffmpeg on avi, mp4 - c#

i am getting inconsistent thumbanails when i add a new video. i have video files with width and height 640x480 and 1280x720. what do i have to change?
public void exec(string input, string output, string parametri)
{
ffmpeg = new Process();
ffmpeg.StartInfo.Arguments = " -i " + input + (parametri != null ? " " + parametri : "") + " " + output;
ffmpeg.StartInfo.FileName = "ffmpeg.exe";
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.RedirectStandardError = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.Start();
ffmpeg.WaitForExit();
ffmpeg.Close();
}
public void GetThumbnail(string video, string jpg, string velicina)
{
if (velicina == null) velicina = "640x480";
exec(video, jpg, "-s " + velicina);
}
private void btnBrowseThumbnail_Click(object sender, EventArgs e)
{
string newThumbnail = Properties.Settings.Default.folderPathUserThumbnail + "CopyFiles.jpg";
GetThumbnail(txtFile.Text, newThumbnail, null);
string curFile = newThumbnail;
if (File.Exists(curFile))
txtThumbnail.Text = newThumbnail;
}

Related

Code after Process.Start() call not running, but working when debugging C#

Here is the function that is calling Process.Start().
I am simply opening two folders in WinMerge. This part works correctly and this application pops up. None of the code written after this runs though. However, when I place a breakpoint on p.Dispose() or p.Start() and press continue, everything afterwards works correctly.
private void openWinMerge(string leftFile, string rightFile)
{
string args = "/C /f *.xml " + leftFile + " " + rightFile;
Process p = new Process();
p.StartInfo.FileName = "C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe";
p.StartInfo.Arguments = args;
p.StartInfo.CreateNoWindow = true;
if (p.Start())
{
p.Dispose();
return;
}
}
This is where I call the function calling Process.Start(). None of the code below openWinMerge() runs.
private void btnStart_Click(object sender, EventArgs e)
{
if (txtSerial.Text.Length == 9)
{
PO.Number = txtSerial.Text.ToUpper();
PO.SerialSearch = true;
if (PO.Search())
{
txtPO.Text = PO.Field.ProductionOrderNumber;
search();
createFolders();
copyDefaultFiles();
copyBackupFiles();
openWinMerge("\"" + Path.Combine(path, "INITIAL") + "\"", "\"" + Path.Combine(path, "Default") + "\"");
copyFinalXML();
return;
}
MessageBox.Show("Invalid Serial");
} else if (txtPO.Text.Length == 12)
{
PO.Number = txtPO.Text.ToUpper();
if (PO.Search())
{
txtSerial.Text = PO.Field.SerialNumber;
search();
createFolders();
copyDefaultFiles();
copyBackupFiles();
openWinMerge("\"" + Path.Combine(path, "INITIAL") + "\"", "\"" + Path.Combine(path, "Default") + "\"");
copyFinalXML();
return;
}
MessageBox.Show("Invalid PO or Missing Serial");
} else
{
MessageBox.Show("Please Enter either Serial or PO of Analyzer");
}
}
Update:
I wrote some other code below openWinMerge() and it runs, so my issue is in copyFinalXML()
Here is the code for that
private void copyFinalXML()
{
try
{
string[] files = Directory.GetFiles(Path.Combine(path,"INITIAL"));
Task.Delay(200);
foreach (string file in files)
{
// Will not overwrite if the destination file already exists.
string[] folders = file.Split('\\');
string filename = folders[folders.Length - 1];
if (filename.Equals("config.xml") || filename.Equals("service.xml") || filename.Equals("system.xml"))
{
string d = Path.Combine(Path.Combine(path, "FINAL"), filename);
File.Copy(file, d);
Task.Delay(500);
openNotePad(d);
}
}
}
// Catch exception if the file was already copied.
catch (IOException copyError)
{
MessageBox.Show(copyError.Message);
}
}
private void openNotePad(string filename)
{
//Process.Start("C:\\Program Files(x86)\\Notepad++\\notepad++.exe", "\"" + filename + "\"");
Process.Start(#"notepad++.exe", "\"" + filename + "\"");
return;
}
Add p.WaitForExit(); to your code just before the code you want to execute after it finishes running the process.

C# Starting process with args in specific folder

I am trying to decompile over 30k vulkan shader files using shaderc from google.
All shaders are located in "C:\Users\Admin\Desktop\NMS MOD\SHADER MOD\v2.41\PC"
The tool used to decompile is spirv-cross.exe which I added to Windows Environment variables, which lets me run this simple bat file inside the shaders folder and works fine.
"spirv-cross --version 450 --vulkan-semantics --stage frag ATMOSPHERE_FRAG_CLOUD_769.SPV > ATMOSPHERE_FRAG_CLOUD_769.GLSL"
Since there is way too many to do this manually. I want to make a simple App to do this process and also get the stage type from file name (in this case "frag").
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace Lazy_Me_3
{
public partial class Form1 : Form
{
public string PATH;
public string[] sFilesNames;
public int totalcount = 0;
public int currentcount = 0;
public Form1()
{
InitializeComponent();
}
private string GetStageType(string filename)
{
// Valid Stages = vertex, vert, fragment, frag, tesscontrol, tesc, tesseval, tese, geometry, geom, compute, comp
if (filename.Contains("_VERTEX_") || filename.Contains("_VERT_")) return "vert";
if (filename.Contains("_FRAGMENT_") || filename.Contains("_FRAG_")) return "frag";
if (filename.Contains("_TESSCONTROL_") || filename.Contains("_TESC_")) return "tesc";
if (filename.Contains("_TESSEVEL_") || filename.Contains("_TESE_")) return "tese";
if (filename.Contains("_GEOMETRY_") || filename.Contains("_GEOM_")) return "geom";
if (filename.Contains("_COMPUTE_") || filename.Contains("_COMP_")) return "comp";
else return "error";
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < sFilesNames.Count(); i++)
{
sFilesNames[i] = Path.GetFileName(sFilesNames[i]);
if (sFilesNames[i].Length > 1)
{
var newName = sFilesNames[i].Substring(0, sFilesNames[i].Length - 4);
sFilesNames[i] = newName;
}
}
foreach (var file in sFilesNames)
{
string stageType = GetStageType(file);
if (stageType != "error")
{
string args = "--version 450 --vulkan-semantics --stage " + stageType + " " + file + ".SPV" + " > " + file + ".GLSL";
Process process = new Process();
process.StartInfo.FileName = "spirv-cross";
process.StartInfo.Arguments = args;
process.StartInfo.WorkingDirectory = PATH;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit(5000);
currentcount += 1;
label1.Text = "Status : " + currentcount.ToString() + " / " + totalcount.ToString();
}
else MessageBox.Show("Error on finding stage type of file : " + file);
}
}
private void button2_Click(object sender, EventArgs e)
{
using (var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
sFilesNames = Directory.GetFiles(fbd.SelectedPath, "*.SPV");
totalcount = sFilesNames.Length;
PATH = fbd.SelectedPath;
label3.Text = "Directory : " + PATH;
label2.Text = "Total Count : " + totalcount.ToString();
label1.Text = "Status : 0 / " + totalcount.ToString();
button1.Enabled = true;
}
}
}
}
}
EDIT 1 : Bodge using cmd that works
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < sFilesNames.Count(); i++)
{
//sFilesNames[i] = Path.GetFileName(sFilesNames[i]);
if (sFilesNames[i].Length > 1)
{
var newName = sFilesNames[i].Substring(0, sFilesNames[i].Length - 4);
sFilesNames[i] = newName;
}
}
foreach (var file in sFilesNames)
{
string stageType = GetStageType(file);
if (stageType != "error")
{
var p = new ProcessStartInfo("cmd", #"/c spirv-cross --version 450 --vulkan-semantics --stage " + stageType + " " + file + ".SPV" + " > " + file + ".GLSL");
p.UseShellExecute = false;
p.CreateNoWindow = true;
var ps = Process.Start(p);
ps.WaitForExit();
currentcount += 1;
label1.Text = "Status : " + currentcount.ToString() + " / " + totalcount.ToString();
}
else
{
errorcount += 1;
label4.Text = "Errors : " + errorcount.ToString();
}
}
}

Connect to VPN xamarin android

Hello I am using this code to connect vpn with c# my code can connect and disconnect and create vpn and it working fine but i want use it in xamarin android i do search google but No result
private static string FolderPath => string.Concat(Directory.GetCurrentDirectory(),
"\\VPN");
private void btnConnect_Click(object sender, EventArgs e)
{
if (!Directory.Exists(FolderPath))
Directory.CreateDirectory(FolderPath);
var sb = new StringBuilder();
sb.AppendLine("[VPN]");
sb.AppendLine("MEDIA=rastapi");
sb.AppendLine("Port=VPN2-0");
sb.AppendLine("Device=WAN Miniport (IKEv2)");
sb.AppendLine("DEVICE=vpn");
sb.AppendLine("PhoneNumber=" + txtHost.Text);
File.WriteAllText(FolderPath + "\\VpnConnection.pbk", sb.ToString());
sb = new StringBuilder();
sb.AppendLine("rasdial \"VPN\" " + txtUsrname.Text + " " + txtPassword.Text + " /phonebook:\"" + FolderPath +
"\\VpnConnection.pbk\"");
File.WriteAllText(FolderPath + "\\VpnConnection.bat", sb.ToString());
var newProcess = new Process
{
StartInfo =
{
FileName = FolderPath + "\\VpnConnection.bat",
WindowStyle = ProcessWindowStyle.Normal
}
};
newProcess.Start();
newProcess.WaitForExit();
btnConnect.Enabled = false;
btnDisconnect.Enabled = true;
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
File.WriteAllText(FolderPath + "\\VpnDisconnect.bat", "rasdial /d");
var newProcess = new Process
{
StartInfo =
{
FileName = FolderPath + "\\VpnDisconnect.bat",
WindowStyle = ProcessWindowStyle.Normal
}
};
newProcess.Start();
newProcess.WaitForExit();
btnConnect.Enabled = true;
btnDisconnect.Enabled = false;
}
or I want convert it to xamarin android and
connect or disconnect sorry for my english

Expected behaviour with white space in the command line

I wrote a program that compiles my .cs files using csc.exe:
namespace myCompiler
{
public partial class Form1 : Form
{
string compilerFolder;
string outputFolder;
string projectFile;
string output = #" /out:";
public Form1()
{
InitializeComponent();
}
private void startCompile_Click(object sender, EventArgs e)
{
Compile();
}
public void findCompile_Click(object sender, EventArgs e)
{
DialogResult result1 = folderBrowserDialog1.ShowDialog();
compilerFolder = folderBrowserDialog1.SelectedPath;
MessageBox.Show(compilerFolder);
cscLabel.Text = compilerFolder;
}
private void outputCompile_Click(object sender, EventArgs e)
{
DialogResult result2 = folderBrowserDialog2.ShowDialog();
outputFolder = folderBrowserDialog2.SelectedPath;
outputLabel.Text = (outputFolder);
MessageBox.Show(outputFolder);
}
private void findProject_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
projectFile = openFileDialog1.FileName;
projectLabel.Text = (projectFile);
MessageBox.Show(projectFile);
}
}
public void Compile()
{
try
{
Process compile = new Process();
string outputExe = fileName.Text;
string compiler = compilerFolder + #"\csc.exe";
string arGs = output + outputFolder + #"\" + outputExe + " " + projectFile;
compile.StartInfo.FileName = (compiler);
compile.StartInfo.Arguments = (arGs);
compile.StartInfo.RedirectStandardOutput = true;
compile.StartInfo.UseShellExecute = false;
compile.Start();
string stdOutput = "";
while (!compile.HasExited)
{
stdOutput += compile.StandardOutput.ReadToEnd();
MessageBox.Show(stdOutput);
}
}
catch (Exception errorMsg)
{
MessageBox.Show(errorMsg.Message);
}
}
private void testButton_Click(object sender, EventArgs e)
{
MessageBox.Show(projectFile);
MessageBox.Show(compilerFolder);
}
}
}
The compile instruction runs but produces no results, just a quick flash of a black console screen.
Basically what seems to be happening, is when all the strings are parsed in the commandline as arguments for the process, the .cs project source directory is broken up by each white space ie c:\users\%username%\Documents\Visual Studio 2010\ is broken up as c:\users\%username%\Documents\Visual then Studio then 2010\Projects\Myproject\myproj.cs
and subsequently the compilation fails.
You need double quotes around a filepath with spaces in it.
See my edit to your code below.
public void Compile()
{
try
{
Process compile = new Process();
string outputExe = fileName.Text;
string compiler = compilerFolder + "\csc.exe";
// add double quotes around path with spaces in it.
string arGs = output + "\"" + outputFolder + "\"" + #"\" + outputExe + " " + projectFile;
compile.StartInfo.FileName = compiler;
compile.StartInfo.Arguments = arGs;
compile.StartInfo.RedirectStandardOutput = true;
compile.StartInfo.UseShellExecute = false;
compile.Start();
string stdOutput = "";
while (!compile.HasExited)
{
stdOutput += compile.StandardOutput.ReadToEnd();
MessageBox.Show(stdOutput);
}
}
catch (Exception errorMsg)
{
MessageBox.Show(errorMsg.Message);
}
}

convert all video files to flv using asp.net with c# by using ffmpeg.exe

This is my code below . Its not working to take image from the given video and not converting any kind of video to flv format.Its converting but after converting that flv and thumb images files is not save in the temp(store images) data(store convert flv)folder.That folder is empty.
i am debugging code but it is not giving any kind of exception and error.
Kindly debug my code.Awaiting for ur reply experts...
in Default2.aspx page
a file upload control and save button is there.
Default2.aspx.cs page
protected void Page_Load(object sender, EventArgs e)
{
string ffmpegPath = "";
string tempLocation = "";
string mediaOutPath = "";
string thumbOutPath = "";
string currentFile = "";
ffmpegPath = Server.MapPath("~/ffmpeg/ffmpeg.exe");
tempLocation = Server.MapPath("~/VideoGallery/temp/");
mediaOutPath = Server.MapPath("~/VideoGallery/data/");
thumbOutPath = Server.MapPath("~/VideoGallery/thumb/");
}
protected void Submit1_ServerClick(object sender, System.EventArgs e)
{
if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
{
currentFile = System.IO.Path.GetFileName(File1.PostedFile.FileName);
try
{
Convert(tempLocation + currentFile, mediaOutPath + currentFile, thumbOutPath +
currentFile);
File1.PostedFile.SaveAs(tempLocation + currentFile);
Response.Write("The file has been uploaded.");
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
protected void Convert(string fileIn, string fileOut, string thumbOut)
{
try
{
//convert flv
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = ffmpegPath;
proc.StartInfo.Arguments = "-i " + fileIn +
" -ar 22050 -ab 32 -f flv -s 320×240 -aspect 4:3 -y " + fileOut.Split('.')[0] +
".flv";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.WaitForExit();
//convert img
proc.StartInfo.Arguments = "-i " + fileIn +
" -an -ss 00:00:03 -s 120×90 -vframes 1 -f mjpeg " + thumbOut.Split('.')[0] +
".jpg";
proc.Start();
proc.WaitForExit();
proc.Close();
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
}

Categories

Resources