VideoHelp Forum
+ Reply to Thread
Results 1 to 13 of 13
Thread
  1. Hi !

    I'm trying to code a little soft in C# (it's new langage for me), and i've a little problem.

    In a batch script, with Mediainfo.exe to export data, like framerate, into a text file, you just have to write :
    Code:
    MediaInfo --inform=Video;%%FrameRate%% "video.mp4" > "framerate.txt"
    So, i've been searching on how to execute a program with parameters in C#, I found :
    Code:
    System.Diagnostics.Process.Start("PROGRAM.exe", "COMMAND OPTION");
    So i've put :
    Code:
    System.Diagnostics.Process.Start("MediaInfo.exe", "--inform=Video;%%FrameRate%% c:/test/file.mp4 > c:/test/test.txt");
    And of course, it doesn't work. Well, the window open and close very fast, and with a screenshot i've been able to see what's written, and it's good, but the part which doesn't work, is writing into the txt file.

    I don't know what to do to make it work. If I can't write into a txt file, I'd like to put the information in a variable
    Quote Quote  
  2. batch expert Endoro's Avatar
    Join Date
    Dec 2013
    Location
    Bozen
    Search PM
    Try single percent rather than double.
    Quote Quote  
  3. It doesn't change anything, I think it's the ">", which is the command (in batch) to write into a txt file...
    Quote Quote  
  4. A Member since June, 2004 Keyser's Avatar
    Join Date
    Feb 2013
    Location
    Westernmost point of Europe
    Search Comp PM
    it doesn't work because "> c:/test/test.txt" isn't part of the command options. It is a redirection of the standard output.
    "The greatest trick the Devil ever pulled was convincing the world he didn't exist."
    Quote Quote  
  5. Is there a way to affect the value display by the execution of the program into a variable?
    Quote Quote  
  6. That mediainfo CLI worked for me but it can return only basic info, for example it could not return if video was progressive etc.
    , so I used mediainfo.dll from Ripbot264 that can dump txt file with mediainfo listings into a tree structure, not sure where it came from, maybe it is RipBot264 author, Atak Snajpera who modified that DLL.
    Code:
    "%mediainfo%" %1 dumpinfo:"unicodefile.txt"
    TYPE "unicodefile.txt" > "ascii.txt"
    end then you just parse that ascii.txt , for whatever you look for
    Quote Quote  
  7. batch expert Endoro's Avatar
    Join Date
    Dec 2013
    Location
    Bozen
    Search PM
    I have no clue of C#, but this looks better:
    Code:
    System.Diagnostics.Process.Start("MediaInfo.exe", "--inform=Video;%FrameRate%" "c:/test/file.mp4" > "c:/test/test.txt");
    Quote Quote  
  8. that double % is ok there, otherwise it would not work, but that goes for windows batch script, no idea what is legit for C#
    Quote Quote  
  9. batch expert Endoro's Avatar
    Join Date
    Dec 2013
    Location
    Bozen
    Search PM
    But why do you call a Batch and not mediainfo directly? What Batch code do you use?
    Quote Quote  
  10. a. instead of using the pipe one could specifiy an output file '--Output=file://Text.txt' , see: "mediainfo --help-output"
    b. if you call it from a program there should also be a possibility to capture the command line output with your program, which would allow to avoid any temporal files
    c. if you call mediainfo inside a programm you could also use the dll,...
    Quote Quote  
  11. I don't know how to use the dll actualy... If you can show me..

    I succeded to do what I wanted but it exports in txt file, it's fine for me but if I can avoid that would be great
    Quote Quote  
  12. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    First of all on my computer this works:
    "MediaInfo.exe", "--inform=Video;%%FrameRate%% " "c:/test/file.mp4" > "c:/test/test.txt"
    This does not
    "MediaInfo.exe", "--inform=Video;%%FrameRate%% c:/test/file.mp4 > c:/test/test.txt"

    Also, I just went through the exact same thing creating a program that copies the UTC Encoded date to the Created date of videos. Basically when your program calls a CLI screen, whether you keep the CMD Window open or not, it is starting a separate process and considers it finished and goes on with it's code without waiting for the output from MediaInfo. Tests showed anywhere from 2.0 to 4.5 seconds for Media Info to return information. You can see this if you open a Command window and run the command following on a folder full of videos:

    C:\Users\Bud\Desktop\Holder Folder\New Holder>for %a in (*.*) do "MediaInfo.exe" "--Inform=General;Encoded Date = %Encoded_Date%\r\nTagged Date = %Tagged_Date%" "%a" > "%a.txt".

    It takes a period for the information to show up and all files to be written and if your program looks for it before it is actually there, which it will, it will fail to find it. You can use the excellent method linked by Selur above or if you have problems getting WaitForExit() to work, build a delay in with a timer to 'wait' until it had finished before proceeding. By that I mean launch the CLI, finish execution until the timer times out and go get the variable or StdOut and obtain what you need.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!