Sponsored Content
Top Forums Shell Programming and Scripting help with recursive handbrake script Post 302692467 by jonesal2 on Monday 27th of August 2012 04:47:00 PM
Old 08-27-2012
help with recursive handbrake script

I have a batch of mkv video files I would like to transcode to a more compressed format. After spending a significant amount of time experimenting with various parameters I think I have found the handbrake settings that give the best compromise. I now want to construct a simple bash script that will scan the directory containing the original mkv files, recreate the directory tree and then transcode them into the new directory. I then need to alter the file name to replace the underscores with spaces and add the episode number to the beginning based on the original file name.

My original file structure is as follows:

original_series
|
|-series1
| |-episode_1.s01e01.mkv
| |-episode_2.s01e02.mkv
|
|-series2
| |-episode1.s01e01.mkv
| |-episode2.s02e02.mkv

where the s01 represents season 1 and e01 or e02 represent episode in the season as per thetvdb.com. I would like to replicate this directory structure and change the file name to add the season number and episode number to the front of the file based on the sXX and eXX values, so that the new structure looks like:

transcoded_series
|
|-series1
| |-1-1-episode 1.mp4
| |-1-2-episode 2.mp4
|
|-series2
|-1-1-episode 1.mp4
|-2-2-episode 2.mp4

My first attempt looks like this:
Code:
#!/bin/bash

sourcedir="/media/video/original_series"
destdir="/media/video/transcoded_series"
cd "$sourcedir"

for i in *.mkv; do

HandBrakeCLI -i "$i" -o "$destdir/${i%.*}.mp4" -e x264 -q 20.0 -E copy  -B auto -6 auto -R Auto -D 0.0 \
 -f mkv --detelecine --decomb  --loose-anamorphic -m -x b-adapt=2:rc-lookahead=50

done

but it is not recursive, I have no idea how to recreate the directory tree and no idea how to alter the file namesSmilie

I would be really grateful for some (a lot of) help!

Last edited by jim mcnamara; 08-27-2012 at 06:20 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recursive pid script

I'm trying to create a script that allows me to determine all the pid's that spawned from an original process(ie - who's running this command).... I've created a script that searches the processes running based on an argument passed the script. It then is to get the parent pid and look that... (3 Replies)
Discussion started by: jbarnhar
3 Replies

2. Shell Programming and Scripting

Script problem due to recursive directories Help please

Hello everyone , I am looking for a better solution then the one I have created for the my Task The task is: Create an automated script that will check for Uploads in a specified Directory and move them to another specified Directory if the files are completely uploaded. Files are FTP'd to... (2 Replies)
Discussion started by: robertmcol
2 Replies

3. UNIX for Dummies Questions & Answers

Recursive grep

Hello, First time post - I have no formal unix training and could use some help with this. I have a list of strings in File1 that I want to use to do a recursive search (grep) under a specific directory. Here is an example of the string I need to search: /directory/dire... (16 Replies)
Discussion started by: upstate_boy
16 Replies

4. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

5. Shell Programming and Scripting

Recursive Shell script

I'm trying to run the script below recursively but it is generating multiple and simultaneous processes. how do I do to start same script again (last line of my script) only after he had just run entirely? The file name is bachup.sh I am using this command: # / bin / bash / ... (8 Replies)
Discussion started by: sprool
8 Replies

6. Shell Programming and Scripting

Logic needed to recursive looping in the script

Hello i have a requirement where in a file i will get string. The length could be from 1 to 20. if the string is less than 6 characters ( ex: ABCD) . i need to append 'X' on right hand side to make it 6 characters (ex: ABCDXX). if suppose i get the same string from the file as ABCDXX then i... (5 Replies)
Discussion started by: dsdev_123
5 Replies

7. UNIX for Advanced & Expert Users

recursive grep

Hi, on AIX 6.1 , in man document for grep : -r Searches directories recursively. By default, links to directories are followed. But when I use : oracle@XXX:/appli/XXX_SCRIPTS#grep -r subject *.sh It returns nothing. However I have at least one row in a file : ... (3 Replies)
Discussion started by: big123456
3 Replies

8. Shell Programming and Scripting

Help with creating recursive unzip script

Hello. I am trying to create a script that recursively looks at my folder structure, and extracts any .7z files that have not already been extracted yet. I know that all .7z files only have a single .txt file in them, and the only .txt file in any directory would be from that .7z file. I am... (3 Replies)
Discussion started by: Davinator
3 Replies

9. Red Hat

How to solve compiling handbrake errors?

Hello friends, Am trying to compile and build Handbrake 0.9.9 on my redhat box but getting the below errors. Same errors when I compile the source from github and also from the official web site. # uname -a Linux blah.com 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64... (0 Replies)
Discussion started by: prvnrk
0 Replies
MP4TRACK(1)							  MP4v2 Utilities						       MP4TRACK(1)

NAME
mp4track - manual page for mp4track - MP4v2 2.0.0 SYNOPSIS
mp4track [OPTION]... [PARAMETERS]... ACTION file... DESCRIPTION
For each mp4 file specified, perform the specified ACTION. An action must be specified. Some options are not applicable to some actions. ACTIONS --list list all tracks in mp4 --enabled BOOL set trak.tkhd.flags (enabled bit) --inmovie BOOL set trak.tkhd.flags (inMovie bit) --inpreview BOOL set trak.tkhd.flags (inPreview bit) --layer NUM set trak.tkhd.layer --altgroup NUM set trak.tkhd.alternate_group --volume FLOAT set trak.tkhd.volume --width FLOAT set trak.tkhd.width --height FLOAT set trak.tkhd.height --language CODE set trak.mdia.mdhd.language --hdlrname STR set trak.mdia.hdlr.name --udtaname STR set trak.udta.name.value --udtaname-remove remove trak.udta.name atom --colr-list list all colr-boxes in mp4 --colr-add add colr-box to a video track --colr-set set colr-box parms --colr-remove remove colr-box from track --pasp-list list all pasp-boxes in mp4 --pasp-add add pasp-box to a video track --pasp-set set pasp-box parms --pasp-remove remove pasp-box from track PARAMETERS --track-any act on any/all tracks --track-index IDX act on track index IDX --track-id ID act on track id ID --colr-parms CSV where CSV is IDX1,IDX2,IDX3 --colr-parm-hd equivalent to --colr-parms=1,1,1 --colr-parm-sd equivalent to --colr-parms=6,1,6 --pasp-parms CSV where CSV is hSPACING,vSPACING OPTIONS -z, --optimize optimize mp4 file after modification -y, --dryrun do not actually create or modify any files -k, --keepgoing continue batch processing even after errors -o, --overwrite overwrite existing files when creating -f, --force force overwrite even if file is read-only -q, --quiet equivalent to --verbose 0 -d, --debug NUM increase debug or long-option to set NUM -v, --verbose NUM increase verbosity or long-option to set NUM -h, --help print brief help or long-option for extended help --version print version information and exit DEBUG LEVELS (for raw mp4 file I/O) 0 supressed 1 add warnings and errors (default) 2 add table details 3 add implicits 4 everything VERBOSE LEVELS 0 warnings and errors 1 normal informative messages (default) 2 more informative messages 3 everything mp4track - MP4v2 2.0.0 June 2012 MP4TRACK(1)
All times are GMT -4. The time now is 06:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy