Wednesday, August 29, 2007

HOWTO: Right Click-Convert videos to Ipod / Smartphone format Quickly and Easily

Found a little script that will convert videos to IPod video format (i.e. mp4 with xvid and aac encoding) utilising ffmpeg and ruby. The nice thing about this is that it will preserve the original aspect ratio and add black bars depending, so videos look like they should do (well aside from being in QVGA 320x240 resolution!). Some smartphones (such as the Nokia N95) are also able to display this format =)

The script can be found here

For a little HOWTO:

Open up synaptic and ensure that you have ffmpeg and ruby installed/
apt-get install ruby ffmpeg liblame-dev libxvidcore4-dev libx264-dev libfaac-dev libfaad2-dev
sudo apt-get build-dep ffmpeg
Download the script:

Code:

wget http://thomer.com/howtos/mp4ize
Make it so you can run it:

Code:

chmod +x mp4ize
Move it so it's system-wide:

Code:

sudo mv mp4ize /usr/local/bin
Now, if you want to convert a video, just open up a terminal and type mp4ize [videoname] and it will make an IPod mp4 version in the same folder. Enterprising Nautilus Actions users may want to add a right click menu version for this by adding /usr/local/bin/mp4ize as a path and %M as a parameter.

If everything goes well, your output will look like this:
root@ion:/extra/movies/Life.Support.DVDRip.XviD-BeStDivX/Sample# ls
bestdivx-lifes-sample.avi
root@ion:/extra/movies/Life.Support.DVDRip.XviD-BeStDivX/Sample# mp4ize bestdivx-lifes-sample.avi
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-mp3lame --enable-gpl --enable-faad --mandir=${prefix}/share/man --enable-vorbis --enable-pthreads --enable-faac --enable-xvid --enable-dts --enable-amr_nb --enable-amr_wb --enable-pp --enable-libogg --enable-libgsm --enable-x264 --enable-a52 --extra-cflags=-Wall -g -fPIC -DPIC
libavutil version: 49.0.0
libavcodec version: 51.11.0
libavformat version: 50.5.0
built on Nov 3 2006 21:14:27, gcc: 3.3.5 (Debian 1:3.3.5-13)
Input #0, avi, from 'bestdivx-lifes-sample.avi':
Duration: 00:01:00.0, start: 0.000000, bitrate: 1071 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 576x320, 23.98 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 160 kb/s
Must supply at least one output file
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-mp3lame --enable-gpl --enable-faad --mandir=${prefix}/share/man --enable-vorbis --enable-pthreads --enable-faac --enable-xvid --enable-dts --enable-amr_nb --enable-amr_wb --enable-pp --enable-libogg --enable-libgsm --enable-x264 --enable-a52 --extra-cflags=-Wall -g -fPIC -DPIC
libavutil version: 49.0.0
libavcodec version: 51.11.0
libavformat version: 50.5.0
built on Nov 3 2006 21:14:27, gcc: 3.3.5 (Debian 1:3.3.5-13)
Input #0, avi, from 'bestdivx-lifes-sample.avi':
Duration: 00:01:00.0, start: 0.000000, bitrate: 1071 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 576x320, 23.98 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 160 kb/s
Output #0, mp4, to 'bestdivx-lifes-sample.mp4':
Stream #0.0: Video: xvid, yuv420p, 320x240, q=3-5, 400 kb/s, 23.98 fps(c)
Stream #0.1: Audio: aac, 48000 Hz, stereo, 128 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 1439 q=3.0 Lsize= 3734kB time=59.9 bitrate= 510.6kbits/s
video:2763kB audio:936kB global headers:0kB muxing overhead 0.928542%
root@ion:/extra/movies/Life.Support.DVDRip.XviD-BeStDivX/Sample# ls
bestdivx-lifes-sample.avi bestdivx-lifes-sample.mp4
root@ion:/extra/movies/Life.Support.DVDRip.XviD-BeStDivX/Sample#

22 comments:

  1. Well done, I tried many other script and this works, thank you very much indeed.

    ReplyDelete
  2. FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
    configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
    libavutil version: 0d.49.0.0
    libavcodec version: 0d.51.11.0
    libavformat version: 0d.50.5.0
    built on Sep 20 2006 00:26:15, gcc: 4.1.2 20060906 (prerelease) (Ubuntu 4.1.1-13ubuntu2)
    Input #0, avi, from 'entourage.s01e01.pdtv-pyro.avi':
    Duration: 00:29:08.2, start: 0.000000, bitrate: 1680 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 624x464, 23.98 fps(r)
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, 32 kb/s
    Must supply at least one output file
    FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
    configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
    libavutil version: 0d.49.0.0
    libavcodec version: 0d.51.11.0
    libavformat version: 0d.50.5.0
    built on Sep 20 2006 00:26:15, gcc: 4.1.2 20060906 (prerelease) (Ubuntu 4.1.1-13ubuntu2)
    Unknown codec 'xvid'



    ------------

    Newb to ubuntu - can you tell me where I went wrong? Installed both ffmpeg and ruby.

    ReplyDelete
  3. u may need to do this:
    sudo apt-get install liblame-dev libxvidcore4-dev libx264-dev libfaac-dev libfaad2-dev
    sudo apt-get build-dep ffmpeg

    ReplyDelete
  4. ok you first need to enable universe/multiverse repositories and then apt-get update
    You can install the codecs you need with the following commands:
    sudo apt-get install gstreamer0.8-plugins
    sudo apt-get install gstreamer0.8-lame
    sudo apt-get install gstreamer0.8-ffmpeg
    sudo apt-get install w32codecs
    sudo apt-get install libdivx4linux
    sudo apt-get install lame
    sudo apt-get install sox
    sudo apt-get install ffmpeg
    sudo apt-get install mjpegtools
    sudo apt-get install vorbis-tools
    gst-register-0.8

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Enabling Multimedia in Feisty (HOW-TO)
    Video/audio codec, flash, mp3, dvd playback, and win32 Codec install for Feisty Fawn for beginners. If your a new user, copy and paste commands into the terminal, should be relatively easy from that point forward.

    For mp3, etc.
    Open up Add/Remove programs from your Application bar.

    Go to Sound&Video and Find and Check all of the packages below (easily done by searching for gstreamer)

    * "GStreamer ffmpeg video plugin"
    * "GStreamer extra plugins"
    * "GStreamer plugins for aac, xvid, mpeg2, faad"
    * "GStreamer plugins for mms, wavpack, quicktime, musepack"


    Then go to Other subsection of Add/Remove and find

    * "Ubuntu restricted extras"

    For Flash support

    While under the "Other" section enable

    * "Macromedia Flash plugin"



    For DVD Playback and Win32 Codecs

    Edit the file /etc/apt/sources.list using either of the following commands in a terminal:
    Code:

    $gksudo gedit /etc/apt/sources.list

    to open it in the GUI text editor

    or

    Code:

    $sudo vim /etc/apt/sources.list

    to open it in the Vim command line text editor

    Add the following lines to add the Medibuntu repository to the file:


    Quote:
    ## Medibuntu - Ubuntu 7.04 "feisty fawn"
    ## Please report any bug on https://launchpad.net/products/medibuntu/+bugs
    deb http://medibuntu.sos-sts.com/repo/ feisty free non-free
    deb-src http://medibuntu.sos-sts.com/repo/ feisty free non-free
    Import the gpg key for the Medibuntu repository to ensure that the packages are installed without warnings/errors regarding trust:
    To do this, run the following command from the terminal:

    Code:

    wget -q http://medibuntu.sos-sts.com/repo/medibuntu-key.gpg -O- | sudo apt-key add -

    Now update the local list of packages to get the list of packages from the newly added Medibuntu repository:

    In a terminal execute the following command:

    Code:

    sudo apt-get update

    Now you can install libdvdcss2 and w32codecs using the following command:
    Code:

    sudo apt-get install libdvdcss2 w32codecs

    ReplyDelete
  8. Josh, after that, try and reboot.. the problem is the xvid codec for some reason

    ReplyDelete
  9. $ sudo apt-get install libdivx4linux
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Couldn't find package libdivx4linux

    ReplyDelete
  10. ok, try grabbing Automatix, and installing all the codecs from that application, once installed it will be in applications->system tools
    http://www.getautomatix.com/wiki/index.php?title=Installation

    ReplyDelete
  11. ok did that. Not sure what I'm doing wrong here... but I am getting the same error. "unknown codec xvid". Not likley being as I have installed everything that was listed, rebooted as well. Very frustrating!

    ReplyDelete
  12. http://ubuntuforums.org/showthread.php?p=3274348 looks to be where this originated from. Ill try there.

    ReplyDelete
  13. After I do the apt-get commands (installing sourcecode), is there a way to delete any now-unneeded files (while keeping the ability to do Right Click-Convert videos to Ipod, of course)?

    ReplyDelete
  14. OP wrote: "Enterprising Nautilus Actions users may want to add a right click menu version for this by adding /usr/local/bin/mp4ize as a path and %M as a parameter."

    How exactly do we do that?

    ReplyDelete
  15. I did as the OP wrote: "Enterprising Nautilus Actions users may want to add a right click menu version for this by adding /usr/local/bin/mp4ize as a path and %M as a parameter."
    But I can't see any mp4ize command when I right-click files.

    ReplyDelete
  16. Josh-

    I had the same trouble as you and I discovered a solution.

    I'm assuming you've installed all of the packages mentioned at the top of the post and done the "apt-get build-dep ffmpeg" thing.

    Open up a terminal and type:

    env DEB_BUILD_OPTIONS=risky sudo apt-get -b source ffmpeg

    From here, it'll take a while. Adding risky to the build options unlocks the "--enable-xvid" configuration option, among others.

    Once it's done building, type:

    sudo dpkg -i ffmpeg*.deb

    Or the equivalent deb package that was generated. You'll also need to install the lib* deb files that it generated.

    sudo dpkg -i lib*.deb

    Then try the mp4ize script. It should be working fine for you now.

    ReplyDelete
  17. Thanks Christian, worked for me!
    (Really nice tool btw.)

    so long,
    cheers!

    ReplyDelete
  18. Sorry for not reading all the comments, but I need to let off some steam now...

    With mencoder and ffmpeg available for linux, it should be NO problem making a sweet gui for these WITH presets!

    Lots of people have either psp, ipod videos and mobile phones or other handheld devices that can show videos. But since videos that you find on the net are of course never in the 'correct' format so they need to be converted.

    Not being an expert on video formats, codecs and so on, it's a nightmare trying to convert using the commandline, or even filling in the blanks in the gui...

    I'm so frustrated now! thanks for listening to my rant, and may Santa Claus or someone like him bring me a linux video converter with presets!

    ReplyDelete
  19. hi and thks to every one 4 ur help help but i have a problem, when i send a mp4 video 2 my ipod i can see it but without any sound. pls if some body can help i will be very greatfull.... thnks

    ReplyDelete
  20. I also got the "unkonwn codec xvid" with freshly installed packages. it seems there were changes in the packages and the script needs to the fixed. in the list of ARGS replace xvid by libxvid and aac by libfaac. in the cmd line, put the -i 'infile' before the ARGS. after that it worked.

    ReplyDelete
  21. Avidemux has iPod 320x240 and 640x480 auto formats for exporting. I generally prefer this tool, since it gives you more options than just automagical black borders if need be. I've converted FLV and XVID files just fine with it.

    ReplyDelete