Results 1 to 1 of 1

Thread: How to: Encode a HD timelapse video with H.264 codec and MP4 format

  1. #1
    Join Date
    Aug 2008
    Beans
    96

    Lightbulb How to: Encode a HD time-lapse video with H.264 codec and MP4 format

    Ok. You have taken a few thousands of photos, and now you expect to turn them into a cool time lapse video. You also would like to upload it to, for example, Vimeo, as an HD video. Of course, you want all of this without using Windows or any of it's apps.

    That's exactly what i did here: http://vimeo.com/29459342 (This video hasn't the full res of HD cos i wrote the resize settings wrong. However, it works as you input resize settings above 1280*720px. For vimeo specifications, read the Vimeo FAQ)

    Vimeo tells you that:
    A codec is the format in which your video will be encoded. Different codecs have different features and varying quality. For best results, we recommend using H.264 (sometimes referred to as MP4).
    How to?
    I managed to do it using MEncoder and FFMPEG: Both are in synaptic. However a special install is needed. Without it, the commands for encoding the video won't work properly (THANKS FakeOutdoorsman):


    Quote Originally Posted by FakeOutdoorsman View Post
    FFmpeg is a versatile tool to encode and decode a multitude of video and audio formats. x264 encodes high-quality H.264 video.

    Choose your Ubuntu
    0.The instructions on the page are for Ubuntu Natty Narwhal 11.04 and Ubuntu Maverick Meerkat 10.10. Separate instructions are also available for older, supported releases:



    Install the Dependencies
    1. Uninstall x264, libx264-dev, and ffmpeg if they are already installed. Open a terminal and run the following (you can usually paste into a terminal with shift+ctrl+v). Copy and paste the whole code box for each step.
    Code:
    sudo apt-get remove ffmpeg x264 libx264-dev
    2. Get all of the packages you will need to install FFmpeg and x264 (you may need to enable the Universe and Multiverse repositories):
    Code:
    sudo apt-get update
    sudo apt-get install build-essential checkinstall git libfaac-dev libjack-jackd2-dev \
      libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev \
      libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html \
      yasm zlib1g-dev

    Install x264
    3. Get the current source files, compile, and install x264.
    Code:
    cd
    git clone git://git.videolan.org/x264
    cd x264
    ./configure --enable-static
    make
    sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
        awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
        --fstrans=no --default
    Now that everything is properly installed, we're ready to encode the video:
    3 commands here, each one is separated by a ";" from another, so you can run it by copy paste. This must be run in the same folder your photos are in.

    Code:
    mencoder mf://*.jpg -mf fps=30 -vf scale=1280:-1 -ovc x264 -x264encopts pass=1:bitrate=6000:crf=20:preset=veryslow -nosound -ofps 30 -noskip -of rawvideo -o rawoutput.264 ; ffmpeg -f h264 -i rawoutput.264 -r 30 -vcodec copy muxed.mp4 ; rm rawoutput.264
    Aclaration: You can replace "30" by your desired frames per second. And in
    Code:
    preset=veryslow
    you can change to "veryfast" if you want just a sample video. Encoding time will shorten greately, and quality will suffer a little bit.

    It took me few days until i get this. But of course, the point is that with ubuntu is more than possible to achieve a high quality timelapse video created from photos. It's really cool.


    Expanation: 1)Mencoder creates a RAW video output using H.264 codec, b-frames, and a set of preseted parameters that goes for high quality. Now, since MEncoder's MP4 muxer doesn't get on well with b-frames videos, we will have to mux it into a MP4 container with FFMEG. That's what the second command do. 3) The third command deletes the RAW H.264 video, leaving alone the mp4 video.

    Finally, you can add an audio track to make it more interesting:

    Code:
    ffmpeg -i video-without-audio.mp4 -i audio.mp3 -vcodec copy -acodec copy video-with-audio.mp4


    The truth is that FFMPEG can do this all, but the H.264 encoding with FFMPEG was terrible in my case, the dynamic range happened to be from 14,14,14 to 235,235,235, ergo, darkest pixels weren't black (0,0,0) and whitest pixels weren't white (255,255,255). Greyish and awful image, but i couldn't solve it.


    Hope somebody finds this useful when googling.
    Last edited by nahuel_89p; September 26th, 2011 at 06:32 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •