I'm new to c# and I'm trying to write a movie database that retrieves data from IMDB. For the codecs I found MediaInfo. The included example in winforms works fine, but when I try to use the library in my console application I get the error "Unable to load MediaInfo library".
I did:

  • Put MediaInfo.dll in \bin\debug
  • Included the file MediaInfoDLL.cs in my project
  • In the source code added "using MediaInfoLib;"

So why do I get the error ?


 class Program
        static void Main(string[] args)
            var mi = new MediaInfo();

I can't answer your question but I think you may want to check out Movie DB API. I use it to get movie info via code.

Thanks, but the API is for the movie nfo, not codec nfo (mkv, avi, x246, aac, ac3,....)

I was confused by

I'm trying to write a movie database that retrieves data from IMDB

since IMDB lists a lot of details about a movie, but not the codec since that is not movie specific.

Well, I finally figured it out: in project properties I had to change "any cpu" to x64.

Thanks, I will look into it and see if I can use it.

Here's how I get the media info via code (Python). Save this to a file with a py extension (e.g. mediainfo.py) then run it with the name of a video file as a parameter.

import os
import re
import subprocess

def execCmd(cmd=""):
    return subprocess.check_output(cmd, shell=True).decode().splitlines()

class MediaInfo(object):
    Runs MediaInfo.exe and arranges the output in a more code-friendly way.
    Information is returned as key-value pairs in three dictionaries for the
    three sub-categories of inf which are General, Video, and Audio.
    def __init__(self,file):

        self.General = {}
        self.Audio   = {}
        self.Video   = {}

        if os.path.isfile(file):

            for line in execCmd('mediainfo.exe "%s"' % file):

                line = line.replace('\r','').strip()
                flds = line.split()

                if len(flds) == 1:
                    if   flds[0] == "General": dict = self.General
                    elif flds[0] == "Video":   dict = self.Video
                    elif flds[0] == "Audio":   dict = self.Audio
                elif len(flds) > 1:
                    colon = line.find(":")
                    dict[line[:colon].strip()] = self.fixnums(line[colon+1:].strip())

    def fixnums(self, str):
        Takes a string and removes blanks embedded in number. For example,
        the string '1 024 kb/s' is converted to '1024 kp/s'.
        emb = re.compile(r'(\d+) (\d+)')
        str = re.sub(emb,r'\1\2',str)
        return str

if __name__ == "__main__":

    import sys

    info = MediaInfo(sys.argv[1])

    for key in info.General:
        print("    %s:%s" % (key,info.General[key]))

    for key in info.Video:
        print("    %s:%s" % (key,info.Video[key]))

    for key in info.Audio:
        print("    %s:%s" % (key,info.Audio[key]))
commented: The more I use Python the more I use Python. It's addictive or additive. +15

Thanks, I will give it a try.