prupert
July 20th, 2009, 11:47 AM
Hi there
I'd be very gratefull if someone could help.
I've tried searching, but I can't find search terms that give the answer.
I have created a simple bash script, that converts the .ts and .m2ts files in a folder using handbrake. I then want to use mkvmerge to add chapter information to these mkv files that handbrake creates (so the adverts can be skipped).
In my transcode script I use this line to search for all the mkv files that handbrake has created earlier on in the script:
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec /home/server/scripts/mkvmerge.sh {} \; >> /mnt/media/documents/ruperts/TV/trans.log
In theory, this should find all the .mkv files in the folder and pass them one at a time to my mkvmerge.sh script. This is the contents of the mkvmerge.sh script:
#!/bin/bash
VIDEO=$1
ENC=${VIDEO##*/}
mkvmerge --chapters ${VIDEO%/*}/${ENC%%.*}.chap $VIDEO -o /media/video/Video/TV/${ENC%%.*}.mkv
The "--chapters" switch tells mkvmerge the full filepath and name of the .chap file. Then I pass it the name of the mkv file, and then I tell it where to save the output to with the "-o" switch. The problem I am having is that it isn't passing the full filepath to mkvmerge, as soon as there is a space in the filename, it treats that as the full file path (so it passes /media/documents/Ruperts/TV/The instead of /media/documents/Ruperts/TV/The Big Brother.mkv). I am sure I need to use double or single quotes somewhere, but I am not sure where.
The reason for all the crazy syntax stuff is that the files are named using the following method (a result of the files originally being created on a Windows XP box and being processed by batch script on that machine (as the advert checking software is Windows based)). Say the film is called ROBOCOP.ts, this is converted by Handbrake into ROBOCOP.ts.mkv, thus the chapter marker file is called ROBOCOP.ts.chap. I need to pass both the full path to the mkv file path (from the find command) and also the name of the .chap file as well.
To clarify, I have no problem getting mkvmerge to run, this isn't my issue, the problem I initially seem to have is how to pass the full file path to any program if it includes spaces.
Essentialy the steps I am trying to achieve are:
1) find all the files of type /PATH1/NAME1.mkv
2) for each file of type /PATH1/NAME1.mkv, process them with mkvmerge, also passing files of type /PATH1/NAME1.chap to mkvmerge (the file path and name is the same, except instead of it having a .mkv extention is has a .chap).
Can anyone suggest a solution to my problem, or a more gracefull way to achieve this via bash than using the find --exec command??
I'd be very gratefull if someone could help.
I've tried searching, but I can't find search terms that give the answer.
I have created a simple bash script, that converts the .ts and .m2ts files in a folder using handbrake. I then want to use mkvmerge to add chapter information to these mkv files that handbrake creates (so the adverts can be skipped).
In my transcode script I use this line to search for all the mkv files that handbrake has created earlier on in the script:
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec /home/server/scripts/mkvmerge.sh {} \; >> /mnt/media/documents/ruperts/TV/trans.log
In theory, this should find all the .mkv files in the folder and pass them one at a time to my mkvmerge.sh script. This is the contents of the mkvmerge.sh script:
#!/bin/bash
VIDEO=$1
ENC=${VIDEO##*/}
mkvmerge --chapters ${VIDEO%/*}/${ENC%%.*}.chap $VIDEO -o /media/video/Video/TV/${ENC%%.*}.mkv
The "--chapters" switch tells mkvmerge the full filepath and name of the .chap file. Then I pass it the name of the mkv file, and then I tell it where to save the output to with the "-o" switch. The problem I am having is that it isn't passing the full filepath to mkvmerge, as soon as there is a space in the filename, it treats that as the full file path (so it passes /media/documents/Ruperts/TV/The instead of /media/documents/Ruperts/TV/The Big Brother.mkv). I am sure I need to use double or single quotes somewhere, but I am not sure where.
The reason for all the crazy syntax stuff is that the files are named using the following method (a result of the files originally being created on a Windows XP box and being processed by batch script on that machine (as the advert checking software is Windows based)). Say the film is called ROBOCOP.ts, this is converted by Handbrake into ROBOCOP.ts.mkv, thus the chapter marker file is called ROBOCOP.ts.chap. I need to pass both the full path to the mkv file path (from the find command) and also the name of the .chap file as well.
To clarify, I have no problem getting mkvmerge to run, this isn't my issue, the problem I initially seem to have is how to pass the full file path to any program if it includes spaces.
Essentialy the steps I am trying to achieve are:
1) find all the files of type /PATH1/NAME1.mkv
2) for each file of type /PATH1/NAME1.mkv, process them with mkvmerge, also passing files of type /PATH1/NAME1.chap to mkvmerge (the file path and name is the same, except instead of it having a .mkv extention is has a .chap).
Can anyone suggest a solution to my problem, or a more gracefull way to achieve this via bash than using the find --exec command??