I'm using Runtime.getRuntime.exec(String) to cut some songs with ffmpeg.
But when my song has a name with a blankspace it doesn't work ...
So before I cut the song, I want to replace every blank space of my songs by "\ ".
I did that :
String in = directory+songs.get(i);
String out = directory+"trimed_"+songs.get(i);
in.replaceAll(" "," \\ ");
out.replaceAll(" ", "\\ ");
String str = "ffmpeg -t 1 -i "+in+" -vcodec copy "+out;
Runtime.getRuntime().exec(str);
But it doesn't replace anything at all when I print str, am I missing something ?
Update : I tried every ideas given bellow and I didn't find a way to fix the problem. Hence, I replaced the blankspaces by "_" and it's working great.
Try
String in = directory+songs.get(i);
String out = directory+"trimed_"+songs.get(i);
/* in = in.replaceAll("\\s","\\\\ ");
out = out.replaceAll("\\s","\\\\ ");
*/
in = "\"" + in + "\"";
out = "\"" + out + "\"";
String str = "ffmpeg -t 1 -i " + in + " -vcodec copy " + out;
Runtime.getRuntime().exec(str);
System.out.println("Command executed " + str);
Note: I tested this code myself its working fine.
If it still not working then execute the command manually by copying the str from log and trace the error
Related
String cmc = "D:\\fileFolder\\File Name-" + CurrentDate() + ".xlsx";
String autoitexec = "D:\\AutoITScripts\\AttachFile.exe" + cmc;
Runtime.getRuntime().exec(autoitexec);
Above code is my current code. I am passing autoIt script location and file location from string autoitexec. I am unable to run above code ..
String cmc = "D:\\fileFolder\\File Name-" + CurrentDate() + ".xlsx";
String autoitexec = "\"D:\\AutoITScripts\\AttachFile.exe\" \"" + cmc + "\"";
Runtime.getRuntime().exec(autoitexec);
Escape double quotes with a backslash. i.e. 2 double quotes inside a double quoted string is " \" \" ".
Spaces are required between the command and each of the arguments.
I know I can set the start with -ss and end with -to but can someone please help me to format the following so that I can enter the -ss and -to with a string?
I want -ss to come from
String start = editStart.getText().toString();
and -to to come from
String end = editEnd.getText().toString();
Here is my ffmpeg string I want to edit, I have entered -ss and -to to show where I want the above strings to be.
String s = "-i" + " " + mVideoUri.toString().replace("file:///", "") + " -filter_complex [1:v][0:v]scale2ref=iw:ih[ovr][base];[ovr]colorchannelmixer=aa=0.7[ovrl];[base][ovrl]overlay[v] -ss -to -map [v]" + directoryToStore + "/" + FileName + mp4;
String[] arguments = s.split(" ");
ExecuteFFMPEG(arguments);
Ok so you get your start and end point from:
String start = editStart.getText().toString();
String end = editEnd.getText().toString();
So instead of splitting the argument do this instead:
String[] s = {"-i" ,mVideoUri.toString(),"-filter_complex","[1:v][0:v]scale2ref=iw:ih[ovr][base];[ovr]colorchannelmixer=aa=0.7[ovrl];[base][ovrl]overlay[v]","-ss","start","-to","end","-map","[v]",directoryToStore+"/"+"output.mp4"};
ExecuteFFMPEG(s);
It's so weird that the String + operation has a bug:
String path = "/app/" + monPHost.getUsername() + "/app/" + monProcessInfo.getRegion() + "/tf/bin";
System.out.println("here it ...." + path);
This is the result:
here it ..../app/aiams/app/791
Where has the "/tf/bin" gone?
Maybe monProcessInfo.getRegion() is ending with a carriage return. Try to pre-process it, strip it, and the concatenate with your string.
OR, try this:
String path = "/app/" + monPHost.getUsername() + "/app/" + monProcessInfo.getRegion();
path = path + "/tf/bin";
System.out.println("here it ...." + path);
As a quick work around for all the spaces you're getting:
String path = "/app/" + monPHost.getUsername() + "/app/" + monProcessInfo.getRegion().trim() + "/tf/bin";
System.out.println("here it ...." + path);
I recommend tracking this down in your process object and fixing it there, if you only ever expect an Integer result try to return one, failing fast & early can prevent a lot of downstream bugs.
Given in comment you mentioned monProcessInfo.getRegion() is giving you a String with lots of spaces, and you haven't mentioned the type of return for this method, here is what you may do:
If it is returning a String:
It will be as easy as
String path = "...." + monProcessInfo.getRegion().trim() + "/tf/bin";
If it is returning something else:
Given String concat in Java is relying on Object.toString(), you can change it to:
String path = "...." + monProcessInfo.getRegion().toString().trim() + "/tf/bin";
Since you mentioned that monProcessInfo.getRegion() returns lots of spaces, you can try trimming it before appending it to the later part of the string.
StringBuilder sb = new StringBuilder();
sb.append("/app/" + monPHost.getUsername() + "/app/");
String region = ("" + monProcessInfo.getRegion()).trim();
sb.append(region + "/tf/bin");
System.out.println("here it ...." + sb.toString());
Hello this problem has been bugging me since a week I searched everywhere in vain. I have this code
................
while ((str = buff.readLine()) != null) {
String[] line = str.split(";");
String part1 = line[0];
String part2 = line[1];
String part3 = line[2];
String part4 = line[3];
String part5 = line[4];
if (c.equals(part3)) {
st = st + part1 + ";" + part2 + ";" + part3 + ";" + part4 + ";" + part5;
System.out.println(part1 + ";" + part2 + ";" + part3 + ";" + part4 + ";" + part5 + "\n");
fich1_tampon.write(st);
fich1_tampon.flush();
fich1_tampon.newLine();
++i;
}
}
System.out.println("F;" + i);
fich1_tampon.close();
buff.close();
}
the "System.out.println("F;" + i);" is ignored I don't know why. The code is very long but basically I'm looking for lines that have a certain String that was put in c and I'm writing those line in another file.
The result on my consoleis like this :
E;2014/02/19 20:21:06
File already exists.
N;2000;PU;Promotion iphone;232425
N;2001;PU;Promotion dell;232426
N;2002;PU;Promotion samsung;23242
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at LireFichierDecouper.decouper(LireFichierDecouper.java:70)
at Main2.main(Main2.java:7)
Line 70 in LireFichierDecouper is "String part3 = line[2];"
PS:I'm very very new to java and eclipse, if you want me to post all the code to make it more clear I will.
If you work on eclipse, check "Problems" view for errors. Sometimes eclipse cannot compile code when your workspace has errors.
If you work on a running server, may be server do not recognize your changes. Restart it, may be this helps.
If double of above do not help you please explain exactly what you want and specify your development environment how it is.
A debugger would be helpful to see if you are reaching that code by adding a break point at the System.out.println. Also, where are you running the code? System.out.println would go where directed depending on how java is run. Please provide the command line if executing from the command line.
Java newbie here, I'm having trouble setting a new line in this code:
String FnameTextboxText = FnameTextbox.getText();
String LastnameTextboxText = LastnameTextbox.getText();
String CourseTextboxText = CourseTextbox.getText();
Summary.setText("Firstname:" + " " + FnameTextboxText + "\nLastname:" + " " + LastnameTextboxText + "\nCourse:" + " " + CourseTextboxText);
Also tried something like: "\n" + "Lastname" But its no good.
Do you have any idea on how to make new lines. So that it'll look like this;
Firstname: x
Lastname: y
Course: Z
Using netbeans 6.8. On windows.
I guess you need to use TextArea.
First, use TextArea
Second, test using \r or \n or \r\n
Sometimes, people use \n to make new line and sometimes, like me, use \r\n to make new line