Thursday, February 25, 2010

MinGW: Building GPAC

GPAC is an MPEG-4 multimedia transcoder suite. This post documents my attempt to compile GPAC with MinGW for the Win32 platform.




  1. Compile OpenSSL as shown in this post.

  2. Build FreeType as shown below.
    tar xjvf freetype-2.3.9.tar.bz2
    cd freetype-2.3.9
    ./configure --prefix=/mingw --disable-shared
    make
    make install


  3. liba52 AC3 decoder


    Download the liba52 source from liba52.sf.net and compile libA52 like this:

    tar xzvf a52dec-0.7.4.tar.gz
    cd a52dec-0.7.4/
    ./configure --prefix=/mingw
    make
    make install

    The following files are installed:

    bin/a52dec.exe
    bin/extract_a52.exe
    include/a52dec/a52.h
    include/a52dec/attributes.h
    include/a52dec/audio_out.h
    include/a52dec/mm_accel.h
    lib/liba52.a
    lib/liba52.la
    man/man1/a52dec.1
    man/man1/extract_a52.1


  4. MAD Library


    The MAD (MPEG Audio Decoder) library is a fast fixed-point MPEG audio decoder that doesn't require an FPU numeric processor. Download the libmad source from mad.sf.net and compile MAD like this:


    tar xzvf libmad-0.15.1b.tar.gz
    cd libmad-0.15.1b
    ./configure --prefix=/mingw --disable-shared --enable-fpm=intel --disable-debugging
    make
    make install

    The following files are installed:

    include/mad.h
    lib/libmad.a
    lib/libmad.la


  5. Get DirectX headers from either location below and extract it into /mingw/include:


  6. Download the source for the JPEG library and compile as follows:
    tar xzvf jpegsrc.v7.tar.gz
    cd jpeg-7
    ./configure --prefix=/mingw --enable-static
    make
    make install


  7. Download the source for the PNG library and compile like this:
    tar xzvf libpng-1.2.38.tar.gz
    cd libpng-1.2.38/
    ./configure --prefix=/mingw --disable-shared
    make
    make install


  8. Then, compile GPAC like this:
    ./configure --prefix=/mingw --cpu=i586 --strip --use-png=no --use-ffmpeg=no

    cp config.h include/gpac/internal


    Before compilation, I edited config.mak:


    SSL_LIBS=-lssleay32 -leay32 -lgdi32 -lws2_32 -lz

    Then, I started make:


    make

    make install


    I encountered an error during the final compilation. But I got MP4Box.exe which was all I needed. So I copied mp4box.exe and libgpac.dll from ~/gpac/bin/gcc.





List Of Created Files


The following files are created as a result of compiling GPAC with MinGW:


gm_aac_in.dll
gm_ac3_in.dll
gm_bifs_dec.dll
gm_ctx_load.dll
gm_dummy_in.dll
gm_dx_hw.dll
gm_ft_font.dll
gm_img_in.dll
gm_ismacryp.dll
gm_isom_in.dll
gm_laser_dec.dll
gm_mp3_in.dll
gm_mpegts_in.dll
gm_odf_dec.dll
gm_ogg_xiph.dll
gm_raw_out.dll
gm_rtp_in.dll
gm_saf_in.dll
gm_soft_raster.dll
gm_svg_in.dll
gm_timedtext.dll
gm_wav_audio.dll
gm_xvid_dec.dll
libgpac.dll
MP4Box.exe
MP4Client.exe

Monday, February 22, 2010

Getting Cygwin cdrkit

cdrkit is a CD-ROM authoring utility. If you don't mind typing commands in Command Prompt, cdrkit can prove useful to you. To download cdrkit for Windows, find a Cygwin mirror. I like the Cygwin mirror at
ftp://mirrors.kernel.org/sourceware/cygwin/release



Go to the directory cdrkit and download the packages genisoimage, icedax and wodim at the subdirectories. Other packages are just aliases. Also, don't forget to download the cygwin package which contain cygwin1.dll.

Saturday, February 20, 2010

Fixing Jittery DVD Sound on Windows 7

I've been using Windows 7 happily until I played a DVD movie and heard continuous jittery noise. The picture was fine, but Windows Media Player 12 only uttered the jittery noise instead of words and music.


I think it's a codec problem. To fix the problem, I downloaded Preferred Filter Tweaker for Windows 7 and disabled Microsoft DTV-DVD Audio Decoder.




This renames C:\Windows\System32\msmpeg2adec.dll so that Windows Media Player 12 doesn't use its own codec. Then, I installed AC3Filter. This fixed the jittery noise problem. Alternatively, ffdshow can be used instead of AC3Filter.

Monday, February 15, 2010

Using Mencoder to Rip DVD into AVI/MKV/MP4 movies

Since I compiled MPlayer and Mencoder, I can use the programs for ripping DVD's as well as watching movies. Usually, I use SMPlayer frontend to play movies. Here I summarize how to make AVI, Matroska (.MKV) or MP4 files containing H.264 video and AAC audio.



First, download my Mplayer/Mencoder builds for Windows. MKVtoolnix is also needed.




Finding the Main DVD Title


In most cases, the first DVD title is the movie you want. Often, you can watch the feature title with the following command (Assuming D: is the DVD drive):


mplayer dvd://1 -dvd-device D:\ -ao dsound -vo directx:accel

For Windows Vista and Windows 7, direct3d is recommended as video output:


mplayer dvd://1 -dvd-device D:\ -ao dsound -vo direct3d

However, some DVD's have a feature title on a track other than the first. For such DVD's, trying each track can be tedious. The following command will help identify the main title on the DVD and also find information on available chapters and subtitles.


mplayer dvd://1 -dvd-device D:\ -identify -vf cropdetect > log.txt

Stop the movie after a moment (pressing q) and you'll get the log file log.txt. In the log.txt file, you'll find the main title to be the longest:


ID_DVD_TITLE_15_LENGTH=12.000
ID_DVD_TITLE_16_LENGTH=5513.533
ID_DVD_TITLE_17_LENGTH=0.500

Here, you find that the 16th title is the feature film.



Dumping the Feature Film from DVD


You can use MPlayer to save a DVD title on hard drive:


mplayer dvd://1 -dvd-device D: -v -dumpstream -dumpfile movie.vob

Now you can put aside your DVD. From now on, you can work with the VOB file saved on your hard drive. Alternatively, you can use VLC to dump a DVD title.



Finding Crop Values


If your DVD is widescreen (not fullscreen), look for the crop values from the log.txt file obtained above:


[CROP] Crop area: X: 0..719  Y: 60..417  (-vf crop=720:352:0:64).

In this example, the crop value will be 720:352:0:64. Note that the first two values (here 720 and 352) have to be divisible by 16.



Encoding DVD to an AVI file containing H.264 video and AAC audio


The following command actually creates an AVI file encoded in H.264:


mencoder dvd://1 -dvd-device E:\ -o movie.avi -oac faac -faacopts object=2:br=128 -vf pp=lb,filmdint,crop=704:464:6:10,scale=720:480,harddup -sws 8 -ofps 24000/1001 -ovc x264 -x264encopts crf=20:8x8dct:frameref=4:bframes=3:b_pyramid=normal:weight_b

The -vf scale= filter is used to resize the video stream. The output refresh rate will be 24000/1001=23.976 frames per second. If you're concerned with encoding speed, set bframes=2.



Encoding DVD to an AVI file containing DIVX video and MP3 audio


The following example shows how to create an AVI file encoded in MPEG-4. In the example below, the encoding bitrate is moderately 768 kilobits per second. The crop filter is only for widescreen titles.:


set VENCOPTS=vcodec=mpeg4:vbitrate=896:vmax_b_frames=2:mbd=2:v4mv:last_pred=3:trell:cbp
mencoder dvd://1 -dvd-device E:\ -o NUL -nosound -vf yadif=0,crop=704:464:6:10,scale=720:480,harddup -ovc lavc -lavcopts %VENCOPTS%:autoaspect:vpass=1
mencoder dvd://1 -dvd-device E:\ -o movie.avi -aid 128 -oac mp3lame -lameopts preset=128,aq=2,vol=8 -vf yadif=0,crop=704:464:6:10,scale=720:480 -ovc lavc -lavcopts %VENCOPTS%:autoaspect:vpass=2


Encoding Additional Sound Tracks


The following example command encodes the English sound track (aid 128) to +8dB-amplified 96kbps MP3:


mencoder dvd://1 -dvd-device D:\ -o audio-en.mp3 -of rawaudio -ovc frameno -aid 128 -oac mp3lame -lameopts preset=96,aq=2,vol=8

The following example encodes an AAC file:


mencoder dvd://1 -dvd-device E: -o audio-en.aac -of rawaudio -ovc frameno -aid 128 -oac faac -faacopts object=2:br=128

Another way to encode DVD audio is to save the sound as .WAV file and encode it with LAME MP3 encoder. First, extract the audio as .WAV file. Then, encode the .WAV file to MP3.


mplayer dvd://1 -dvd-device D:\ -vo null -vc null -aid 128 -ao pcm:fast:file=audio-en.wav
lame --preset tape -h audio-en.wav audio-en.mp3

Later, you can mux AVI:


mencoder.exe -ffourcc DIVX -oac copy -ovc copy -o final_movie.avi -audiofile audio-en.mp3 movie.avi


Editing Chapters.txt


In the log.txt file, you'll find a section that looks like:


CHAPTERS: 00:00:00,00:03:37,00:05:42,00:09:12,00:11:24,00:16:18,00:20:21,00:22:56,00:26:14,00:29:31,00:32:26,00:35:13,00:38:13,00:42:14,00:43:47,00:48:25,00:51:45,00:53:52,00:57:32,01:00:04,01:05:44,01:08:29,01:10:45,01:13:53,01:18:21,01:21:10,01:24:45,01:28:53,01:31:32,01:33:36,01:35:36,01:38:57,01:41:44,

With a text editor, create a text file chapters.txt and put something like:


CHAPTER01=00:00:00.00
CHAPTER01NAME=My name is John Connor.
CHAPTER02=00:03:37.01
CHAPTER02NAME=Weight of the future.
CHAPTER03=00:05:42.16
CHAPTER03NAME=T-X arrives.


Extracting Subtitles from DVD


If you look at the log.txt file gotten above, you'll find information on subtitles.


subtitle ( sid ): 0 language: en
ID_SUBTITLE_ID=0
ID_SID_0_LANG=en
subtitle ( sid ): 1 language: fr
ID_SUBTITLE_ID=1
ID_SID_1_LANG=fr
subtitle ( sid ): 2 language: es
ID_SUBTITLE_ID=2
ID_SID_2_LANG=es

To extract DVD subtitles, I ran the following command in the Command Prompt:


mencoder movie.vob -nosound -ovc frameno -o nul -sid 0 -vobsubout subtitle-en -vobsuboutindex 0 -vobsuboutid en

mencoder movie.vob -nosound -ovc frameno -o nul -sid 1 -vobsubout subtitle-fr -vobsuboutindex 1 -vobsuboutid fr

mencoder movie.vob -nosound -ovc frameno -o nul -sid 2 -vobsubout subtitle-es -vobsuboutindex 2 -vobsuboutid es

The sid and vobsuboutindex number can be obtained from the log.txt file above. Do this for each subtitle but remember to name each output file uniquely.



Creating a Matroska file with Mkvmerge


Let's put together the video, audio and subtitles into a Matroska package. For this task, a command-line tool mkvmerge from MkvToolNix project is used.


mkvmerge
--title "Holiday Trip" --chapters CHAPTERS.TXT -o my_movie.mkv
--aspect-ratio 0:4/3
--track-name 1:"English AAC audio" --default-track 1 --language 1:en movie.avi
--track-name 0:"French AAC audio" --language 0:fr audio-fr-51.aac
--language 0:en en.idx --language 0:fr fr.idx --language 0:es es.idx

If there's a problem with audio/video synchronization, use the --sync option with mkvmerge. For example, the following command makes the audio track start at 13 seconds after the video starts:


mkvmerge -o movie.mkv video.264 --sync 0:13000 audio.mp3


Creating .MP4 files


Use MP4Box to create a .MP4 movie.


MP4Box -add video.h264 -add audio-en.mp3:lang=eng -add audio-fr.mp3:lang=fre -add en.idx -add fr.idx -add es.idx -fps 23.976 -chap CHAPTERS.TXT movie.mp4


Related Links


Monday, February 1, 2010

MinGW: To Compile LAME for Windows

LAME is a high-quality open-source MP3 encoder. Even though LAME is open-source, LAME is not freely distributed by some major Linux distributions, including Debian and Ubuntu. That's because there have been uncertain legal issues surrounding the MP3 algorithm. However, you can still download the LAME source and compile LAME using the free MinGW compiler. Following is an easy guide to compiling LAME for Windows.


The configure script of LAME makes use of nasm if found. To produce an optimal build of LAME, download yasm and save it as /mingw/bin/nasm.exe.


Launch MSYS (rxvt) and type the following command to unpack the LAME tarball.


tar xzvf lame-398-4.tar.gz

Go to the new folder lame-3.98.4 and configure LAME.


cd lame-3.98.4

./configure --prefix=/mingw --disable-shared --enable-expopt=full

Start compilation.


make

make install” will copy the following files into /mingw tree.


bin/lame.exe
bin/libmp3lame-0.dll
include/lame/
lib/libmp3lame.a
lib/libmp3lame.dll.a
lib/libmp3lame.la

What you definitely want is libmp3lame-0.dll and lame.exe. Copy them to a folder, for example, C:\Windows\System32 or C:\Windows.



To Make LAME_ENC.DLL


Even though the normal MinGW process creates a dynamic library named libmp3lame-0.dll, many Windows applications require a variant of LAME library called lame_enc.dll. Rather than hacking Makefiles, we can use a tool called a2dll from mingw-utils. mingw-utils is a package of tiny handy programs useful for MinGW users. Download mingw-utils-0.3.tar.gz and extract a2dll with tar or 7-zip.


After compiling LAME as shown above, open MSYS rxvt again and go to the folder that contains libmp3lame.a.


cd lame-3.98.4/libmp3lame/.libs

Then, run a2dll like this:


a2dll libmp3lame.a -o lame_enc.dll

You may append the -s option to get a leaner file lame_enc.dll. I tested lame_enc.dll I got this way with Audacity, and audacity was able to recognize lame_enc.dll and export to MP3 files. Yet, I need to do more testing with other programs, such as WinAMP, etc.



Related Posts


About This Blog

KBlog logo This blog seeks to provide a collection of interesting pictures found on the Web. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

Powered By Blogger