diff --git a/remux.c b/remux.c
index bd18c718b3d43cd536c0bb68835fb1226b3685eb..9ada5392d695b12639b2b8f3174f86cf95144896 100644
--- a/remux.c
+++ b/remux.c
@@ -8,9 +8,15 @@ static AVRational chapter_time_base = {1, 1};
 
 void parse_dict(AVDictionary **d, char *s)
 {
+	char *val;
 	char key[JSTR_SIZE], value[JSTR_SIZE];
 	for (s = jenter(s); s; s = jnext(s))
-		av_dict_set(d, jstrb(s, 0, key), jstrb(jvalue(s), 0, value), 0);
+	{
+		if (val = jstrb(jvalue(s), 0, value))
+			av_dict_set(d, jstrb(s, 0, key), val, 0);
+		else
+			av_dict_set_int(d, jstrb(s, 0, key), jint(jvalue(s), 0), 0);
+	}
 }
 
 void parse_chapters(AVFormatContext *ctx, char *s, int duration)
@@ -42,6 +48,7 @@ int main(int argc, char *argv[])
 	AVFormatContext *demux, *mux;
 	AVPacket pkt;
 	AVStream *stream;
+	AVDictionary *muxopts;
 	if (argc != 5)
 		return 1;
 	av_register_all();
@@ -59,7 +66,7 @@ int main(int argc, char *argv[])
 	if (avformat_open_input(&demux, path, 0, 0))
 		goto fail;
 	avformat_find_stream_info(demux, 0);
-	avformat_alloc_output_context2(&mux, 0, 0, path);
+	avformat_alloc_output_context2(&mux, 0, jstr(jlookup(argv[4], "format"), 0), path);
 	av_dict_copy(&mux->metadata, demux->metadata, 0);
 	parse_dict(&mux->metadata, jlookup(argv[4], "metadata"));
 	parse_chapters(mux, jlookup(argv[4], "chapters"), av_rescale_q(demux->duration, AV_TIME_BASE_Q, chapter_time_base));
@@ -80,7 +87,9 @@ int main(int argc, char *argv[])
 		mux->streams[i]->time_base = demux->streams[i]->time_base;
 	}
 	avio_open(&mux->pb, tmp, AVIO_FLAG_WRITE);
-	if (avformat_write_header(mux, 0) < 0)
+	muxopts = 0;
+	parse_dict(&muxopts, jlookup(argv[4], "options"));
+	if (avformat_write_header(mux, &muxopts) < 0)
 		goto fail;
 	while (!av_read_frame(demux, &pkt))
 	{