I have over 1000 audio files, all of which end in a mouse click. I would like to remove the last half second from all of them. The audio files have different length (i.e. 15sec, 5 sec ...) But one thing in common with all of them is the last half second has a mouse click sound. How do I trim in bulk the ending of the mp3 files within a folder using windows 10 command line? I already have FFMPEG downloaded. Thank you!
This is two questions in one:
How to remove the last 0.5 seconds from inputs of arbitrary durations?
How to incorporate this into a Windows batch script?
I'll answer #1 because I'm not a Windows user. The batch scripting will be up to you.
Get duration using ffprobe:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp3
Trim using ffmpeg:
ffmpeg -i input.mp3 -t <duration> -c copy output.mp3
Replace <duration> with the output from ffprobe minus 0.5 seconds.
How to incorporate this into a Windows batch script?
This should do:
FOR %%A IN (*.mp3) DO (
FOR /F %%B IN ('ffprobe.exe -v error -show_entries format^=duration -of csv^=p^=0 "%%~A" ^| xidel -s - -e ". - 0.5"') DO (
ffmpeg.exe -i "%%~A" -t %%B -c copy "%%~dpnA_trimmed.mp3"
)
)
First of all, doing floating point calculations in Batch is officially impossible and unofficially really hard to script. That's why I suggest to let Xidel do the math. It's first of all a command line tool to download and extract data from HTML/XML/JSON, but it can do A LOT more!
Loop over all mp3-files in the current directory.
The ffprobe command as suggested by llogan piped to Xidel to subtract the 0.5s. For example, 25.547755 now becomes 25.047755.
Don't forget to escape the necessary characters inside the for-loop! The = and | in this case.
The ffmpeg command as suggested by llogan, which opens "%%~A (the mp3-file), sets the duration to %%B and creates a new mp3-file (<filename>_trimmed.mp3).
This code assumes the mp3-files, ffprobe.exe, xidel.exe and ffmpeg.exe are all in the same directory.
I am using the QGIS software, which includes the OSGeo4W.bat file. This file opens a prompt, rewrite the path variables and include some others, like the python2 enviroment and some sitepackages like the Qt4 installed with QGIS. When opened the .bat file, it opens:
The problem is that i need to insert many commands in here so many times per day, like this one that converts a .ui file made by QtDesigner in .py:
pyuic4 -x C:\Users\Roberto\a.ui -o C:\Users\Roberto\a.py
As this is too much time consuming, i decided to write a batch file, call the OSgeo4W.bat and just add theses commands, but it doesnt work. The commands after the call are not runned. How can i run commands in a batch file inside the prompt created by another batch file? I am using Windows8.1. my batch file
#echo off
call "C:\Program Files\QGIS 2.18\OSGeo4W.bat"
pyuic4 -x C:\Users\Roberto\a.ui -o C:\Users\Roberto\a.py
rem more codes here
pause
You could try the Start command to execute the commands, you could also use timeout to wait before each of the executions.
#echo off
call "C:\Program Files\QGIS 2.18\OSGeo4W.bat"
start pyuic4 -x C:\Users\Roberto\a.ui -o C:\Users\Roberto\a.py
start rem more codes here
//you can use timeout 5 to wait to execute next command
start rem ***
start rem ***
pause
Working with rsync on a windows machine (cWrsync) and I am syncing a large folder with sub directories to a web server which takes several minutes to complete. But when the user just needs to add a file to a sub-directory I don't want them to have to wait an hour to sync that directory.
My Idea
Add a file into each sub-directory (1_sync.bat) that they can execute when they add or delete a file within that directory. I need the batch file to be able to dynamically tell rsync which directory to sync.. here is the static version:
#echo off
REM Make environment variable changes local to this batch file
SETLOCAL
REM where ti find rsync and related files
SET CWRSYNCHOME=C:\cwRsync
SET HOME=C:\Users\greg\AppData\Roaming
SET CWORLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
"C:\cwRsync\bin\rsync.exe" -v -e 'ssh -i C:\home\greg\.ssh\id_rsa' --delete --recursive --inplace "/cygdrive/z/1CustomerDocs/2017/Client Folder/" "root#domainname.com:/var/storage/customer_files/2017/Client\ Folder/"
In the above example I would like to have Client Folder be a variable that will detect what folder the batch script is actually in so I can just through one of the bat files in every sub directory.
I tried %~dp0 which almost does the trick, but outputs the entire path.. I just need the last two directories.
so if %~dp0 = \SERVER-PATH\Content\1CustomerDocs\2017\Client Folder\
I wish I could cut the last two directories off and have a variable that looks like
2017/Client Folder (but also need one that escapes the spaces for linux)
So the end results would look like
#echo off
REM Make environment variable changes local to this batch file
SETLOCAL
REM where ti find rsync and related files
SET CWRSYNCHOME=C:\cwRsync
SET HOME=C:\Users\greg\AppData\Roaming
SET CWORLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
SET CUST_FOLDER_WINDOWS=*YOUR HELP NEEDED HERE*
SET CUST_FOLDER_LINUX=*YOUR HELP NEEDED HERE*
"C:\cwRsync\bin\rsync.exe" -v -e 'ssh -i C:\home\greg\.ssh\id_rsa' --delete --recursive --inplace "/cygdrive/z/1CustomerDocs/%CUST_FOLDER_WINDOWS%" "root#domainname.com:/var/storage/customer_files/%CUST_FOLDER_LINUX%"
And again, I would need the linux folder to escape spaces.
Thanks for the help!
To be independent from the current dirlevel:
#echo off
Echo current dir %CD%
Echo Batch dir %~dp0
for %%a in ("%~dp0.") Do Set "Parent=%%~nxa"
for %%a in ("%~dp0..") Do Set "Grandparent=%%~nxa"
Echo Last 2 dirs \%Grandparent%\%Parent%
current dir Q:\Test\2017\08\10
Batch dir Q:\Test\2017\08\10\
Last 2 dirs \08\10
Figured it how below
#echo off
REM Make environment variable changes local to this batch file
SETLOCAL
REM where ti find rsync and related files
SET CWRSYNCHOME=C:\cwRsync
SET HOME=C:\Users\greg\AppData\Roaming
SET CWORLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
for /F "tokens=5,6 delims=\" %%a in ("%0") do (
"C:\cwRsync\bin\rsync.exe" -v -e 'ssh -i C:\home\greg\.ssh\id_rsa' --delete --
recursive --inplace "/cygdrive/z/1CustomerDocs/%%a/%%b/"
"root#domainname.com:/var/storage/customer_files/%%a/%%b/"
)
Does anyone have any idea on how to force dumpcap to create the directory before it writes in it? I am trying to capture packets for a year, and have a batch file that writes based on the year/month/day/hour, but unfortunately dumpcap doesn’t try and create the directory if it is not there.
Any suggestions?
dumpcap -i 2 -b duration:3600 -P -w D:\pcaps\%year%\%month%\%day%\%HH24%\capture -q
Any help would be appreciated.
(I know I could create all the directories ahead of time, or run it every hour with at/schtasks and create the directory beforehand. Looking for another way.)
Additionally, I found another workaround (This will store the files by hour and I just have a schtask that runs it each hour):
#echo off
For /f "tokens=1-4 delims=/:." %%a in ("%TIME%") do (
SET HH24=%%a
SET MI=%%b
SET SS=%%c
SET FF=%%d
)
mkdir d:\pcaps\%year%
mkdir d:\pcaps\%year%\%month%
mkdir d:\pcaps\%year%\%month%\%day%
mkdir d:\pcaps\%year%\%month%\%day%\%HH24%
"c:\program files\wireshark"\dumpcap -i 2 -a duration:3600 -b filesize:100000 -P -w D:\pcaps\%year%\%month%\%day%\%HH24%\CORP.pcap -q
Does anyone have any idea on how to force dumpcap to create the directory before it writes in it?
No, because there is no way to do that; dumpcap never calls any routines that create a directory for the capture file. The only way to force it to do so would be to change it to do so and recompile it.
I want to learn how to write batch scripts and tried to create a script which automatically runs this command in the command line once:
ping www.google.de -t
and displays the ping, so it would look like this:
Reply from XXX.XXX.X.XX: time=30ms
Reply from XXX.XXX.X.XX: time=31ms
Reply from XXX.XXX.X.XX: time=29ms
My problem is, that this will result in this when I execute this command as script:
My problem is that it will not execute the ping command at all, but just insert the command unlimited times in the console window as its shown in the screenshot.
I just created a new file, wrote ping www.google.de -t in it, saved it as ping.bat file and executed it with double clicking on it.
So how to write the batch file to start this command only once and display the ping result?
I am sure you must have named the resultant bat file as "ping.bat". If you rename your file to something else say pingXXX.bat. It will definitely work. Try it out.
my batch file contains below code only
ping 172.31.29.1 -t
with file name as ping.bat
with file name abc.bat
Enter in a command prompt window ping /? and read the short help output after pressing RETURN. Or take a look on:
ping - latest Microsoft documentation for this Windows command
ping - Windows XP documentation for this Windows command
Explanation for option -t given by Microsoft:
Specifies ping continue sending echo Request messages to the destination until interrupted. To interrupt and display statistics, press CTRL+ENTER. To interrupt and quit this command, press CTRL+C.
You may want to use:
#%SystemRoot%\system32\ping.exe -n 1 www.google.de
Or to check first if a server is available:
#echo off
set MyServer=Server.MyDomain.de
%SystemRoot%\system32\ping.exe -n 1 %MyServer% >nul
if errorlevel 1 goto NoServer
echo %MyServer% is available.
rem Insert commands here, for example one or more net use to connect network drives.
goto :EOF
:NoServer
echo %MyServer% is not available yet.
pause
goto :EOF
For bash (OSX) ping google.com -c 1 (incase search brought you here)
if you want to use the name "ping.bat", a small trick is to use this code:
#echo off
cd\
ping google.com -t
Just add that "cd\" and you are fine... ;)
Not sure exactly what you are trying but your posted code should work just fine. in case you don't want the command to be displayed, add #echo off at starting of your script. If i have the below code in a file named as test.bat and run it command prompt as test.bat it will work just fine.
#echo off
ping www.google.de -t
To address your EDIT: where the main concern is ping command was not recognizable. ping command generally will be located under C:\Windows\System32\ where C:\ being the root directory. In case, the root directory is different you can get the root directory using %SystemRoot% environment variable and can say like
%SystemRoot%\Windows\System32\PING.EXE www.google.de -t
Another way to see if the command you are trying to run is recognizable or not is using WHERE command like below
where ping
If the command is recognizable; it will output the path like
C:\Windows\System32\PING.EXE
Else will result in error
I know why, you are using the file name "ping" and you are using the code "ping", it just keeps trying to run itself because its selected directory in where that file is, if you want it to actually ping, put this before the ping command: "cd C:\Windows\system32", the actual file that pings the server is in there!
From Batch file, ping a ip only once using the following command:
Ping 192.168.199.10 -n 1
i used Mofi sample, and change some parameters, no you can do -t
#%SystemRoot%\system32\ping.exe -n -1 4.2.2.4
The only thing you need to think about in this case is, in which directory you are on your computer.
Your command line window shows C:\users\rei0d\desktop\ as your current directory.
So the only thing you really need to do is:
Remove the desktop by "going up" with the command cd ...
So the complete command would be:
cd ..
ping XXX.XXX.XXX.XXX -t
Having 2 scripts called test.bat and ping.bat in same folder:
Script test.bat contains one line:
ping google.com
Script ping.bat contains below lines:
#echo off
echo Hello!
pause
Executing "test.bat" the result on CMD will be:
Hello!
Press any key to continue . . .
Why? Because "test.bat" is calling the "ping.bat" ("ping google.com" is interpreted as calling the "ping.bat" script).
Same is happening if script "ping.bat" contains "ping google.com". The script will execute himself in a loop.
Easy ways to avoid this:
Do not name your script "ping.bat".
You can name the script as "ping.bat" but inside the script use "ping.exe google.com" instead of "ping google.com".
Create a text file with text "#%SystemRoot%\system32\ping.exe -t www.google.com" and save it with extension ".bat".
Just click and run it and you will get the result.
So basically what happens is that we run ping.exe application with parameters '-t' and 'www.google.com' (web-address).
The answer to your question is this
Ping -n 1 0.0.0.0
But if you want it to be faster than this, this will be your answer
Ping -n 1 -l 1 0.0.0.0
Note: Replace 0.0.0.0 with your desired IP address
Just
write the command "ping your server IP" without the double quote. save file name as filename.bat and then run the batch file as administrator