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

Kodi keeps crashing when it is started without connected displays. Sometimes I want to startup my kodi setup for some other reasen and start using kodi later.... then kodi was already closed with some crash log file... :( This script works arround by waiting to start kodi until some hdmi port is connected (modify the grep query to adapt to some other port name). #!/bin/bash # Some programs have issues when run without connected display. E.g. Kodi likes to crash when started without any display connected on my system. # This script starts after some hdmi port is connected. # Depends on xrandr. WARNINGTIMEOUTINSECONDS=840 TIMEOUTINSECONDS=900 POLLINGDURATIONINSECONDS=5 LOGFILE= " $HOME /waitTillHdmiConnected.log" #set start conditions SECONDS=0 triggerTimeoutActions (){      echo   ...

Skript kiddies und SSH

Anzahl an fehlerhaften Logins ausgeben: cat /var/logauth.log | grep invalid | wc -l Für einen Server, der in halbes Jahr im Netz läuft finde ich 68350 Versuche. Ein Auszug von /var/logauth.log Jun 3 00:12:02 uhweb69144 sshd[11470]: Invalid user hilary from 201.147.235.91 Jun 3 00:12:02 uhweb69144 sshd[11470]: reverse mapping checking getaddrinfo for static.customer-201-147-235-91.uninet-ide.com.mx failed - POSSIBLE BREAK-IN ATTEMPT! Jun 3 00:12:02 uhweb69144 sshd[11470]: (pam_unix) check pass; user unknown Jun 3 00:12:02 uhweb69144 sshd[11470]: (pam_unix) authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost= 201.147.235.91 Jun 3 00:12:04 uhweb69144 sshd[11470]: Failed password for invalid user hilary from 201.147.235.91 port 49507 ssh2 Jun 3 00:12:09 uhweb69144 sshd[11530]: Invalid user howard from 201.147.235.91 Jun 3 00:12:09 uhweb69144 sshd[11530]: reverse mapping checking getaddrinfo for static.customer-201-147-235-91.uninet-ide.com.mx failed - POSS...

favourite geek&poke comics

http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef013485e5e37b970c-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef013486458e35970c-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0133f32a0f25970b-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0133f3716c17970b-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef013486997ef7970c-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef013487146609970c-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0133f4227ee4970b-pi