Changes

Jump to navigation Jump to search
no edit summary
convert myfile.pdf p_%03d.jpg
</texcode>
will convert the 300 pages of `myfile.pdf` to 300 images named `p_000.jpg`, `p_001.jpg`, ..., `p_299.jpg`. The next step is to assemble the images into a movie, which is done with the free ``''ffmpeg`` '' (https://ffmpeg.org) tool. The command
<pre>
ffmpeg -y -r 30 -i JPGdir/p_%03d.jpg -c:v libx264
</pre>
will assemble the JPG files at a framerate of 30 images per second (option \type{`-r 30}`) into a QuickTime MP4 movie named \type{''myMovie.mp4}''.
[[File:Project1-A.mp4]]
For an overview, here's the complete script for a Unix-like system. After producing the PDF with Context (line 1), we create a temporary folder named \type{`JPGdir} ` (line 2), convert the PDF to a series of JPG images in the created folder (line 3), create a QuickTime MP4 movie from the JPG images (lines 4-5), clean up (line 6), and finally, open the movie (line 7) :
<pre>
</pre>
A note about the definition of the picture: although the conversion from PDF to JPG could be made at any resolution with ImageMagick, the default density is 72 dpi. This means that if the size of the PDF page is 15 inches by 15 inches (equivalent to 1080 pixels by 1080 pixels, or 38.1 cm by 38.1 cm at a definition of 72 dpi), the resulting image will also be 1080 pixels by 1080 pixels. Therefore, if the intention is to create a UHD video, add the following line at the end of the code (line 18before the `\stopMPpage`):
<pre>
</pre>
The number of frames needed for a movie can be large. For example, consider a five-minute movie at 30 frames per second: we would need 5 x 60 x 30 = 9,000 frames. If there are a lot of calculations for each frame, this could pose an issue. Therefore, during development, it could be useful to speed up the the processes : sometimes, it's possible to speed up or adjust the timing. For instance, assume the loop instruction `currentframe := #1;` in the preceding code at line 12 is changed to:
<texcode>
currentframe := (#1-1)*100 ;
</texcode>
The first page of the file will correspond to frame 1, the second to frame 100, the third to frame 200, and the last one, the fourth, to frame 300. This allows us to obtain a rough idea of the movie without generating every single page. However, as will become clear later, this approach is not always feasible.
36

edits

Navigation menu