8

Here is an avi movie (204*432 Pixels) which contains 22 different images with numbers from 1 to 22. I tested e.g. with VirtualDub and MATLAB that all extracted images are different.

Movie: https://drive.google.com/open?id=0B9wKP6yNcpyfUE1hb0UyNXhDRFk

(5.5MB)

When I extract the images with the mathematica code below image 20 is same as image 19. All the rest is correct.

The two same images are seen here:

Import[avifile, {"AVI", "ImageList", Range[19, 20, 1]}]

enter image description here

The error occurs due to the non integer FrameRate:

Import[avifile, {"FrameRate"}]

15.7143

VirtualDub and other software do not care about the frame rate. They simply extract sequentially image by image and the result is corrrect:

{Import["virtualdub_000019.png"], Import["virtualdub_000020.png"]}

enter image description here

Do you know a solution for mathematica?

My code for extracting grayscale images is:

avifile = "20170623_movie_for_testing_duplicate_images.avi";

numberImages = Length@Import[avifile, "Frames"]

22

Do[

  image = ColorConvert[Import[avifile, {"Frames", i}], "Grayscale"];

  fileNameCounter = ToString@PaddedForm[i, 6, NumberPadding -> {"0", ""}];

  Export[StringJoin[fileNameCounter, ".png"], image];

  , {i, 1, numberImages}

  ];

For comparison here are all extracted

mrz
  • 11,686
  • 2
  • 25
  • 81
  • 1
    I tried extracting the frames with ffmpeg as well, and that also shows that image 19 and 20 are not the same. Despite what Mathematica thinks. – C. E. Jun 23 '17 at 11:41
  • But why is mathematica doing something different with frame 20? All other images are the same as extracted with VirtualDub and probably also with ffmpeg. – mrz Jun 23 '17 at 12:13
  • 2
    I would report it as a bug. – C. E. Jun 23 '17 at 12:18
  • @C. E. The error with mathematica occurs due to the non integer FrameRate. – mrz Jun 23 '17 at 12:50
  • ok, nice that you figured it out. – C. E. Jun 23 '17 at 16:31
  • 1
    can you import all, Import[avifile,"ImageList"] and extract the frames you want with Part ? (That will likely be faster anyway unless the file is too big to load in memory all at once ) – george2079 Jun 23 '17 at 20:58
  • @george2079: Unfortunately this does not help. See: http://imgur.com/gallery/mQyAM – mrz Jun 26 '17 at 06:33
  • 1
    This is NOT the case with Mathematica 9.0.1.0 (Win7 64-bit). In 9.0.1, I get the correct sequence of images from 1 to 22 with Import[..., "ImageList"]. – Theo Tiger Jun 26 '17 at 19:54
  • 1
    Not with 11.0.1.0 either... I cannot confirm what you have observed. I do not know how Mathematica handles the import of video files. Can it be a codec issue? – Theo Tiger Jun 26 '17 at 20:02
  • 1
    I get the expected output with Mathematica 11.1.1, 11.0.1, 10.4.1 and 8.0.4 on Windows 7 x64. Which OS/ Mathematica version do you use? – Alexey Popkov Jun 27 '17 at 01:02
  • Thank you to everybody. I am using Window 10 Pro (64Bit), Mathematica 11.1.1. Could you please show me exactly the code you used for the test, so that I can check it? If I don't succeed, would it be possible to chat with you? I have also a Mac and will make the test there (will let you know). – mrz Jun 27 '17 at 06:46
  • Test with my mac (macOS Sierra, 10.12.5, Mathematica 11.1.1): still the same problem. I downloaded the video from link (in the question) and used the code shown here: http://imgur.com/8nvUeZq. What am I doing wrong? – mrz Jun 27 '17 at 07:07
  • 1
    I get the correct output with Mathematica 11.1.1 on Windows 10 (64 bit). I used the exact code you showed in your linked image. – Simon Woods Jun 27 '17 at 09:04

2 Answers2

8

Solution:

The error described below has nothing to do with mathematica (as you veryfied it) but with Quicktime. Mathematica used the Quicktime decoder which produced the mistake. Quicktime extracts image 20 as beeing the same as image 19.

After deinstalling Quicktime mathematica extracts the images correctly.

Thanks to everybody, especially for the hint of Theo Tiger who wrote: Can it be a codec issue?

See also these links:

https://github.com/SimonWoods/MathMF/

https://github.com/kmisiunas/ffmpeg-mathematica

"Mathematica's (v9 or v10) default methods uses QuickTime that produces artifact in uncompressed videos or duplicated frames."

mrz
  • 11,686
  • 2
  • 25
  • 81
  • (+1) Do you know which decoder Mathematica uses by default (when the Quicktime decoder isn't installed)? Is there an option which allows to control this behavior? – Alexey Popkov Jun 27 '17 at 13:12
  • 2
    @AlexeyPopkov if Quicktime isn't available Mathematica (11.1.1 on Windows) uses a Java class System.Convert.MovieDump (see the definition of System`Convert`MovieDump`MovieImport). It looks like it's based on the out-of-date Java Media Framework. You could probably override System`Convert`MovieDump`QuickTimeInstalledQ[] to bypass Quicktime. – Simon Woods Jun 27 '17 at 20:26
  • 2
  • @Simon Woods. Thanks dor the link. I tried to use MathMF, but I am not able to read the movie. Did you try it? – mrz Jul 04 '17 at 08:06
  • 1
    To answer both questions, yes I tried it with Import and with MathMF. Both worked as expected, here is a screenshot. I do not have Quicktime installed. – Simon Woods Jul 04 '17 at 09:23
  • 1
    No, I have never had Quicktime installed on this PC. – Simon Woods Jul 05 '17 at 10:00
  • @Simon Woods: I tested MathMF with avi files of about 100 GB size - it works excellent - see also https://mathematica.stackexchange.com/questions/149269/cannot-read-in-a-movie-as-a-list-of-images . – mrz Jul 05 '17 at 12:15
0

I got today (2017/11/10) the following email from Wolfram Technical Support:

In Jul 2017 you reported an issue with Mathematica wherein importing some uncompressed AVI files failed on Windows. We believe that the issue has been resolved in the current 11.2 release of Mathematica.

Thank you for your report and we look forward to a continued, productive relationship with you.

And indeed the following code in version 11.2.0.0 produces the correct result:

Import[avifile, {"AVI", "ImageList", Range[19, 20, 1]}]

enter image description here

mrz
  • 11,686
  • 2
  • 25
  • 81