You are not logged in.

#1 2019-09-09 01:26:43

cgc13
New Member
Registered: 2019-09-09
Posts: 1

bash & mkvmerge batch processing

My aim: use mkvmerge to merge .srt subs with either a .avi or mp4. I can do this on mp4 files when all are in the same directory with



#!/bin/sh

for f in *.mp4; do

mkvmerge -o "${f%.mp4}.mkv" "$f" "${f##*.srt}"

done

If possible I would like to do this in one step with either mp4 or avi files. If needed, I can repeat the script to convert avi files.



Question: How can I alter the above to be recursive when movie and the corresponding subs are in separate directories?



Thanks.

CGC

Offline

#2 2019-09-09 05:23:46

malm
jgmenu developer
Registered: 2016-10-13
Posts: 530
Website

Re: bash & mkvmerge batch processing

You could put your for loop inside another for loop which iterates over some directories.

Offline

#3 2019-09-09 07:35:31

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,930
Website

Re: bash & mkvmerge batch processing

As for the first part of the question

#!/bin/bash

# do I need this
shopt -s extglob

# If no specific arguments were passed to script then it will check current dir for
# certain video extensions itself

(( $# )) || set -- *.@(mkv|mp4|avi|mov); [[ -e $1 ]] || { echo "No video files"; exit 1; }

while [ $# -gt 0 ]; do

    echo "$1"

    shift
done

and 2nd, maybe something along

f=woot
find . -name ${f}*.srt
./subs/woot.srt

or again some sort of extended glob.
https://unix.stackexchange.com/question … rsive-glob

shopt -s globstar
f=woot
ls **/*.srt
sub.srt  subs/woot.srt

ls **/${f}*.srt
subs/woot.srt

Last edited by brontosaurusrex (2019-09-09 11:44:59)

Offline

Board footer

Powered by FluxBB