ImageMagick only capturing first frame of mp4 video - imagemagick

All of a sudden, ImageMagick has started only grabbing the first frame of a video file, no matter what slide number I pass into the array. If I select a range, it does output all screenshots as jpgs in that range. Normally this wouldn't be an issue but our company's videos always have a one-two second delay so all I'm getting is a white or black background in my output.
I am using ImageMagick-7.1.0-Q16-HDRI on Windows 10, running from a command prompt. Here is my command:
magick.exe "\localfolder\somevideo.mp4[30] -resize 128x128> -border 1 \localfolder\outputfolder\outputimage.jpg", 0, True
Anyone else ever see this issue?

Related

ImageMagick convert from pdf to image shrinks image and places it in bottom left corner

I am using this command to convert pages from a pdf to jpeg images:
magick convert -density 300 sample.pdf output.jpeg
I see a white background and the content of the PDF appears as a smaller image stuck to the bottom left corner of the white "canvas". Can anyone help with why this might be happening and how to prevent this "shrinking"?
My PDF has 14 pages. Here is the metadata for a few of those pages:
>magick identify sample.pdf
sample.pdf[0] PDF 2286x3600 2286x3600+0+0 16-bit sRGB 6458B 0.016u 0:00.017
sample.pdf[1] PDF 2286x3600 2286x3600+0+0 16-bit sRGB 6018B 0.016u 0:00.020
sample.pdf[2] PDF 2286x3600 2286x3600+0+0 16-bit sRGB 5732B 0.016u 0:00.023
And here are the actual and expected outputs for one of the pages:
actual output:
expected output:
edit: here is a sample PDF:
https://www.dropbox.com/s/0bzu5brfzbedd7i/sample.pdf?dl=0
I am not sure why you have that behavior. There is something in the PDF, perhaps a crop box, that Imagemagick/Ghostscript is not picking up. But you can get rid of the excess white using -trim
magick sample.pdf -trim sample_%d.jpg
Thanks for the example
> magick identify sample.pdf
> sample.pdf[0] PDF 2286x3600
Apears to be wrong as there is no match
from the PDF contents
/Width 1531
/Im0
/Height 2454
/MediaBox [0 0 1531 2454]
on
Page Size:
/CropBox [0 0 919 1473]
919 pt x 1473 pt
32.42 x 51.96 cm
12.76 x 20.45 inches
Therefore no problems when the images were inserted as # 120 dpi
We can check the image by copy when zoom to 100% in a viewer and paste into say paint, which agrees the image is 1531 x 2454 pixels.
As a result of comments with #fmw42, it was decided to see if GhostScript (which ImageMagick depends on for PDF handling) was having an affect, and certainly processing that PDF using GS v 9.55 without any special switches gave warnings and produced the output below left So the issue seems to be caused by recent GhostScript method of calling/scaling. since using simple GhostScript based image apps (Irfanview using GS plugin on the left) behave the same whilst other viewers have less of a problem even sister product MuPDF as previewed on the right. So the file Media Box as seen and probably used for scaling by Ghostscript seems to be the culprit, but was processed by two other PDF handlers during generation.
One solution would be to use a simpler method of extracting images as PNG thus look at Xpdf command line tools "pdftopng" which gives a good result but you need to calculate that the optimum resolution in this case is 120 (or 240), Typical windows command line does not need .exe but its best to use that when prefixing with a path for use from another location.
pdftopng.exe -r 120 -f 1 -l 1 sample.pdf

How to remove antialias edge in ImageMagick when converting to a binary bitmap?

We're doing a cognitive experiment that requires flashing 480 black-and-white images at high speed against a neutral-gray background. The image shown is detail at about 300% zoom; the full display is 932 x 612; there are actually other clusters similar to this one elsewhere on the screen.
We have to generate these images in a source app and later display them in the experimental app. At first, we were using 24-bit PNG's with the background color built in, but despite the size of each file hovering around 10KB, the total file payload of 480 is too large and takes way too long to preload. We can, however, set a default background color in the app and put up 1-bit images. Although we can change the background color in the source application, we don't have control over bit depth there, so we are stuck generating screen captures and then downsampling to binary. We have tried this with original images that sit on both a white background and the gray background. Using ImageMagick, both of these commands yield similar results:
magick gray.png -transparent "rgb(192,192,192)" -alpha set -depth 1 out\gray-out.bmp (or .png)
magick white.png -transparent white -alpha set -depth 1 out\white-out.bmp (or .png)
The PNGs are coming out to 1.5K to 5K, so this is where we want to be. However, we're stuck with that problem aliased edge whether we start with gray- or white-background images. We've also tried the -fuzz argument (1-99%) to no effect. The resulting pseudoalias artifact that we see in these 1-bit files is the same in multiple apps, so apparently it must be built into the output file generated by ImageMagick's attempt to filter the edge, and not an artifact of any single app or the OS.
We don't quite get how an alpha channel can even be attached to a 1-bit image if it is not strictly RGBA: an alpha channel with a 1-bit image doesn't even make sense. But if an alpha channel isn't being included, then where is the map coming from in a nonbinary image to distinguish that "white" edge from a nonwhite surface? It's not the destination apps. The output files must either not be strictly binary, or else ImageMagick is not computing the channel exactly to the contour edges. (When we remove the -alpha argument, ImageMagick generates a larger file; the aliasing (e.g., when we place into PowerPoint and select Transparent Color to white) may appear in slightly different places, but the effect is essentially the same.
The question is, how is it possible to remove this artifact in a 1-bit image using ImageMagick? We'd like to get the file sizes down to the minimum.

ImageMagick convert is not creating an animated gif

I have a folder containing a series of PNG files named forGif001.png forGif002.png ... and I am trying to convert them to an animated gif. The command I am using is magick convert -delay 1000 *png -loop 0 newGif.gif where the delay value is supposedly in milliseconds (a delay of 1000 being 1 second therefore) but I have tried it with smaller values such as 1 just to be safe. However, the gif it creates is just a still image of forGif001 and it never cycles to any of the following pictures. I am not getting any errors or warnings. I installed image magick a few hours ago so I imagine the issue is not stemming from an outdated version.

ImageMagick command to strip ICC color profiles

I have ~500 images that all seem to have a color profile on them; as when I upload to Shopify it changes the color tone of the images. This is due to Shopify stripping out the color profile on upload as per this link:
https://help.shopify.com/themes/customization/colors-images-and-video/fix-colors-of-uploaded-images
I have tried to use ImageMagick to strip out all the color profiles: mogrify +profile "-strip" *.jpg and this noticeably changes the image color which I can see on the image thumbnail but when I try uploading to Shopify the color is still being changed.
What am I doing wrong with ImageMagick? Or maybe it's not a color profile that needs removing?
I have also tried this on Photoshop using 'Save for Web', and this method strips out the color profile, but I don't want to do this for ~500 images, and File > Automate > Batch in CS6 doesn't have any Action for Save For Web. Can this be automated? I am running Windows.
Thanks
Original: http://imgur.com/3lcuZVy
Shopify: http://imgur.com/ko2bQvg
Photoshop: http://imgur.com/Ez3bNT4
EDIT:
I have run ImageMagick identity on the image 3 times. On the original image, on the image after upload to Shopify, and then 'save image as' and again after doing save for web on Photoshop
http://pastebin.com/710fHhJ0
Observations:
Original image: CMYK, ColorSeparation
Shopify image: sRGB, TrueColor
Photoshop image: sRGB, TrueColor
So after another ~hour of playing around I looked into Photoshop Automation. Turns out you can record your own macro and play it back. I wasn't aware you could record your own hence trying to play around with ImageMagick and this question.
For those who may stumble across this:
Window > Actions
[pops up on the toolbar]
Click the folded paper (New Action)
The record (circle) should now change to Red, it is recording.
Carry out your action, e.g mine was to go to File>Save for Web>click OK
Once finished your repetitive task, click the Stop button (square)
Now use your new recorded action, File > Automate > Batch
Unfortunately, this doesn't help those trying to do Save For Web using ImageMagick only.

Converting a multi page pdf to multiple pages using a single command

I want to convert multi page pdfs into single page images efficiently.
I already know how to do this one page at a time with imagemagick. For example,
convert x.pdf[2] x3.jpg
will give me the 3rd page of the pdf as an image. So if I figure out how many pages are in the pdf using identify then I can loop through and convert all pages in the pdf to images. This method can however take a while. For example a 15 page pdf could take anywhere between 15-30 seconds.
According to answers that I have seen elsewhere (also on the imagemagick forums) the following imagemagick command should split a pdf into multiple images.
convert x.pdf x-%0d.jpg
but all this ends up doing is creating the first page named x-0.jpg
As an alternative I have tried using pdftk with the burst capability. The problem I faced there is that burst does not work in all cases. It does for some pdf's and does not for some others.
Any suggestions on how to improve things would help.
My OS is Mac OSX Lion but I do need this working on CentOS 6 as well.
You're missing the quantity of digits. Use:
convert x.pdf x-%04d.jpg
Where 4 means 4 digits will be show on the page count.
If you use Graphicsmagick on Debian or ImageMagick on macOS you probably have to add ADJOIN to your command.
So it should look like
convert x.pdf +adjoin x-%04d.jpg
When I tried to convert my multi-page pdf, the resulting image files had a gray background despite the pdf having a white background. (#John P commented on it on the accepted answer, but I couldn't get his comment to directly work for me.)
Here's what worked for me to make the background white:
convert -authenticate yourpassword -background white -alpha remove -alpha off -density 300 -quality 80 -verbose "Your file.pdf" "Your file.png"
My pdf had a password hence the authenticate.
You can see a summary of the options here:
-authenticate value decipher image with this password
-background color background color
-alpha on, activate, off, deactivate, set, opaque, copy", transparent, extract, background, or shape the alpha channel
-density geometry horizontal and vertical density of the image
-quality value JPEG/MIFF/PNG compression level
-verbose print detailed information about the image
More detail: https://imagemagick.org/script/convert.php
And the alpha remove option: http://www.imagemagick.org/Usage/masking/#alpha_remove
Ran into the same issue. Reinstall Imagemagick to work in Mountain Lion. If you use brew the simply
$brew unlink imagemagick
$brew install imagemagick

Resources