You are not logged in.

#1 2018-01-11 13:46:16

Kino
Member
From: Stockport, UK
Registered: 2016-04-30
Posts: 109

[SOLVED] bash & mkvmerge batch processing

Hi,

I am struggling with bash scripting - I hope someone can straighten me out!

I have a folder with about 24 mp4 files with corresponding subtitles. e.g.

AAA.mp4
AAA.ass
.
.
ZZZ.mp4
ZZZ.ass

and I'm trying to mux them together using mkvmerge as a batch process.

I've searched online for help but nothing I've tried works.

My latest attempt is:

#!/bin/sh

for f in *.mp4; do 

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

done

which gives the error

Error: The name of the output file 'OVA01.mp4' and of one of the input files is the same.
This would cause mkvmerge to overwrite one of your input files.
This is most likely not what you want.

I can't seem to separate the filenames and extensions properly.
Any help would be much appreciated.

Thanks in advance.

Last edited by Head_on_a_Stick (2018-01-12 06:50:31)

Offline

#2 2018-01-11 14:35:52

bigbenaugust
Member
From: unc.edu / the 919 / KIGX
Registered: 2017-05-20
Posts: 95

Re: [SOLVED] bash & mkvmerge batch processing

for f in *.mp4; do 

This is going to take the whole filename. To get rid of the extension, you're going to need something more like:

for f in `ls *.mp4 | cut -d. -f 1`; do

This will take a listing of all of the mp4 files, cut them at the period character, and print only the first field (the filename) and discard the extension.

I am not familiar with mkvmerge, though. But it seems like you are trying for:

mkvmerge -o $f.mkv $f.mp4 $f.ass

or similar.


--Ben
BL / BL Helium / Raspbian / Ubuntu MATE ... and a whole bunch of RHEL boxes. :)

Offline

#3 2018-01-11 14:49:37

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2015-09-29
Posts: 477

Re: [SOLVED] bash & mkvmerge batch processing

@Kino ... this line

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

should be

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

EDIT:
Or even perhaps

mkvmerge -o "${f%.mp4}.mkv" "$f" "${f%.mp4}.ass"

(I'm not familiar with mkvmerge ... I'm only guessing the arguemtns; but '-o' switch is probably output file name.)

Source.

Last edited by iMBeCil (2018-01-11 14:53:00)


Postpone all your duties; if you die, you won't have to do them ..

Online

#4 2018-01-11 15:00:24

Kino
Member
From: Stockport, UK
Registered: 2016-04-30
Posts: 109

Re: [SOLVED] bash & mkvmerge batch processing

Yes - that worked!

Thank you.

Offline

#5 2018-01-11 19:12:19

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2015-09-29
Posts: 477

Re: [SOLVED] bash & mkvmerge batch processing

You're welcome (if the thanks is for me).


Postpone all your duties; if you die, you won't have to do them ..

Online

Board footer

Powered by FluxBB