8
$\begingroup$

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

$\endgroup$
13
  • 1
    $\begingroup$ 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. $\endgroup$
    – C. E.
    Jun 23, 2017 at 11:41
  • 2
    $\begingroup$ I would report it as a bug. $\endgroup$
    – C. E.
    Jun 23, 2017 at 12:18
  • 1
    $\begingroup$ 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 ) $\endgroup$
    – george2079
    Jun 23, 2017 at 20:58
  • 1
    $\begingroup$ 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"]. $\endgroup$
    – Theo Tiger
    Jun 26, 2017 at 19:54
  • 1
    $\begingroup$ 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? $\endgroup$
    – Theo Tiger
    Jun 26, 2017 at 20:02

2 Answers 2

8
$\begingroup$

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."

$\endgroup$
7
  • $\begingroup$ (+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? $\endgroup$ Jun 27, 2017 at 13:12
  • 2
    $\begingroup$ @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. $\endgroup$ Jun 27, 2017 at 20:26
  • 2
    $\begingroup$ @mrz, see also this question $\endgroup$ Jun 27, 2017 at 20:29
  • 1
    $\begingroup$ 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. $\endgroup$ Jul 4, 2017 at 9:23
  • 1
    $\begingroup$ No, I have never had Quicktime installed on this PC. $\endgroup$ Jul 5, 2017 at 10:00
0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.