none
What is the “Error initializing filter 'drawtext' with args…” error in using of ffmpeg at c# process class? RRS feed

  • Question

  • I used this below code for create a resolution of a video and write text on it.

    string fileIn=@"d:\\OtherProjects\\ConvertProj\\ffmpeg\\4k.mp4";
    string fileOut=@"d:\\OtherProjects\\ConvertProj\\ffmpeg\\4k-new.mp4";              
     var proc =newSystem.Diagnostics.Process();
        string OrginalResolution="nhd";
        proc.EnableRaisingEvents=false;
        proc.StartInfo.FileName= ffmpegPath;
        proc.StartInfo.Arguments="-i \""+ fileIn +"\" -f mp4 -s "+OrginalResolution+" -vf drawtext=fontfile=/OtherProjects/ConvertProj/ff‌​mpeg/OpenSans-Reg‌​ular.ttf:text=Parsa" \""+ fileOut.Split('.')[0]+".mp4";
        proc.StartInfo.UseShellExecute=false;
        proc.StartInfo.CreateNoWindow=false;
        proc.StartInfo.RedirectStandardOutput=true;
        proc.StartInfo.RedirectStandardError=true;
    
        proc.Start();
        proc.WaitForExit();string sdsd = proc.StandardError.ReadToEnd();
        proc.Close();

    I faced with this problem(some string output of StandardError is in below):

    Fontconfig error: Cannot load default config file\r\n[Parsed_drawtext_0       
    @0000000002fd8c20] Cannot find a valid font for the family 
    Sans\r\n[AVFilterGraph @ 0000000000511660] Error initializing 
    filter'drawtext' with args 
    'fontfile=/OtherProjects/ConvertProj/ffmpeg/OpenSans-
    Regular.ttf:text=parsa'\r\nError opening 
    filters!\r\n

    In cmd the same argument value of process works fine.

    I proposed this issue at stackoverflow too.
    http://stackoverflow.com/questions/40398506/what-is-the-error-initializing-filter-drawtext-with-args-error-in-using-o




    • Edited by ParsaSaei Sunday, November 6, 2016 1:45 PM
    Sunday, November 6, 2016 1:41 PM

Answers

  • Thank you very much. I test it in a console application as you mentioned, and I set:
    proc.StartInfo.WorkingDirectory=Server.MapPath("/ffmpeg/");
    with your helpful guidance it works.
    just a thing : before set workingDirectory when I debug program I see in StandardError of process the name of font in fontfile address after '-' I mean Regular 'OpenSans-Regular.ttf' changed to a unknown characters.
    and I removed the dash from filename at the directory and my code.
    my final code is here :
    string fileIn=Server.MapPath("/ffmpeg/")+"4k.mp4";
    string fileOut=Server.MapPath("/ffmpeg/")+"4k-new.mp4";              
     var proc =newSystem.Diagnostics.Process();
        string OrginalResolution="nhd";
        proc.StartInfo.FileName= ffmpegPath;
        proc.StartInfo.Arguments="-i \""+ fileIn +"\" -f mp4 -s "+OrginalResolution+" -vf drawtext=fontfile=/OtherProjects/ConvertProj/ff‌​mpeg/OpenSansReg‌​ular.ttf:text=Parsa" \""+ fileOut.Split('.')[0]+".mp4";
        proc.StartInfo.UseShellExecute=false;
        proc.StartInfo.CreateNoWindow=false;
        proc.StartInfo.RedirectStandardOutput=true;
        proc.StartInfo.RedirectStandardError=true;
        proc.StartInfo.WorkingDirectory = Server.MapPath("/ffmpeg/");
        proc.Start();
        proc.WaitForExit();string sdsd = proc.StandardError.ReadToEnd();
        proc.Close();

     

    • Edited by ParsaSaei Monday, November 7, 2016 11:55 AM
    • Marked as answer by ParsaSaei Monday, November 7, 2016 11:56 AM
    Monday, November 7, 2016 11:53 AM

All replies

  • Have you tried the full path to font file?

    If you prefer relative paths, that consider the value of proc.StartInfo.WorkingDirectory too (similar to current directory of cmd experiments).


    • Edited by Viorel_MVP Sunday, November 6, 2016 4:11 PM
    Sunday, November 6, 2016 4:09 PM
  • yes, I set fullpath too.I used it like this:

     

    string fontFilePath=server.MapPath("/ffmpeg/")+"OpenSans-Regular.ttf";

    and used it on argument of proc at below:

    proc.StartInfo.Arguments="-i \""+ fileIn +"\"
     -f mp4 -s "+OrginalResolution+"
     -vf drawtext=fontfile="+fontFilePath+":text=Parsa \""+
     fileOut.Split('.')[0]+".mp4";

    but still exists the error,and I test any addressing method for fontfile which ok with ffmpeg and c# syntaxes and doesn't conflict with them.
    and each solutions that I tested, run with cmd and didn't have any problems, but not work with process class.


    • Edited by ParsaSaei Sunday, November 6, 2016 4:56 PM
    Sunday, November 6, 2016 4:55 PM
  • Before doing complex processing, maybe try an experiment that uses explicit strings and paths only, without concatenations. Try in a console application, then in ASP. And make sure that each opening \” is properly closed.

    Sunday, November 6, 2016 5:10 PM
  • Thank you very much. I test it in a console application as you mentioned, and I set:
    proc.StartInfo.WorkingDirectory=Server.MapPath("/ffmpeg/");
    with your helpful guidance it works.
    just a thing : before set workingDirectory when I debug program I see in StandardError of process the name of font in fontfile address after '-' I mean Regular 'OpenSans-Regular.ttf' changed to a unknown characters.
    and I removed the dash from filename at the directory and my code.
    my final code is here :
    string fileIn=Server.MapPath("/ffmpeg/")+"4k.mp4";
    string fileOut=Server.MapPath("/ffmpeg/")+"4k-new.mp4";              
     var proc =newSystem.Diagnostics.Process();
        string OrginalResolution="nhd";
        proc.StartInfo.FileName= ffmpegPath;
        proc.StartInfo.Arguments="-i \""+ fileIn +"\" -f mp4 -s "+OrginalResolution+" -vf drawtext=fontfile=/OtherProjects/ConvertProj/ff‌​mpeg/OpenSansReg‌​ular.ttf:text=Parsa" \""+ fileOut.Split('.')[0]+".mp4";
        proc.StartInfo.UseShellExecute=false;
        proc.StartInfo.CreateNoWindow=false;
        proc.StartInfo.RedirectStandardOutput=true;
        proc.StartInfo.RedirectStandardError=true;
        proc.StartInfo.WorkingDirectory = Server.MapPath("/ffmpeg/");
        proc.Start();
        proc.WaitForExit();string sdsd = proc.StandardError.ReadToEnd();
        proc.Close();

     

    • Edited by ParsaSaei Monday, November 7, 2016 11:55 AM
    • Marked as answer by ParsaSaei Monday, November 7, 2016 11:56 AM
    Monday, November 7, 2016 11:53 AM