Direkt zum Hauptbereich

ffmpeg wrapper for .net and java

Ok. I built a custom ffmpeg wrapper but it was just a dirty hack. it was not encapsulated clean.... it worked but it was just tooo ugly to develop some extension... wrapping looked something like this:


THIS DOES NOT WORK it is refactored to death:
   class MencoderSharp
    {
        public static bool mencoder(System.Uri infovdrpath, string ratio, System.Uri destinationpath, BackgroundWorker worker, bool deleteConverted,string audioparameter, string videoparamter, bool testRun, DoWorkEventArgs e)
        {
            int returncode = 0;
            foreach (string sourcepath in Directory.GetFiles(infovdrpath.ToString().Substring(0, infovdrpath.ToString().Length - 9), "0*.vdr"))
            {
                Process p = new Process();
                //p.StartInfo.WorkingDirectory = @"C:\whatever";
                p.StartInfo.FileName = @"mencoder.exe";
                //http://msdn.microsoft.com/de-de/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx
                p.StartInfo.RedirectStandardOutput = false;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                string arguments;
                if (ratio == "4/3")
                {
                    //4:3
                    arguments = "\"" + sourcepath + "\" " +audioparameter  + " " + videoparamter + " " + destinationpath;
                }
                else
                {
                    //16:9
                    arguments = "\"" + sourcepath + "\" " + audioparameter + " " + videoparamter + " " + destinationpath;
                }
                // for testing:
                if (testRun)
                {
                    //nur die ersten 6 sekunden mencodieren:
                    arguments = arguments + " -endpos 6";
                }
                //richTextBox1.Text = "\n\n" + richTextBox1.Text + arguments + "\n";
                //p.StartInfo.Arguments = sourcepath + "  -oac copy -aid 128  -ovc xvid -xvidencopts bitrate=800:aspect="+ratio+"  -vf scale=-10:-1 -o \"" + destinationpaht + "\"";
                //richTextBox1.Text += arguments;
                p.StartInfo.Arguments = arguments;
                //p.StartInfo.CreateNoWindow = true;
                //richTextBox1.Text += arguments + "\n";

                p.Start();
                //nur eins darf synchron gelesen werden!! http://msdn.microsoft.com/de-de/library/system.diagnostics.processstartinfo.redirectstandarderror.aspx
                //richTextBox1.Text = richTextBox1.Text + p.StandardOutput.ReadToEnd();
                //richTextBox1.Text = richTextBox1.Text + p.StandardError.ReadToEnd();
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }
                p.WaitForExit();
                e.Result = p.ExitCode;
                //Wenn das Konvertieren erfolgreich war, dann lösche doch bitte das original
                if (p.ExitCode != 0)
                {
                    returncode = 1;
                }
                //worker.ReportProgress(p.ExitCode);
            }
            if (returncode == 0)
            {
                foreach (string sourcepath in Directory.GetFiles(infovdrpath.Substring(0, infovdrpath.Length - 9), "0*.vdr"))
                {
                    //Filenamen für die temporären transkodierten Datein generieren
                    string tempfilename = destinationpath.Insert(destinationpath.Length - 4, sourcepath.Substring(sourcepath.Length - 7, 3));
                    File.Move(tempfilename, tempfilename.Substring(0, tempfilename.Length - 4) + ".avi");
                }

                if (!testRun)
                {
                    Directory.Delete(infovdrpath.Substring(0, infovdrpath.Length - 9), true);
                    richTextBox1.Text += infovdrpath.Substring(0, infovdrpath.Length - 9) + " wurde gelöscht\n";
                }
            }
            else
            {
                //Wenn die Transkodierung unerfolgreich war, dann bitte die tmpdatein löschen
                foreach (string sourcepath in Directory.GetFiles(infovdrpath.Substring(0, infovdrpath.Length - 9), "0*.vdr"))
                {
                    //Filenamen für die temporären transkodierten Datein generieren
                    string tempfilename = destinationpath.Insert(destinationpath.Length - 4, sourcepath.Substring(sourcepath.Length - 7, 3));
                    if (File.Exists(tempfilename))
                        File.Delete(tempfilename);
                }
            }
        }
    }

.net
FFlib.NET
http://www.intuitive.sk/fflib/
  • source code available for money
  • free for personal and commercial use
  • Last Rlease: 2008
ffmpeg-sharp
http://code.google.com/p/ffmpeg-sharp/
  • GPL
  • Last Rlease: 2009
SharpFFmpeg
http://sourceforge.net/projects/sharpffmpeg/
  • Last Rlease: 2006

Java
JAVE
http://www.sauronsoftware.it/projects/jave/
  • GPL
  • Last Rlease: 2009
Sample:
public void encode(java.io.File source, java.io.File target, it.sauronsoftware.jave.EncodingAttributes attributes)

FOBS
http://fobs.sourceforge.net/
  • GPL
  • Last Rlease: 2008


FFMPEG-Java
http://fmj-sf.net/ffmpeg-java/getting_started.php

JMF wrapper for ffmpeg
http://sourceforge.net/projects/jffmpeg/files/jffmpeg/
  • GPL, LGPL
  • Last Rlease: 2006
Offtopic:

.net Wrapper for libvlc - use vlc to play videos in .net
http://wiki.videolan.org/C_Sharp

Conclusion:

By now JAVE seems to be the most attraktive ffmpeg wrapper for a highlevel lanugage. see http://www.sauronsoftware.it/projects/jave/manual.php#9 for what i mean. maybe i report later if it does the job ...

Kommentare

Anonym hat gesagt…
Hi, mich würde interessieren welche Erfahrungen du mit JAVE gemacht hast, oder ob du den Wrapper/FFMPEG Integration nochmal gewechselt hast?
Gruß, Jo
stefan hat gesagt…
hi Jo,
JAVE will nur java.io.file als parameter. das ist unbrauchbar für mich. ich will sourcen, die über ftp abzuholen sind, benutzen.
Sonst hat das ding, soweit ich mich erinnern kann, ganz gut funktioniert.
gruss stefan
stefan hat gesagt…
solved my own problem with http://code.google.com/p/mencoder-sharp/

Beliebte Posts aus diesem Blog

Open DRM-Free Unencrypted DVB-T2 Tv and Radio in Austria

Most things in Austria terestical TV got encrypted since DVB-T got shut down, but there are still three TV channels and three Radio Channels unencrypted. I had some hard time to find out how to get it working using linux... and non existing documentation of the sender did not help. Howerver... if you have use for detailed channel setup arround vienna, take a look: Tvheadend seems to lack channel search support using DVB-T2, but puzzeling every value together works fine: Mux A-WNB Channel Frequency: 498000000 Bandwitdh: 8MHz Constellation; QAM/16 Mux B2 Channel Frequency: 578000000 Bandwitdh: 8MHz Constellation; QAM/16 Unstable Twin Tuner I am using some twin tuner. That was not supported on older kernel version, but is now supported on current versions. Great? nope. The system/tvheadend gets unstable if two tuner are enabled running for weeks. After disabling one tuner, tvheadend runs reliable for months. List of unencrypted streams Example stream info tv channel   Surround sound Too

Cleanup your windows machine

still working: Use these lines to get your windows system cleaned up a bit and free your disk from old temporary and backup files: RD %temp%\ /S /Q rd /s /q C:\Windows\ServiceProfiles\NetworkService\AppData\Local\VSEQT\QTController rd %windir%\temp\ /s /q rd C:\TEMP\ /s /q rd C:\Quarantine /s /q rd "%userprofile%\AppData\Local\Temp\"  /s /q del C:\Windows\Installer\.tmp RD /S /Q "%SystemRoot%\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET Files\" RD /S /Q "%SystemRoot%\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\" RD /S /Q "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\" RD /S /Q "%SystemRoot%\Microsoft.NET\Framework\v3.0\Temporary ASP.NET Files\" RD /S /Q "%SystemRoot%\Microsoft.NET\Framework\v3.5\Temporary ASP.NET Files\" RD /S /Q "%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\" RD /S /Q "%userprofile%\AppData\Local\Microso

pdf to dxf

if you get a cad plan in pdf format you have a problem: Pdf can not be loaded in most cad programs. I used pstoedit to solve this problem. Pstoedit is a free tool to convert pdfs to dxf. What you have to do: Install pstoedit Install ghostscript shot at your pdfs: pstoedit.exe <pdfSource> <dxfOutput> -f dxf thanks to the author of pstoedit! Here is the pstoedit.exe -help output: No output format specified (-f option) and format could not be uniquely deduced from suffix .dxf of output file Available formats :     psf:            .fps:    Flattened PostScript (no curves)     (built-in) -------------------------------------------     ps:            .spsc:    Simplified PostScript with curves     (built-in) -------------------------------------------     debug: