add the --output-prefix option
diff --git a/doc/documentation.html b/doc/documentation.html
index b23d76f..d405831 100644
--- a/doc/documentation.html
+++ b/doc/documentation.html
@@ -305,7 +305,15 @@
 				<TT>-o filename</TT>
 			</TD>
 			<TD>
-				Force the output file name (usually <TT><B>flac</B></TT> just changes the extension).
+				Force the output file name (usually <TT><B>flac</B></TT> just changes the extension).  May only be used when encoding a single file.  May not be used in conjunction with <TT>--output-prefix</T>.
+			</TD>
+		</TR>
+		<TR>
+			<TD NOWRAP ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
+				<TT>--output-prefix string</TT>
+			</TD>
+			<TD>
+				Prefix each output file name with the given string.  This can be useful for encoding/decoding files to a different directory.  Make sure if your string is a path name that it ends with a trailing '<TT>/</TT>' slash.
 			</TD>
 		</TR>
 		<TR>
diff --git a/man/flac.sgml b/man/flac.sgml
index a029389..d1c0282 100644
--- a/man/flac.sgml
+++ b/man/flac.sgml
@@ -112,7 +112,20 @@
 		<term><option>-o</option> <replaceable>filename</replaceable></term>
 		<listitem>
 		  <para>Force the output file name (usually flac just
-		    changes the extension).</para>
+		    changes the extension).  May only be used when
+		    encoding a single file.  May not be used in
+		    conjunction with --output-prefix.</para>
+		</listitem>
+	      </varlistentry>
+
+	      <varlistentry>
+		<term><option>--output-prefix</option> <replaceable>string</replaceable></term>
+		<listitem>
+		  <para>Prefix each output file name with the given
+		    string.  This can be useful for encoding/decoding
+		    files to a different directory.  Make sure if your
+		    string is a path name that it ends with a trailing
+		    `/' (slash).</para>
 		</listitem>
 	      </varlistentry>
 
diff --git a/src/flac/main.c b/src/flac/main.c
index f0b3a08..c071e3f 100644
--- a/src/flac/main.c
+++ b/src/flac/main.c
@@ -38,7 +38,7 @@
 FLAC__bool verify = false, verbose = true, lax = false, test_only = false, analyze = false;
 FLAC__bool do_mid_side = true, loose_mid_side = false, do_exhaustive_model_search = false, do_qlp_coeff_prec_search = false;
 FLAC__bool force_to_stdout = false, delete_input = false, sector_align = false;
-const char *cmdline_forced_outfilename = 0;
+const char *cmdline_forced_outfilename = 0, *output_prefix = 0;
 analysis_options aopts = { false, false };
 unsigned padding = 0;
 unsigned max_lpc_order = 8;
@@ -96,6 +96,8 @@
 			delete_input = true;
 		else if(0 == strcmp(argv[i], "--delete-input-file-"))
 			delete_input = false;
+		else if(0 == strcmp(argv[i], "--output-prefix"))
+			output_prefix = argv[++i];
 		else if(0 == strcmp(argv[i], "--sector-align"))
 			sector_align = true;
 		else if(0 == strcmp(argv[i], "--sector-align-"))
@@ -339,6 +341,12 @@
 		else if(format_sample_rate >= 0 && format_sample_rate != 2)
 			return usage("ERROR: --sector-align can only be done with sample rate of 44100\n");
 	}
+	if(argc - i > 1 && cmdline_forced_outfilename) {
+		return usage("ERROR: -o cannot be used with multiple files\n");
+	}
+	if(cmdline_forced_outfilename && output_prefix) {
+		return usage("ERROR: --output-prefix conflicts with -o\n");
+	}
 
 	if(verbose) {
 		fprintf(stderr, "\n");
@@ -586,7 +594,8 @@
 	if(encode_infile == stdin || force_to_stdout)
 		strcpy(outfilename, "-");
 	else {
-		strcpy(outfilename, infilename);
+		strcpy(outfilename, output_prefix? output_prefix : "");
+		strcat(outfilename, infilename);
 		if(0 == (p = strrchr(outfilename, '.')))
 			strcat(outfilename, ".flac");
 		else {
@@ -637,7 +646,8 @@
 		strcpy(outfilename, "-");
 	else {
 		const char *suffix = suffixes[analyze? 2 : format_is_wave? 0 : 1];
-		strcpy(outfilename, infilename);
+		strcpy(outfilename, output_prefix? output_prefix : "");
+		strcat(outfilename, infilename);
 		if(0 == (p = strrchr(outfilename, '.')))
 			strcat(outfilename, suffix);
 		else {