diff --git a/libavcodec/xvidff.c b/libavcodec/xvidff.c
index 70f744f5e8fd480f2e7cb03b10977dcb688c01f8..b46b5e3093bbef81eda9e4b2ec34f2ee8915cea2 100644
--- a/libavcodec/xvidff.c
+++ b/libavcodec/xvidff.c
@@ -234,6 +234,10 @@ int ff_xvid_encode_init(AVCodecContext *avctx)  {
         }
         strcpy(x->twopassfile, "/tmp/xvidff.XXXXXX");
         fd = mkstemp(x->twopassfile);
+        if(fd < 0){
+            strcpy(x->twopassfile, "./xvidff.XXXXXX");
+            fd = mkstemp(x->twopassfile);
+        }
         if( fd == -1 ) {
             av_log(avctx, AV_LOG_ERROR,
                 "XviD: Cannot write 2-pass pipe\n");