Log in

View Full Version : find Linux bash script equivalent to Windows batch file


wiseant
16th September 2023, 20:50
Hi

I have some simple Windows batch files and Linux bash scripts using ffmpeg

I can demux a folder of mp4 files to m4v files in Windows

for %%a in *.mp4 do "c:\ffmpeg\bin\ffmpeg" -i "%%a" -an -c:v copy "%%a.demuxed.m4v"
pause

I can do the same thing in Linux with this bash script

#!/bin/bash
for mediafile in *.mp4; do
ffmpeg -i "$mediafile" -an -vcodec copy "${mediafile%.*}.m4v"
done

However, I have been unable to find a Linux bash script equivalent for

c:\ffmpeg\bin\ffmpeg -i "%~dpnx1" -an -c:v copy "%~dpn1.m4v"
pause

I can drag and drop a mp4 file and demux the video to a m4v file in Windows

%~dpnx1 which expands to the drive, path, name and extension of the first argument

I have searched far and wide and have not found a Linux equivalent for -i "%~dpnx1"

TIA

StainlessS
17th September 2023, 11:42
I aint no linux guy (yet), I forgot everything I did know back in mid 90's -> about 2000.

Method would seem to be reliant upon OS Window Manager and maybe File Manager, so you might wanna say what you are using for better assistance.

Maybe try look here for some clues::

FFMPEG Drag and Drop sh file:- https://stackoverflow.com/questions/67308652/ffmpeg-drag-and-drop-sh-file

Hope you find an answer.

EDIT: Might wanna see this too (I aint watched it) Drag and Drop files to a BASH Shell Script:- https://www.youtube.com/watch?v=gUb5g0J963o
EDIT: Above Youtube guy has lotsa clips on scripting and such.

wiseant
17th September 2023, 18:18
@StainlessS

Thanks for the links

I am on Xubuntu - with xfce4-terminal and thunar file manager

wiseant
17th September 2023, 21:32
Looks like I found a solution

In Linux I created this bash script named audio_video_demux.sh

#!/bin/bash
ffmpeg -i "$1" -vn -acodec copy "${1%.*}.m4a"
ffmpeg -i "$1" -an -vcodec copy "${1%.*}.m4v"
$SHELL

then with a right-click on a video file I use the "Open With" dialog - "Open With Other Application" then "> Use a custom command " and I typed in

/home/unoit/audio_video_demux.sh

the "${1%.*}.m4a" removes the original extension and adds the .m4a extension
the "${1%.*}.m4v" removes the original extension and adds the .m4v extension

I can select one or more video files and it processes them

If i want to see the terminal with the ffmpeg banner and the output I need to drag the bash script to the terminal then drag the video[s] to the terminal