Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by RoofTurkey · Jan 16, 2016 at 04:28 PM · c#command line

Running command line action through C# script

For a project I need to load in video files from the computer. However, as Unity does not support any other format besides "ogg" (right?), I will have to convert the videos from .mp4 to .ogg first. To do this I found ffmpeg that I can simply call from the command line and then it converts the video nicely.

However I would now like to automate this process by running that command line script dynamically from the Unity game itself, so the user won't have to perform any extra actions.

The script I tried to use for this looks like this:

 public static void ExecuteCommand (string inputVideo)
     {
         var processInfo = new ProcessStartInfo("cmd.exe", @"ffmpeg -i " + inputVideo + @" -acodec libvorbis -vcodec libtheora -f ogg " + inputVideo.Split('.')[0] + @".ogg");
         processInfo.CreateNoWindow = true;
         processInfo.UseShellExecute = false;
 
         var process = Process.Start(processInfo);
 
         process.WaitForExit();
         process.Close();
     }

The problem I have is that it freezes Unity when I run it through this code:

 if (dialog.FileName.EndsWith(".mp4"))
             {
                 ConvertVideo.ExecuteCommand(dialog.FileName);
             }
             url = dialog.FileName.Split('.')[0] + ".ogg";

Any idea what might fix my problem?

Edit: Platform is Windows in case that could make a difference.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image samf1111 · Jul 13, 2021 at 12:02 PM 0
Share

windows platform will make a HUGE difference. windows commands cant run on linux or mac. they all have different commands.

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by hexagonius · Jan 16, 2016 at 04:38 PM

I think that's because the conversion takes place on the same Thread as Unity's. For this to be executed parallel to Unity you need to put the task on a seperate thread.

Maybe this is a start:
threading

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RoofTurkey · Jan 18, 2016 at 09:18 AM 0
Share

This seems to fix the freezing:

 public static void ExecuteCommand (string inputVideo)
     {
         var thread = new Thread(delegate () {Command(inputVideo);});
         thread.Start();
     }
 
     static void Command (string input)
     {
         var processInfo = new ProcessStartInfo("cmd.exe", @"ffmpeg -i " + input + @" -acodec libvorbis -vcodec libtheora -f ogg " + input.Split('.')[0] + @".ogg");
         processInfo.CreateNoWindow = true;
         processInfo.UseShellExecute = false;
 
         var process = Process.Start(processInfo);
         
         process.WaitForExit();
         process.Close();
     }

But it still doesn't give me the same result as when I run the line directly in the command prompt (cmd.exe).

Any idea what could be the cause of that?

Edit: I've directly used ffmpeg(.exe) now and it works like a charm :-) .

avatar image Jeffreyharper926 · Apr 02, 2017 at 06:00 AM 0
Share

Hello,

I used some of this code in my own project, even calling the ffmpeg.exe directly. However, the video does not get saved.

var processInfo = new ProcessStartInfo(path, @"-i input output.wav");

path is the path to the ffmpeg... Any help here would be awesome. Thanks

PS I have my FF$$anonymous$$PEG folder in my Strea$$anonymous$$gAssets Folder

If that makes a difference.

avatar image
0

Answer by Joshtradamus · Jan 05, 2018 at 08:35 PM

what if I want the command prompt to run a certain input when I use it. Ideally I want to push a button that will enable command prompt to pull up as a background process with a pre-input text that it responds to and continue to run in the background. How to do that all at a click of a button with c script?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eskivor · Sep 29, 2021 at 04:52 PM 0
Share

'How to do that all at a click of a button with c script?'

Use menu items for example: https://docs.unity3d.com/ScriptReference/MenuItem.html

'what if I want the command prompt to run a certain input when I use it' What do you mean by input? If you want to execute a specific method, '-executeMethod' argument may be want you want: https://docs.unity3d.com/Manual/CommandLineArguments.html

avatar image
0

Answer by talespinvr · May 27 at 01:39 PM

Is there a way to do this during play mode? My thread keeps getting aborted, likely by Unity.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Nancy963 · May 27 at 04:21 AM

The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window. www.myfortiva.com

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Get notification from command line or other application when a printer finish printng? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges