I have done everything how is in this question. everything is alright except one. I can't save the taken snapshot. If I'll follow with debug everything is alright.. what's wrong?
public class FFMPEG
{
Process ffmpeg;
public void exec(string input, string parametri, string output)
{
ffmpeg = new Process();
ffmpeg.StartInfo.Arguments = " -i " + input + (parametri != null ? " " + parametri : "") + " " + output;
ffmpeg.StartInfo.FileName = HttpContext.Current.Server.MapPath("~/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, "-ss 00:00:06 " + velicina, jpg);
}
}
FFMPEG f = new FFMPEG();
f.GetThumbnail(Server.MapPath("~/Uploads/" + unique), Server.MapPath("~/Thumbnails/" + unique.Remove(unique.IndexOf(".")) + ".jpg"), "1200x223");
I assume you are extracting 640x480 thumbnails, and velicina is the parameter used to specify the resolution judging by the partial code you posted. In this case, you have a ffmpeg syntax error and you can change GetThumbnail function as belowing for a try:
public void GetThumbnail(string video, string jpg, string velicina)
{
if (velicina == null) velicina = "640x480";
exec(video, "-ss 00:00:06 -s" + velicina, jpg);
}
Specially, -s tells ffmpeg the resolution for the output. Try whether it works out.
Related
I have two video files, which I want to play side by side and download them later. I used FFMPEG to merge them as one:
protected void combinetwovideo()
{
string strParam;
string Path_FFMPEG = Path.Combine(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["FFMpegPath"]));
string apppath=HttpRuntime.AppDomainAppPath;
//Merging two videos
String video1=apppath+"\\recordings\\client2019-08-03 02_23_59";
String video2 =apppath+"\\userrecord\\User2019-08-03 02_24_00";
String strResult =apppath+"\\RESULT\\";
strParam = string.Format("-i ('" + video1 + "') -i ('" + video2 + "') -filter_complex \'[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' /-map [vid] -c:v libx264 -crf 23 -preset veryfast output.mp4");
process(Path_FFMPEG, strParam);
}
public void process(string Path_FFMPEG, string strParam)
{
try
{
Process ffmpeg = new Process();
ProcessStartInfo ffmpeg_StartInfo = new ProcessStartInfo(Path_FFMPEG, strParam);
ffmpeg_StartInfo.UseShellExecute = false;
ffmpeg_StartInfo.RedirectStandardError = true;
ffmpeg_StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo = ffmpeg_StartInfo;
ffmpeg_StartInfo.CreateNoWindow = true;
ffmpeg.EnableRaisingEvents = true;
ffmpeg.Start();
ffmpeg.WaitForExit();
ffmpeg.Close();
ffmpeg.Dispose();
ffmpeg = null;
}
catch (Exception ex)
{
}
}
But this method outputs nothing and does not throw any errors. I'm confused about the strParam query. Did I write it wrong or am I missing something. Any help would be apreciated.
This problem concerns a thermal receipt printer. I have downloaded C# EPSON OPOS receipt printing examples in attempt to implement such a printer in my current project, all is working well but when I print a bitmap logo, successive text is being printed under it, and I need to print some text to the right side of it. Here is an approximation of what it does now:
This is what I need it to do:
My current code, pretty much as-is from EPSON's samples:
private void btnReceipt_Click(object sender, System.EventArgs e)
{
//<<<step8>>>--Start
//Initialization
DateTime nowDate = DateTime.Now; //System date
DateTimeFormatInfo dateFormat = new DateTimeFormatInfo(); //Date Format
dateFormat.MonthDayPattern = "MMMM";
string strDate = nowDate.ToString("MMMM,dd,yyyy HH:mm",dateFormat);
int iRecLineSpacing;
int iRecLineHeight;
bool bBuffering = true;
bool bBitmapPrint = false;
int iPrintRotation = 0;
string strCurDir = Directory.GetCurrentDirectory();
string strFilePath = strCurDir.Substring(0,
strCurDir.LastIndexOf("Step8") + "Step8\\".Length);
strFilePath += "bitmap_logo.bmp";
Cursor.Current = Cursors.WaitCursor;
Rotation[] arBitmapRotationList = m_Printer.RecBitmapRotationList;
Rotation[] arBarcodeRotationList = m_Printer.RecBarCodeRotationList;
//Check rotate bitmap
for (int i = 0; i < arBitmapRotationList.Length; i++)
{
if (arBitmapRotationList[i].Equals(Rotation.Left90))
{
bBitmapPrint = true;
iPrintRotation = (iPrintRotation | (int)PrintRotation.Left90)
| ((int)PrintRotation.Bitmap);
}
}
iRecLineSpacing = m_Printer.RecLineSpacing;
iRecLineHeight = m_Printer.RecLineHeight;
if (m_Printer.CapRecPresent == true)
{
try
{
m_Printer.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Transaction);
m_Printer.RotatePrint(PrinterStation.Receipt, (PrintRotation)iPrintRotation);
if (bBitmapPrint == true)
{
m_Printer.PrintBitmap(PrinterStation.Receipt, strFilePath, m_Printer.RecLineWidth, PosPrinter.PrinterBitmapCenter);
}
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|4C" + "\u001b|bC" + " Receipt ");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|3C" + "\u001b|2uC" + " Mr. Brawn\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|2uC" + " \n\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|2uC" + "\u001b|3C" + " Total payment $" +"\u001b|4C" + "21.00 \n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|1C\n" );
m_Printer.PrintNormal(PrinterStation.Receipt,strDate + " Received\n\n");
m_Printer.RecLineHeight = 24;
m_Printer.RecLineSpacing = m_Printer.RecLineHeight;
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|uC" + " Details \n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|1C" + " " + "\u001b|2C" + "OPOS Store\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|uC" + " Tax excluded $20.00\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|1C" + " " + "\u001b|bC" + "Zip code 999-9999\n");
m_Printer.PrintNormal(PrinterStation.Receipt,"\u001b|uC" + " Tax(5%) $1.00" + "\u001b|N" + " Phone#(9999)99-9998\n");
}
catch(PosControlException ex)
{
if(ex.ErrorCode == ErrorCode.Illegal && ex.ErrorCodeExtended == 1004)
{
MessageBox.Show("Unable to print receipt.\n", "Printer_SampleStep8", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// Clear the buffered data since the buffer retains print data when an error occurs during printing.
m_Printer.ClearOutput();
bBuffering = false;
}
}
try
{
m_Printer.RotatePrint(PrinterStation.Receipt, PrintRotation.Normal);
if(bBuffering == true)
{
m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|fP");
}
m_Printer.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal);
}
catch(PosControlException)
{
// Clear the buffered data since the buffer retains print data when an error occurs during printing.
m_Printer.ClearOutput();
}
}
m_Printer.RecLineSpacing = iRecLineSpacing;
m_Printer.RecLineHeight = iRecLineHeight;
Cursor.Current = Cursors.Default;
//<<<step8>>>--End
}
If there is a method to do absolute text positioning or being able to write to the same line where the bitmap is, it would solve my issue. Any directions appreciated!
Please ask EPSON whether you can print with the layout you want with one set of RotatePrint.
As an alternative, consider dividing it into two sets of RotatePrint.
If you first set of RotatePrint with Bitmap and "Some other text", and the second set of RotatePrint with "Sample text 1" to "Sample text 3", it will be close to the layout you want.
In addition:
Epson OPOS seems to support PageMode, so can you print it?
As for explanation of Japanese, please look through google translation etc.
I have a strange requirement. User can upload their video of any format (or a limited format). We have to store them and convert them to .mp4 format so we can play that in our site.
Same requirement also for audio files.
I have googled but I can't get any proper idea. Any help or suggestions....??
Thanks in advance
You can convert almost any video/audio user files to mp4/mp3 with FFMpeg command line utility. From .NET it can be called using wrapper library like Video Converter for .NET (this one is nice because everything is packed into one DLL):
(new NReco.VideoConverter.FFMpegConverter()).ConvertMedia(pathToVideoFile, pathToOutputMp4File, Formats.mp4)
Note that video conversion requires significant CPU resources; it's good idea to run it in background.
Your Answer
please Replace .flv to .mp4 you will get your answer
private bool ReturnVideo(string fileName)
{
string html = string.Empty;
//rename if file already exists
int j = 0;
string AppPath;
string inputPath;
string outputPath;
string imgpath;
AppPath = Request.PhysicalApplicationPath;
//Get the application path
inputPath = AppPath + "OriginalVideo";
//Path of the original file
outputPath = AppPath + "ConvertVideo";
//Path of the converted file
imgpath = AppPath + "Thumbs";
//Path of the preview file
string filepath = Server.MapPath("~/OriginalVideo/" + fileName);
while (File.Exists(filepath))
{
j = j + 1;
int dotPos = fileName.LastIndexOf(".");
string namewithoutext = fileName.Substring(0, dotPos);
string ext = fileName.Substring(dotPos + 1);
fileName = namewithoutext + j + "." + ext;
filepath = Server.MapPath("~/OriginalVideo/" + fileName);
}
try
{
this.fileuploadImageVideo.SaveAs(filepath);
}
catch
{
return false;
}
string outPutFile;
outPutFile = "~/OriginalVideo/" + fileName;
int i = this.fileuploadImageVideo.PostedFile.ContentLength;
System.IO.FileInfo a = new System.IO.FileInfo(Server.MapPath(outPutFile));
while (a.Exists == false)
{
}
long b = a.Length;
while (i != b)
{
}
string cmd = " -i \"" + inputPath + "\\" + fileName + "\" \"" + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".flv" + "\"";
ConvertNow(cmd);
string imgargs = " -i \"" + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".flv" + "\" -f image2 -ss 1 -vframes 1 -s 280x200 -an \"" + imgpath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".jpg" + "\"";
ConvertNow(imgargs);
return true;
}
private void ConvertNow(string cmd)
{
string exepath;
string AppPath = Request.PhysicalApplicationPath;
//Get the application path
exepath = AppPath + "ffmpeg.exe";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = exepath;
//Path of exe that will be executed, only for "filebuffer" it will be "flvtool2.exe"
proc.StartInfo.Arguments = cmd;
//The command which will be executed
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
while (proc.HasExited == false)
{
}
}
protected void btn_Submit_Click(object sender, EventArgs e)
{
ReturnVideo(this.fileuploadImageVideo.FileName.ToString());
}
I know it's a bit old thread but if I get here other people see this too. You shoudn't use it process info to start ffmpeg. It is a lot to do with it. Xabe.FFmpeg you could do this by running just
await Conversion.Convert("inputfile.mkv", "file.mp4").Start()
This is one of easiest usage. This library provide fluent API to FFmpeg.
Is it possible to merge the two videos by c# asp.net with the help of ffmpeg. In the ffmpeg documentation they gave us cat command. But it wont works in asp.net. I thought it only for linux.
cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg
asp.net execute this command but there is no output. Help me.
namespace demo
{
public partial class Default : System.Web.UI.Page
{
protected void Button2_Click(object sender, EventArgs e)
{
string strFile = "cars1.flv";
MergeFiles(strFile);
}
public void MergeFiles(string strFile)
{
string strParam;
string Path_FFMPEG = Server.MapPath("~/ffmpeg/bin/ffmpeg.exe");
//Converting a video into mp4 format
string strOrginal = Server.MapPath("~/Videos/");
strOrginal = strOrginal + strFile;
string strConvert = Server.MapPath("~/Videos/ConvertedFiles/");
string strExtn = Path.GetExtension(strOrginal);
if (strExtn != ".mp4")
{
strConvert = strConvert + strFile.Replace(strExtn, ".mp4");
strParam = "-i " + strOrginal + " " + strConvert;
//strParam = "-i " + strOrginal + " -same_quant " + strConvert;
process(Path_FFMPEG, strParam);
}
//Merging two videos
String video1 = Server.MapPath("~/Videos/Cars1.mp4");
String video2 = Server.MapPath("~/Videos/ConvertedFiles/Cars2.mp4");
String strResult = Server.MapPath("~/Videos/ConvertedFiles/Merge.mp4");
//strParam = "-loop_input -shortest -y -i " + video1 + " -i " + video2 + " -acodec copy -vcodec mjpeg " + strResult;
strParam = " -i " + video1 + " -i " + video2 + " -acodec copy -vcodec mjpeg " + strResult;
process(Path_FFMPEG, strParam);
}
public void process(string Path_FFMPEG, string strParam)
{
try
{
Process ffmpeg = new Process();
ProcessStartInfo ffmpeg_StartInfo = new ProcessStartInfo(Path_FFMPEG, strParam);
ffmpeg_StartInfo.UseShellExecute = false;
ffmpeg_StartInfo.RedirectStandardError = true;
ffmpeg_StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo = ffmpeg_StartInfo;
ffmpeg_StartInfo.CreateNoWindow = true;
ffmpeg.EnableRaisingEvents = true;
ffmpeg.Start();
ffmpeg.WaitForExit();
ffmpeg.Close();
ffmpeg.Dispose();
ffmpeg = null;
}
catch (Exception ex)
{
}
}
}
}
Finally i found the answer for my own question.
The following method resolves my problem.
public void MergeFiles(string strFile)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = Server.MapPath("~/app.bat");
p.Start();
p.WaitForExit();
p.Dispose();
}
app.bat
The app.bat contains the following code.
copy e:\cars1.mpg /b + e:\cars2.mpg /b e:\output.mpg /b
NOTE: This is for windows only. That's why "cat" command doesn't works. Instead of "cat" command we use copy command.
Creating app. Bat file double the file size but it play as single. Still problem not resolved. You should try ffmpeg concat command approach in which you need to create a text file that contain files names and this file should be on same folder where mp4 file are. the below code will help you i was facing the same issue. My task was to merge two mp4 files and I merge successfully when I was doing it from Command prompt. But stuck when I was doiing it through asp. Net. My issue resolved by given correct path and remove ffmpeg from command. For E. G( ffmepg - f concat TO - f concat)
Dim _ffmpeg As String = "D:\Develop\Experiment\mergermp4Vb\mergermp4Vb\bin\ffmpeg.exe"
Dim params = "-f concat -i D:\Develop\Experiment\mergermp4Vb\mergermp4Vb\Videos\mylist2.txt -c copy D:\Develop\Experiment\mergermp4Vb\mergermp4Vb\Videos\0104.mp4"
Dim _FFmpegProcessPropertys As New ProcessStartInfo
_FFmpegProcessPropertys.FileName = _ffmpeg
_FFmpegProcessPropertys.Arguments = params
_FFmpegProcessPropertys.UseShellExecute = False
_FFmpegProcessPropertys.RedirectStandardOutput = True
_FFmpegProcessPropertys.RedirectStandardError = True
_FFmpegProcessPropertys.CreateNoWindow = True
Dim FFmpegProcess = Process.Start(_FFmpegProcessPropertys)
I want to know how to capture thumbnail for video while uploading it in ASP.NET ?
Well first of all, you will also need to convert it to MP4 which will work on everywhere. For that you can use ffmpeg tool,
To Create Thumbnail,
//Create Thumbs
string thumbpath, thumbname;
string thumbargs;
string thumbre;
thumbpath = AppDomain.CurrentDomain.BaseDirectory + "Video\\Thumb\\";
thumbname = thumbpath + withoutext + "%d" + ".jpg";
thumbargs = "-i " + inputfile + " -vframes 1 -ss 00:00:07 -s 150x150 " + thumbname;
Process thumbproc = new Process();
thumbproc = new Process();
thumbproc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe";
thumbproc.StartInfo.Arguments = thumbargs;
thumbproc.StartInfo.UseShellExecute = false;
thumbproc.StartInfo.CreateNoWindow = false;
thumbproc.StartInfo.RedirectStandardOutput = false;
try
{
thumbproc.Start();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
thumbproc.WaitForExit();
thumbproc.Close();
However, for more details about the code, see this link.
http://ramcrishna.blogspot.com/2008/09/playing-videos-like-youtube-and.html
And you will need to change paths according to your web application's path.