2

I want to convert a .ppt to .mp4 file with a script. Is this possible, if yes how can I start ?

Thanks for Ideas...

I know I can export directly over Microsoft Powerpoint but I want a script which does it by himself.

kemal uluz
  • 29
  • 2

1 Answers1

3

First, install the following packages:

sudo apt update
sudo apt-get install unoconv ffmpeg imagemagick

Next, convert the ppt to pdf using the following command:

unoconv -f pdf filename.ppt

where you should replace filename.ppt with the actual file name of the power point presentation.

Then, convert the pdf to individual png files using imagemagick:

convert -density 400 filename.pdf picture.png

Again, replace filename.pdf with the actual filename of the pdf file when you run the command. Multiple png files will be automatically indexed by number.

Finally, run the following command to automatically convert the png files to an mp4 video:

ffmpeg -r 1/10 -i picture-%01d.png video.mp4

This is just a general explanation for the last command. Visit How To Create A Video From PDF Files In Linux - OSTechNix for more information. For example, the 1/10 specifies 10 seconds per image. Also, picture-%01d.png will work with under 10 image files. For more than 9 but less than 100 files, you would use picture-%02d.png instead. For more than 99 but less than 1000 files, use picture-%03d.png etc.


EDIT:

If you get a convert error see here and here or run the following command:

sudo sed -i 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/;s/1GiB/4GiB/' /etc/ImageMagick-6/policy.xml

EDIT EDIT:

If you are having trouble playing the video, install the following packages:

sudo apt update
sudo apt install ubuntu-restricted-extras gir1.2-gstreamer-1.0 gstreamer1.0-alsa gstreamer1.0-clutter-3.0 gstreamer1.0-crystalhd gstreamer1.0-doc gstreamer1.0-espeak gstreamer1.0-fluendo-mp3 gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-libav gstreamer1.0-libav-dbg gstreamer1.0-nice gstreamer1.0-omx-bellagio-config gstreamer1.0-omx-generic gstreamer1.0-omx-generic-config gstreamer1.0-packagekit gstreamer1.0-plugins-bad gstreamer1.0-plugins-bad-doc gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-base-dbg gstreamer1.0-plugins-base-doc gstreamer1.0-plugins-good gstreamer1.0-plugins-good-dbg gstreamer1.0-plugins-good-doc gstreamer1.0-plugins-ugly gstreamer1.0-plugins-ugly-dbg gstreamer1.0-plugins-ugly-doc gstreamer1.0-pocketsphinx gstreamer1.0-pulseaudio gstreamer1.0-qt5 gstreamer1.0-rtsp gstreamer1.0-rtsp-dbg gstreamer1.0-tools gstreamer1.0-vaapi gstreamer1.0-vaapi-doc gstreamer1.0-x libgstreamer-gl1.0-0 libgstreamer-plugins-bad1.0-0 libgstreamer-plugins-base1.0-0 libgstreamer-plugins-good1.0-0 libgstreamer1.0-0 libgstreamer1.0-dev libgstreamermm-1.0-1 libreoffice-avmedia-backend-gstreamer

Also, I tested this using the totem media player so you might want to try using that player:

sudo apt update
sudo apt install gir1.2-totem-1.0 gir1.2-totemplparser-1.0 libtotem-plparser-common libtotem-plparser-videosite libtotem-plparser18 libtotem0 totem totem-common totem-plugins
mchid
  • 42,315
  • 7
  • 94
  • 147
  • How can I change the policy because the operation is not allowed if I type convert -density ..... – kemal uluz Jul 06 '21 at 09:12
  • Ok. Policy done. Problem now is that the terminal is given an error by initializing at output stream .. maybe incorrect parameters such as bit_rate......and so on – kemal uluz Jul 06 '21 at 09:30
  • Is it a [cache error](https://stackoverflow.com/questions/31407010/cache-resources-exhausted-imagemagick)? If so, run `sudo sed -i 's/1GiB/4GiB/' /etc/ImageMagick-6/policy.xml` and then try again. If you get the cache error again, you can increase like this and try again `sudo sed -i 's/4GiB/8GiB/' /etc/ImageMagick-6/policy.xml` – mchid Jul 06 '21 at 09:33
  • I don´t have the policy problem anymore. I can´t convert to .mp4 because of the error "width not divisible by 2" (5333x3000) – kemal uluz Jul 06 '21 at 09:37
  • What's the exact error? – mchid Jul 06 '21 at 09:39
  • width not divisible by 2 (5333x3000) Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height – kemal uluz Jul 06 '21 at 09:41
  • Se here https://askubuntu.com/questions/1081895/trouble-with-batch-conversion-of-png-to-pdf-using-convert/1081907#1081907 on how to tame Imagemagicks convert. – vanadium Jul 06 '21 at 09:42
  • @kemaluluz https://stackoverflow.com/a/60793196 – mchid Jul 06 '21 at 09:45
  • @mchid I tried but the only think is it doesn´t show me up the video. it converts but nothing happens. – kemal uluz Jul 06 '21 at 09:54
  • @mchid ffmpeg -i test1-%01d.png -vf "format=yuv444p,scale:375:500" -c:a copy test.mp4 – kemal uluz Jul 06 '21 at 09:54
  • @kemaluluz `ffmpeg -r 1/10 -i picture-%01d.png video.mp4` works without error. – mchid Jul 06 '21 at 10:20
  • it converts yes but doesn´t show me up the video .. why ? – kemal uluz Jul 06 '21 at 10:34
  • @kemaluluz Did you try my command? It works for me. – mchid Jul 06 '21 at 10:35
  • I tried now. it converts but doesn´t play it up. It opens vlc but don´t play. – kemal uluz Jul 06 '21 at 10:36
  • @kemaluluz I'm not sure. Try a different player. – mchid Jul 06 '21 at 10:38
  • I tried now. Only green screen :/ – kemal uluz Jul 06 '21 at 10:41
  • @kemaluluz Sounds like you need to install [restricted extras](https://help.ubuntu.com/community/RestrictedFormats) and possibly [these gstreamer packages](https://askubuntu.com/questions/590578/green-screen-on-totem-when-playing-mp4-files) as well. – mchid Jul 06 '21 at 10:55
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/127231/discussion-between-kemal-uluz-and-mchid). – kemal uluz Jul 06 '21 at 11:02
  • I tried it now with ubuntu and the problem is it takes some time to convert and afterwards it doesn´t play the video – kemal uluz Jul 08 '21 at 14:36
  • @kemaluluz What video player are you using? I tried with the ffmpeg command you used and it didn't play but when using the commands in the answer and the totem video player and it works. Make sure you have the [restricted extras](https://help.ubuntu.com/community/RestrictedFormats) installed and [these gstreamer packages](https://askubuntu.com/questions/590578/green-screen-on-totem-when-playing-mp4-files) installed as well. – mchid Jul 10 '21 at 14:40
  • I added some commands. It might be a bit of overkill on installing all those gstreamer packages but it won't hurt unless you're lacking disk space. – mchid Jul 10 '21 at 15:01
  • @mchid I tried your commands to install the packages but it isn´t working. For example it tells me that gir1.2-totem-1.0:amd64 isn´t a package to install I tried without amd64 it installs but doesn´t help me a lot – kemal uluz Jul 20 '21 at 08:38
  • @kemaluluz I changed the install command. Like I said, I tried your ffmpeg command and the video did not play but using my command it did. Please open a new question if the video doesn't play; this is really a separate question. I've tested this on my system and it works. Thanks. – mchid Jul 20 '21 at 18:55
  • Somebody should make a program that does all of this. I think I will. – ADBeveridge Nov 15 '21 at 03:13