11

I created a nodejs application hosted on heroku which uses imagemagick. I am doing this operation:

require('child_process').exec(`convert -quiet -delay 1 output.avi ${gif}`);

This should convert output.avi (which is present) to a gif file. In this case, gif is "/app/temp/gifs/xstrycatdq.gif". This command works perfectly on my local windows machine. As I use the path module to get a variable with path.joinand __dirname.

I have installed heroku buildpack:

The error I am receiving is:

Command failed: convert -quiet -delay 1 output.avi /app/temp/gifs/xstrycatdq.gif
convert: DelegateFailed `'ffmpeg' -nostdin -v -1 -vframes %S -i '%i' -vcodec pam -an -f rawvideo -y '%u.pam' 2> '%Z'' @ error/delegate.c/InvokeDelegate/1919.
convert: UnableToOpenBlob `magick-93R4VJcemPz0z1.pam': No such file or directory @ error/blob.c/OpenBlob/2705.
convert: NoImagesDefined `/app/temp/gifs/xstrycatdq.gif' @ error/convert.c/ConvertImageCommand/3257.

It seems that the /tmp/ directory can't be written to or anything. I also tried to mkdir /tmp/ but bash tells me that this dir already exists.

I have also tried changing the imagemagick's temp directory with the environment variable by doing export MAGICK_TMPDIR="temp".

Any help?

Edit: The variables are now absolute.

Tvde1
  • 1,246
  • 3
  • 21
  • 41
  • What does this question to do with `bash`? – Jdamian Jan 17 '18 at 19:22
  • I use the `child_process` module to execute bash commands. – Tvde1 Jan 17 '18 at 19:34
  • I have heard of other cases where Imagemagick will not read from /tmp. I suspect it is done for security, but do not know for a fact. I suggest not putting images there. – fmw42 Jan 17 '18 at 19:59
  • @fmw42 it's not my files, it's IM's temp files. – Tvde1 Jan 17 '18 at 20:07
  • Those files are there when Imagemagick crashes or cannot finish a process. They are then left behind. You should just delete them and redo your process. It is possible they are corrupt, since the process may have aborted and left them in an unfinished state. That may be why they cannot be opened and viewed. – fmw42 Jan 17 '18 at 21:28
  • But my command never completes, that error gets thrown every time. And every time I deploy my app, heroku starts off with an empty /tmp/ folder. – Tvde1 Jan 17 '18 at 22:31
  • ImageMagick is trying to write the gif file to a directory named **gifs** at the same level of the directory you are running the command from. Check you have permissions to create that directory or set your path to /tmp/gifs/your_file.gif – LMC Jan 17 '18 at 23:23
  • I am positive that the `temp/gifs` folder exists. I think the problem is ImageMagick reading from /tmp/. – Tvde1 Jan 20 '18 at 11:27
  • May it happen that there is simply not enough space for the intermediate raw video file (the output of the ffmpeg step)? – Leon Jan 22 '18 at 07:42
  • That's not the problem. If heroku uses more than 512 mb then it'll store your data on a disk and not in ram. – Tvde1 Jan 22 '18 at 07:55
  • 1
    If you are sure about its something to do with '/tmp' can you check whether it has any file attributes with command like 'lsattr -d /tmp' ? And also check 'getfacl /tmp'. Did it throw any clue? – webminal.org Jan 28 '18 at 06:21
  • `isattr` returns this: `-------------e-- /tmp` and `getfacl` cannot be found on heroku. – Tvde1 Jan 29 '18 at 09:44
  • @webminal.org Is that of any help? – Tvde1 Feb 05 '18 at 19:46
  • @Tvde1 those attribute value seem to be fine. Can you check this: https://github.com/ImageMagick/ImageMagick/issues/89 it looks similar to yours. does `whereis ffmpeg` return valid ffmpeg path? – webminal.org Feb 06 '18 at 21:05

1 Answers1

1

Are you sure it's not an issue of permissions? Can you write a simple text file to /app/temp? Is nothing is being read or written at all, it sounds like an issue of permissions. Maybe it's not necessarily a protection design of ImageMagick, but rather heroku or your programming environment?

This directory you're trying to use, it's special in that it contains corrupt or incomplete files - it may have special protections or guards in place, when certain software is running. temp directories are typically designed (or assumed) to be protected from user interference, as they are only to be used and worked with, by the program itself - not the user's commands of the program.

This question is similar to yours, it might be able to help you.

Tanner Babcock
  • 3,232
  • 6
  • 21
  • 23
  • This along with the rest tells me I sould make a folder in my app root (`/app/tmp`). I can do that but I need ImageMagick to also use that folder. This answer is useless. – Tvde1 Jan 29 '18 at 09:40