Well, I have such transcoding script:


for a in *$fmt; do 
$vlc -I dummy -vvv "$a" --sout "#transcode{acodec=$acodec,ab=$arate,channels=2}:duplicate{dst=std{access=file,mux=ogg,dst=\"${PWD##*/}/${a%%.*}.$ext\"}" vlc://quit 

But I want to place output files in other separate directory with the same name as source. For example, if I convert all files from folder


I want to place converted files in directory


I've made all possible variations and always get error. With the current (above) variant I get error:

[0xb500abe0] main stream out debug: destroying chain... (name=(null))
[0xb500abe0] main stream out debug: destroying chain done [0xb5000588] main stream output error: stream chain failed for `transcode{acodec=vorb,ab=256,channels=2}:duplicate{dst=std{access=file,mux=ogg,dst="1/Alabama - If You're Gonna Play in Texas (You Gotta Have a Fiddle in the Band).ogg"}'
[0x95be4f8] main input error: cannot start stream output instance, aborting
[0x96985a8] main playlist debug: finished input
[0x96985a8] main playlist debug: dead input

I tried to specify in dst:
1) 1/XXX.ogg
2) /1/XXX.ogg
3) 1\XXX.ogg
4) \1\XXX.ogg
but with no luck...

  • Does the target directory exist? VLC will probably not automatically create it for you. – Daniel Andersson Mar 12 '14 at 18:53

If the output directory does not exist, VLC fails with that exact message.

This is a small expansion of the script. In the current state it takes directories as arguments and loops through them. If no argument is given, it looks for files in the current directory. Output files are written to the home directory, under a subdirectory named as the parent directory of each given file. The output directories are created upon invocation to avoid the error message.

usage() {
    cat <<-USAGE 1>&2
    usage: ${0##*/} [DIR ...]

    optional arguments:
      DIR   directories to search. Use current directory if none are given.
    exit 1

error() {
    printf '%s: error: %s, aborting.\n' "${0##*/}" "$1" 1>&2
    exit $2

transcode_dir() {
    indir=$(readlink -f -- "$1")

    ! mkdir -pv -- "$outdir" && error "cannot create directory \"$outdir\"" 3

    cd -- "$indir"
    for a in *.$fmt; do
        $vlc -I dummy -vvv "$a" --sout "#transcode{acodec=$acodec,ab=$arate,channels=2}:duplicate{dst=std{access=file,mux=ogg,dst=\"$outdir/${a%.*}.$ext\"}}" vlc://quit
    cd - 2> /dev/null

while getopts "h" option; do
    case $option in
        h|\? )  usage;;
shift $((OPTIND-1))


if [ $# -eq 0 ]; then
    transcode_dir .
    while [ $# -ge 1 ]; do
        [ ! -d "$1" ] && error "not a directory: \"$1\"" 2
        transcode_dir "$1"

A lot of lines, but most of it is just pasted boiler-plate code (feel free to ask if any part is unclear). I changed the interpreter to #!/bin/sh since no Bash specific constructs are used. I moved the transcoding part to a function for clarity.

| improve this answer | |
  • Thanks for your help. Does this usual behavior (directories should be created manually) for UNIX-based systems? Or it is VLC specifics? In Windows if destination is specified via slash the directory will be created automatically I know – Suncatcher Mar 13 '14 at 7:13
  • @Dezmond: I think it is quite common for programs to fail if the path is not available. At least they should ask something like "The directory X does not exist, should it be created?" before doing it. That is the way e.g. Windows installers generally solve it; exactly how it is solved on a program to program basis varies. – Daniel Andersson Mar 13 '14 at 7:38
  • Tried your script and it wrote: "Syntax error: end of file unexpected (expecting "}")" – Suncatcher Mar 23 '14 at 16:47
  • @Dezmond: I tried pasting and running it locally, and it worked. Check your pasting again. I'm running it with Dash as interpreter, which quickly breaks on anything non-standard, so I can't currently see where the syntax error could come from if it is pasted correctly. Note though that the script gives unexpected results if there are no matching files in the given directory, but that should make itself clear upon trying. So, write the script to e.g. the file transcoder.sh, make it executable: chmod +x transocer.sh and run it with ./transcoder.sh. – Daniel Andersson Mar 23 '14 at 17:04
  • "No matching files" and "syntax error" are different situations:) Okay, I'll try again soon – Suncatcher Mar 24 '14 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.