0

I have 2 preset .json files(from the GUI version on windows) to convert mkv to mp4.

  1. converts to h264 and adds subtitle 1
  2. converts to h264

I'm only trying to get no.2 to work at this stage.

for i in `*.mkv`; do HandBrakeCLI --preset-import-file HPRESET.json -Z "MYPRESET" --output *.mp4; done no output name

HandBrakeCLI -i $1 --preset-import-gui HPRESET.json -Z "MYPRESET" --output $1.mp4

errors on output name

for i in `*.mkv`; do HandBrakeCLI --title $i --preset "Very Fast 1080p30" --output *.mp4; done

errors on output name AND not valid preset.

$ for i in `seq 4`; do HandBrakeCLI --input /dev/dvd --title $i --preset Normal --output NameOfDisc_Title$i.mp4; done copied this from another stackoverflow question, but outputs as 1.mp4 and then 2.mp4 etc.

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
Michaelp
  • 31
  • 3

1 Answers1

1

You can extract the filename without extension with something like that:

noext=${i%.*}

Example:

╰─$ for i in *.mkv; do echo "$i"; noext=${i%.*}; echo "$noext"; done
asdf.mkv
asdf
test.mkv
test

Same loop, different notation:

for i in *.mkv
do
    #put the commands you want to run after "do" and before "done"
    echo "$i"
    noext=${i%.*}
    echo "$noext"
done

Note that the for command will search any file in the current directory ending with .mkv. For each file it has found, it will save the files name into the variable $i, then execute the commands after do, then save the next files name into the variable $i and execute the commands between do and done. It will repeat that cycle until every file which has been found is processed.

As I have no experience with handbrake presets, here a solution with ffmpeg:

for i in *.mkv
do
    #put the commands you want to run after "do" and before "done"
    noext=${i%.*}
    ffmpeg -i "$i" -c:v libx264 -c:a copy -c:s copy "$noext.mp4"
done 
mashuptwice
  • 640
  • 3
  • 18
  • thats but didnt end up helping. it only echos the name, but even trying `for i in noext=${i%.*}; do HandBrakeCLI --input /www/video --preset-import-file HPRESET.json -Z "MYPRESET" --output $noext.mp4; done` or many other variations still wont work – Michaelp Apr 04 '22 at 10:38
  • @Michaelp I am not sure if you understand how a `for` loop works, maybe you should start by learning the [fundamentals of a for loop in linux](https://bash.cyberciti.biz/guide/For_loop). – mashuptwice Apr 04 '22 at 16:37
  • 1
    your edit works perfectly(for both). thank you so much – Michaelp Apr 07 '22 at 13:10