Hot answers tagged

33

64-bit Windows only Note for Mathematica 11.3: There is a potential conflict between MathMF and the built-in MediaTools package. See here for details and here for an example of how to use MediaTools in place of MathMF.   Note for Mathematica version 10: The Wolfram Library has been updated in version 10 and you will need to recompile the MathMF DLL. ...


28

I built a service connection for this and blogged about it here: Playing with YouTube from Mathematica Here's an example of how this works. Connect to YouTube First install the paclet: PacletInstall["ServiceConnection_YouTube", "Site"-> "http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer/" ] Then connect: $so = ServiceConnect["...


27

Well, I suspect this question will get closed because it is a bit broad, but I've played around with image tracking and thought I'd show what I've done in case it's helpful. I was interested in learning some physics, and have the following video: To do the tracking, I smoothed out the images and converted them to black and white, which allows for the ...


21

The trick is using a combination of "FrameRate", an option of Export, and AutorunSequencing, an option of Manipulate. The former determines the number of frames/second of the movie whereas the latter determines how long a sweep of the control takes. With one control, that will be the length of the movie. Export["output.avi", Manipulate[ Plot[Sin[k x],...


18

(Thanks to K.H. from Wolfram): Even on Windows, if QuickTime is installed, Mathematica uses the native QuickTime install (excluding added, third-party codecs) to import AVI files, and the supported codecs are listed in: Internal`$VideoEncodings (Without an installation of QuickTime, only uncompressed AVI files are supported by Mathematica.) For the ...


15

About: This is my second answer. After playing with Mathematica's video import I have noticed that it makes import mistakes (duplicated frames + artifacts) and thus developed ffmpeg package for Mathematica which is based on ssch answer. https://github.com/kmisiunas/ffmpeg-mathematica The speed of this package is as follows on moderate computer: ...


14

This is a solution specifically using the QTKit library in Mac OS X. I'm calling it through the built-in Python interface, using a script that could also be run as a Python module or in standalone mode. Since the goal here is to make a Mathematica function, I wrapped the call in a Run command inside a function exportMov. This required stuffing the Python ...


13

Since your code is not running due to the lack of trajectory and data it's not possible to give a verified solution, but the tips should help too. What you have to keep in mind is you don't need Animate because to export a movie, you can just give Export a list of images or graphics. Use Table in exact the same way where you have Animate and remove the ...


12

The performance can be improved by loading more than 100 frames at a time. To test this we can run: LoadNFrames[n_] := (Import[video , {"Frames" , Range[1000, 1000 + n]} ]; n); times = Table[ AbsoluteTiming[ LoadNFrames[n] ], {n, {1, 2, 5, 10, 20, 30, 50, 100, 150, 200, 300, 400, 500, 600, 700, 800}}] One can see that in Mathematica there is a ...


12

If you only want to read it linearly you can tell ffmpeg to dump the video to stdout and then read widthheightbytes-per-pixel bytes at a time to get the video frame-by-frame: openVideo[fname_, w_, h_] := Module[{video}, video["stream"] = OpenRead[ "!ffmpeg -i " ~~ fname ~~ " -loglevel quiet -f rawvideo -pix_fmt rgb24 -", BinaryFormat -> ...


11

An almost direct equivalent of shiftdim is Transpose with two arguments: Say, if we have a 3-dimensional array arr, then shiftdim(arr,1) will be the same as Transpose[arr, {3,1,2}] More generally, shiftdim[arr_, k_] := Transpose[arr, RotateRight[Range@ArrayDepth[arr], k]] is completely equivalent to the MATLAB version of the function for any positive k (...


11

In version 11.3 for Windows you can do the following: In[1]:= file = URLSave["http://mirrors.standaloneinstaller.com/video-sample/ Panasonic_HDC_TM_700_P_50i.avi", "c:\\tmp\\sample.avi"]; In[2]:= Needs["MediaTools`"] In[3]:= MediaTools`Private`$MFInitReader[file] Out[3]= True In[4]:= AbsoluteTiming[i = MediaTools`Private`$MFReadNextFrame[];] Out[4]= {0....


9

The question doesn't provide enough specifics to give a very detailed answer but here are a couple of things that might help get you started. First, here I use my webcam's CurrentImage with ColorConvert to create a live grayscale video. Note the semicolon. If you are going to be doing a lot of dynamic video stuff the additional outputs will slow things ...


9

I know halirutan has already provided an answer, but here's a nice way to deal with GIF import in a frame-wise manner (or really in chunks of frames). Mathematica does a very dumb thing when it reads GIFs. It calls the function System`Convert`CommonGraphicsDump`IEImageRead which, if intelligent, would merely process the requested frames. Instead it always ...


8

The option you need is "FrameRate". It's not even necessary to create a list of graphics objects first, as per Sjored's answer.


8

k = Import["traffic.avi", "ImageList"]; a = RandomReal[{0, 1}, 10]; s[n_] := ListLinePlot[a[[1 ;; n]], PlotStyle ->{Thick, White}, PlotRange ->{{1, 10}, {0, 1}}] Table[ImageCompose[k[[n]], s[n]], {n, 10}]


7

So basically ImageCapture[] is the hub where you set things which CurrentImage[] adoptes. Run ImageCapture[] and in-interface select the device - it is easier: Then run your code with CurrentImage[] - it will now pick up the external camera. Droste video-feedback effect you see in the images proves I'm not using my laptop camera in all this ;-) - not that ...


7

There is nice general writeup made by @b3m2a1: Playing with YouTube from Mathematica The "display" part of the question is very easy. In the Cloud version of notebooks which can be accessed here: https://www.wolframcloud.com You can use EmbeddedHTML to embed a video right into a Cloud notebook: EmbeddedHTML[ "<iframe width='854' height='510' src='//...


7

Here is an example of formating the srt file. Since it is a text file, it can be exported using the "String" option: exportRST[path_, string_] := Module[{formateLine, strLs,}, formateLine[str_] := Module[{timePos, times, text}, timePos = StringPosition[str, _ ~~ ":" ~~ _ ~~ _ ~~ "." ~~ _ ~~ _]; times = StringTake[str, #] & /@ timePos; text ...


7

The bad news is that your code spiked at about 60 GB RAM on my machine before the result is returned. The problem is clearly the Import routine. I would like to offer an alternative if you have more than 22 GB of RAM available. data = Import[file, {"GIF", "RawData"}]; This gives you the list of frames. Each frame is a matrix of color-indices. So to ...


6

If you only need to access the video frame by frame you can use ffmpeg to decode the video. Reposting a previous answer: If you only want to read it linearly you can tell ffmpeg to dump the video to stdout and then read widthheightbytes-per-pixel bytes at a time to get the video frame-by-frame: openVideo[fname_, w_, h_] := Module[{video}, video["...


6

In addition to the memory (and slowness) problem, this question combines two other issues that I've thought about before. The problems only arise if the gif files are animations, but the solution could be similar: When importing GIF animation, how to find the correct list of “DisplayDurations”? Does Mathematica support variable frame rate for any video ...


6

You could speed things up by opening the file once for import since you are saving all of the frames. MapIndexed[ Function[{value, index}, Export[StringJoin[outputPath, "image_", PaddedForm[First@index, 4, NumberPadding -> {"0", ""}], ".png"], value, "png"]], Import["F:\\movie.avi", "ImageList"]]; Hope this helps.


6

This is a very empirical answer, so I hope that someone more authoritative will chime in, but here's what I found. I am on Mathematica 10.3.1 on Win7-64bit. I generated a silly animation: a = ExampleData[{"ColorTexture", "GiraffeFur"}]; b = ExampleData[{"ColorTexture", "CatFur"}] // ImageCrop[#, ImageDimensions[%]] &; frames = Table[Blend[{a, b}, x], {...


6

Here's a real quick example that does what you're looking for: Export["test.gif", ImageResize[#,100] & /@ Table[ImageTrim[Import["ExampleData/coneflower.jpg"], {{0,0},{m,m}}],{m,100,50,-5}] , "GIF"] Here we use ImageResize to set the final image size, and use ImageTrim to pick which section of the image you're zooming into. Exporting a ...


5

As some simple comparisons confirm, the main time in creating the images is spent in the Rasterize function and that time has -- not to much surprise -- a quadratical dependence on the image resolution. I have not tested it, but I guess that the Export behaves similar, and of course also the final file size and intermediate memory usage depends on the ...


5

Might as well write my comment as an answer. Exporting a list of frames as a movie usually gives you much more control on the smoothness of the animation you are making. since you have 1000 frames, if we export 1000 frames as a 25 fps, we get a 40 second movie. data = Import[ "http://pastebin.com/raw.php?i=4Tuv8UKv", {"Data", All, {2, 3}}]; ...


5

I present a solution qualitatively similar to belisarius's, but done somewhat differently: (* import an AVI frame-by-frame *) imgs = ExampleData /@ ExampleData[{"TestAnimation", "ToyVehicles"}, "Frames"]; (* some plots *) plots = Table[Plot[Sin[x], {x, -$MachineEpsilon, u}, Axes -> None, Frame -> True, Epilog -> {Directive[...


5

The last example in this talk is processing of a video with irregularly timed frames in order to measure the period of the filmed pendulum. Notebook with code is also available for download. Image Processing: Real-World Applications See my answer to Tracking a point in a video How to make 360 degree videos For correlated frames processing see example in ...


5

You can change the specific functions and speed etc.of course, but how about something like this? im1 = ImageReflect[Import["1.jpg"]]; ima = Raster[ImageData[im1], {{-1.5023, -1}, {1.5023, 1}}]; gif = Table[ Graphics[Scale[Translate[ima, {Sin[a], Sin[Cos[a]]}], Cos[Sin[a]]], ImageSize -> Medium, PlotRange -> {{0, 1}, {0, 1}}], {a, 0, 2 Pi, ...


Only top voted, non community-wiki answers of a minimum length are eligible