Hot answers tagged

34

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


29

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


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


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: Importing ...


14

This bug has been fixed by a paclet update. This would be applied automatically whenever the functionality is used in a new kernel (as long as the paclet manager has updated its local site index, which typically happens once per session). To force an immediate installation, evaluate PacletSiteUpdate /@ PacletSites[]; PacletInstall["FFmpegTools"] which ...


13

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


13

Easy! Just set Progress`$ConsoleSupport=True. You can set this in your init.m and have it always on. Now, the usual word of warning about undocumented functionality: it may change or break in the future, erase your hard-drive, or cause a global pandemic. Use with appropriate caution. Why did we hide such an awesome feature behind a flag? Because we didn'...


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


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

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

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

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

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

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], {...


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

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

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

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

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

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 did an implementation for capturing from an RTSP using FFMPEG (via RunProcess): capture = CaptureFromIPCamera[ "D:\\ffmpeg\\bin\\ffmpeg.exe", "rtsp://10.6.149.218/live.sdp" ] You can get this function from my Prototypes paclet: PacletInstall @ "https://github.com/arnoudbuzing/prototypes/releases/download/v0.2.9/Prototypes-0.2.9.paclet" Or, if you ...


5

I've found that giving the option "AnimationDuration"-> (seconds) in the Export function gives better results generally.


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

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

Here's one thing that might ease the pain a little: calculate and save the images in the movie one by one, saving them all to a directory. Once done, read them all back in and export to the movie. The first step is something like: Do[thisImg = (* define your images here *); Export[path ~~ folder ~~ ToString[PaddedForm[r, {4, 2}]] ~~ ".jpg", thisImg]...


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


5

Solution with MathMF from Simon Woods (here and here): The code for sequentially reading images of an avi movie is very fast. Needs["MathMF`"]; MFInitSourceReader[avifile]; numberImages = Length@Import[avifile, "Frames"]; Do[ image = MFGrabFrame["ByteImage"]; (* additional code *) , {i, 1, numberImages} ]; ...


5

In my comment, I pointed to how exiftool and ffprobe can be used to read the frame count. Apparently, VirtualDub can too. But, it turns out, these tools aren't doing anything we can't also do easily in Mathematica. The AVI metadata header is documented e.g. here. What this says is that we can retrieve the metadata by reading the bytes at the beginning of the ...


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