Showing posts with label mencoder. Show all posts
Showing posts with label mencoder. Show all posts

Sunday, May 16, 2010

Using Mencoder To Merge AVI Files

Merging 2 AVI files can be easily accomplished with mencoder. But the two AVI files must be encoded with the same video and audio codec. Assuming that you have part1.avi and part2.avi, seamlessly consecutive, the mencoder command to concatenate them is:


mencoder -ovc copy -oac copy -o whole.avi part1.avi part2.avi

Friday, April 9, 2010

MinGW: MPlayer와 Mencoder 동적 컴파일하기

MinGW의 GCC 컴파일러를 사용하여 Windows용 MPlayer와 Mencoder를 컴파일해 보자. MPlayer는 동영상을 보는 프로그램이고 Mencoder는 동영상이나 음악을 인코딩하는 프로그램이다. 예전에는 정적으로 컴파일하였지만 이번에는 동적으로 컴파일해 보자.


우선 MinGW를 설치한다. MPlayer는 FFmpeg 라이브러리에 의존하므로 먼저 FFmpeg 라이브러리를 동적으로 컴파일하도록 한다.


시작 메뉴를 열어 MinGW (rxvt)를 실행한다. 노란 창이 나타날 것이다. 그럼 다음과 같이 MPlayer와 의존 라이브러리를 컴파일하자.



  1. LZO 압축 라이브러리 컴파일 (옵션)

    tar xzvf lzo-2.03.tar.gz
    cd lzo-2.03/
    ./configure --prefix=/mingw
    make
    make install


  2. Fribidi 라이브러리 컴파일 (옵션)

    Fribidi는 아랍어와 히브리어의 표시에 필요하다. 솔직히 이 기능은 빠뜨려도 된다.

    tar xzvf fribidi-0.19.2.tar.gz
    cd fribidi-0.19.2/
    ./configure --prefix=/mingw --disable-debug
    make
    make install

    자세한 내용은 Fribidi에 관한 글을 참조.

  3. giflib 라이브러리 컴파일 (옵션)

    tar xjvf giflib-4.1.6.tar.bz2 
    cd giflib-4.1.6/
    ./configure --prefix=/mingw
    make
    make install


  4. Live555 라이브러리 컴파일 (권장)

    Live 라이브러리는 인터넷 동영상을 보는 데 쓰인다. live555.com에서 최신 버전을 받아 다음과 같이 컴파일한다:

    export CC=/mingw/bin/gcc.exe
    cd /mingw/lib/
    tar xzvf live.2010.04.01.tar.gz
    cd live/
    ./genMakefiles mingw
    make


  5. JPEG 라이브러리 컴파일 (권장)

    tar xzvf jpegsrc.v8a.tar.gz
    cd jpeg-8a/
    ./configure --prefix=/mingw
    make
    make install


  6. PNG 라이브러리 컴파일 (권장)

    tar xzvf libpng-1.4.1.tar.gz 
    cd libpng-1.4.1
    ./configure --prefix=/mingw
    make
    make install


  7. FreeType 라이브러리 컴파일 (필수)

    자막 표시에 필요하다.

    그리고 Freetype를 컴파일한다.

    tar xzvf freetype-2.3.12.tar.gz 
    cd freetype-2.3.12/
    ./configure --prefix=/mingw
    make install


  8. 만일 iconv 라이브러리가 설치되어 있지 않다면 컴파일한다. libXML2 그리고 fontconfig 에 필요하다.

  9. libXML2 컴파일

    만약에 fontconfig 라이브러리를 컴파일하려면 필요하다. 먼저 testThreads.c를 고친다.

    --- testThreads.c.orig  2009-09-11 18:09:00.268640135 +0200
    +++ testThreads.c 2009-09-11 18:12:43.412653512 +0200
    @@ -107,7 +107,7 @@

    for (i = 0; i < num_threads; i++) {
    results[i] = NULL;
    - tid[i] = (pthread_t) -1;
    + memset(&tid[i], 0, sizeof(pthread_t));
    }

    for (i = 0; i < num_threads; i++) {

    그리고 컴파일한다:


    ./configure --prefix=/mingw
    make install


  10. Fontconfig 라이브러리 컴파일 (권장)

    SSA 자막 표시에 필요하다.

    tar xzvf fontconfig-2.8.0.tar.gz 
    cd fontconfig-2.8.0/
    ./configure --prefix=/mingw
    make install


  11. Libcdio 컴파일 (옵션)

    tar xzvf libcdio-0.83.tar.gz 
    cd libcdio-0.83/
    ./configure --prefix=/mingw
    make
    make install


  12. Libdca 컴파일 (권장)

    tar xjvf libdca-0.0.5.tar.bz2 
    cd libdca-0.0.5/
    ./configure --prefix=/mingw
    make install


  13. DirectX 7 라이브러리 추출 (권장)

    cd /mingw/include/
    tar xzvf dx7headers.gz


  14. MPlayer, Mencoder 컴파일

    ffmpeg 소스를 받아서 mplayer 소스 디렉토리에 넣는다.

    tar xjvf mplayer-export-snapshot.tar.bz2

    cd mplayer-export-2011-11-25/

    tar xjvf ffmpeg-snapshot.tar.bz2

    CPPFLAGS='-DWIN32 -DHAVE_INT32_T' ./configure --prefix=/mingw --enable-runtime-cpudetection --enable-theora --enable-fribidi --disable-ffmpeg_a --yasm=/mingw/bin/yasm

    MPlayer를 컴파일하기 전에 config.mak를 텍스트 에디터(notepad.exe)로 수정한다.

    EXTRALIBS_MPLAYER  = -lgdi32 -lopengl32 -lwinmm -lfaac -lx264 -lmp3lame -lfribidi
    EXTRALIBS_MENCODER = -lfaac -lx264 -lfribidi -lmp3lame

    MPlayer 컴파일 시작한다.

    make

  15. MPlayer.exe와 Mencoder.exe를 복사한다.

    strip mencoder.exe mplayer.exe
    cp -iv m*.exe /mingw/bin

Sunday, April 4, 2010

Using MPlayer & Mencoder to Rip Blu-ray

Blu-ray discs require new and powerful CPU and graphics card to play high-definition movies on them. Although MPlayer is not yet suitable for playing Blu-ray discs, Mencoder can be used to rip Blu-ray discs in a more watchable format so that you can watch the movie on your average computer, laptop, iPod or iPad. I blogged previously on using Mencoder to rip DVD. Ripping Blu-ray isn't much different from ripping DVD.


Since Blu-ray discs are encrypted, you need to use DumpHD, Clown_BD or AnyDVD HD to dump the contents of your Blu-ray disc to your hard drive prior to ripping it. If you have Slysoft AnyDVD HD installed, right-click on the red fox icon on the right side of the taskbar, and choose Rip Video DVD to Harddisk from the menu. Then, specify the location where you want to save unencrypted Blu-ray contents. Note that you'll need more than 20GB free space.



After saving the huge amount of Blu-ray contents, open Command Prompt and type mplayer commands to play the Blu-ray movie. Here are some examples:



  • VC-1 video and AC-3 audio

    mplayer E:\BDMV\STREAM\00024.m2ts -vo directx:accel -vc ffvc1 -ao dsound -ac ffac3 -aid 4352 -framedrop

  • H.264 video and AC-3 audio

    mplayer E:\BDMV\STREAM\00024.m2ts -vo directx:accel -vc ffh264 -ao dsound -ac ffac3 -aid 4352 -framedrop

  • MPEG video and AC-3 audio

    mplayer E:\BDMV\STREAM\00024.m2ts -vo directx:accel -vc ffmpeg12 -ao dsound -ac ffac3 -aid 4352 -framedrop


To find available audio tracks, type the -identify option for mplayer to create a log file and look for AUDIO_ID strings.


mplayer 00024.m2ts -vo direct3d -vc ffvc1 -vf cropdetect -ss 180 -identify > log.txt


To encode the Blu-ray video with H.263 codec and resize it to 768x432 screen at the same time, the mencoder command would be like:


mencoder 00024.m2ts -o film.h264 -of rawvideo -oac copy -vf scale=768:432,harddup -ofps 24000/1001 -vc ffvc1 -ovc x264 -x264encopts bitrate=1200:subq=4:bframes=3:b_pyramid=normal:weight_b:pass=1:turbo=1

My second-pass mencoder command would be:


mencoder 00024.m2ts -o film.264 -of rawvideo -oac copy -vf scale=768:432,harddup -ofps 24000/1001 -vc ffvc1 -ovc x264 -x264encopts bitrate=1200:8x8dct:me=umh:frameref=4:bframes=3:b_pyramid=normal:weight_b:pass=2:trellis=1:psnr


I like to convert 5.1-channel AC3 audio to 6-channel AAC sound.


mplayer 00024.m2ts -vo null -vc null -aid 4352 -ao pcm:fast:file=audio-en-51.pcm -ac ffac3 -channels 6
faac --mpeg-vers 4 -q 108 -c 16800 -I 2,6 audio-en-51.pcm


Finally, let's put together a Matroska package from the video and audio


mkvmerge --title "Le Film" --default-language fr --chapters Chapters.txt -o le_film.mkv --track-name 0:"Video_Title" --default-duration 0:23.976fps --display-dimensions 0:768x432 --noaudio film.264 --default-track 0 --language 0:fr audio-fr-51.aac

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


Sunday, August 16, 2009

Mplayer & Mencoder: Extracting AC3 audio from DVD

Extracting AC3 audio from a DVD is a smart thing to do when ripping DVD's. First of all, it separates the audio part of the task and lets the user focus on the video encoding part. Secondly, it helps the user to make decision about the bitrate of the video depending on the size of output files. Here's my mencoder command to extract AC3 data from a DVD.


mencoder.exe dvd://1 -dvd-device D: -aid 128 -ss 4 -o war.ac3 -of rawaudio -oac copy -ovc frameno

Alternatively, I can use MPlayer to achieve the same thing.


mplayer movie.vob -aid 128 -dumpaudio -dumpfile audio-en-51.ac3

mplayer movie.vob -aid 129 -dumpaudio -dumpfile audio-fr-51.ac3

Oddly, the output file war.ac3 plays fine with MPlayer, but can't be played with VLC player. Is it because VLC player is inferior to MPlayer?


When Mencoder finished ripping DVD audio, it displayed the following:


Recommended video bitrate for 650MB CD: 434

Recommended video bitrate for 700MB CD: 502

Recommended video bitrate for 800MB CD: 637

Recommended video bitrate for 2 x 650MB CD: 1316

Recommended video bitrate for 2 x 700MB CD: 1451

Recommended video bitrate for 2 x 800MB CD: 1723



Video stream: 0.767 kbit/s (95 B/s) size: 593132 bytes 6183.043 secs 148295 frames



Audio stream: 448.000 kbit/s (55999 B/s) size: 345966435 bytes 6177.972 secs

This information is helpful in deciding the bitrate of the video.



Extracting Video from DVD


To extract only video from a DVD, I used the following command:


mencoder dvd://1 -dvd-device D: -o war.264 -of rawvideo -vf filmdint -ofps 24000/1001 -nosound -ovc x264 -x264encopts bitrate=720:vbv_maxrate=1000:vbv_bufsize=2000:direct_pred=auto:8x8dct:me=umh:trellis=1:pass=1:turbo=2 -ss 4

Saturday, August 8, 2009

Mencoder: Extract Sound from a DVD track and Save it as .WAV file

A friend of mine asked me to make an audio CD from the sound extracted from a DVD track. For this job, I used mencoder which I've compiled for both Windows and Linux. After several attempts, I found the right mencoder command to extract sound from a DVD track to a raw headerless uncompressed PCM format. The track I wanted was the second track on the DVD. Here's my mencoder command:


mencoder.exe dvd://2 -o track2.raw -of rawaudio -oac pcm -ovc frameno

This will produce a file which only holds uncompressed PCM data. You can't yet play it with a media player. It's got to be converted to the .WAV format. I opened it in audacity and chose File, Import, Raw Data... from the menu. In the Import Data... dialog, I chose the following settings:


  • Encoding: Signed 16-bit PCM
  • Byte-order: Little-endian
  • Channels: 2 Channels (Stereo)
  • Start offset: 0 bytes
  • Amount to import: 100 %
  • Sample Rate: 44100 Hz

Audacity opened it with no problem. Then, I saved the file in .WAV fomat by selecting File, Export... from the menu.


The resulting .WAV file can be burnt to a CD using most CD burners including InfraRecoder and CDBurnerXP.

Monday, June 8, 2009

Compiling Mencoder for Windows

Mencoder is a command-line tool for creating multimedia files. It allows you to convert video from one format to another. When used together with OGMRip, mencoder helps you to rip DVD into a video file that's convenient to watch on computers. Note that the instruction herein explains how to compile Mencoder for the Windows platform, not Linux.



MinGW must be installed first (Look here for how). Once you have MinGW, launch MSYS (rxvt) from the Start menu and type the following commands.




  1. PNG and JPEG


    PNG depends on zlib compression library. Download the zlib source from zlib.net and compile as follows:

    tar xzvf zlib-1.2.3.tar.gz
    cd zlib-1.2.3
    ./configure --prefix=/mingw
    make
    make install

    Now get the PNG library here and compile it as follows:

    tar xzvf libpng-1.2.34.tar.gz
    cd libpng-1.2.34/
    ./configure --prefix=/mingw --disable-shared
    make
    make install

    Download the source for JPEG library, compile and install JPEG as follows:

    tar xzvf jpegsrc.v7.tar.gz
    cd jpeg-7
    ./configure --prefix=/mingw
    make
    make install


  2. libdca Library


    Download the libdca source from videolan.org and compile it like this:


    tar xjvf libdca-0.0.5.tar.bz2
    cd libdca-0.0.5
    ./configure --prefix=/mingw
    make
    make install


  3. OGG, Vorbis and Theora


    The source for these libraries can be obtained from xiph.org. Compile them like this:

    ./configure --prefix=/mingw --disable-shared
    make
    make install


  4. Libcdio Library


    Download the libcdio source from here. Compile and install libcdio as follows:

    tar xzvf libcdio-0.81.tar.gz
    cd libcdio-0.81
    ./configure --prefix=/mingw --disable-shared
    make
    make install


  5. Live555 library


    The Live555 library is used to decode streaming media. Get the live555 source from here and compile it as follows:

    cd /mingw/lib
    tar xzvf live.2009.07.28.tar.gz
    cd live
    ./genMakefiles mingw
    make


  6. LAME


    LAME is an MP3 encoder. This library allows Mencoder to encode DVD sound into MP3 audio. Download LAME from lame.sf.net and compile it as follows.


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

    make

    make install


  7. TwoLame


    TwoLAME is an MP2 audio encoder. Get the source from twolame.org and compile it:

    ./configure --prefix=/mingw CPPFLAGS='-DLIBTWOLAME_STATIC'
    make
    make install


  8. XviD


    In case you didn't know, XviD is the most popular video encoder used in creating movie files found on the P2P networks. With this library, mencoder can rip a DVD into XviD video. Get the XviD source from xvid.org and compile as follows:


    tar xzvf xvidcore-1.2.2.tar.gz

    cd xvidcore/build/generic

    ./configure --prefix=/mingw

    make

    make install

    In addition, change to the /mingw/bin directory and copy xvidcore.a to libxvidcore.a.


    cd /mingw/lib

    cp xvidcore.a libxvidcore.a


  9. FAAC


    FAAC is an MPEG-4 AAC audio encoder. Get the source (faac-1.28.tar.gz) and unpack the package. Then, edit Makefile.am:

    SUBDIRS = include libfaac

    Also, edit the line beginning with AC_OUTPUT in the file configure.in:

    AC_OUTPUT(libfaac/Makefile include/Makefile Makefile)

    Then, compile FAAC like this

    sh bootstrap
    ./configure --prefix=/mingw --enable-static --disable-shared
    make
    make install


  10. x264


    x264 is yet another good video encoder. x264 requires YASM to build an optimized executable. So get yasm and save it as /mingw/bin/yasm.exe. Then, compile x264 like this:


    sh configure --prefix=/mingw --extra-cflags="-DX264_VERSION=20090608"

    make

    make install


  11. Compiling Mencoder


    Now you're ready to compile mencoder. Download the MPlayer source snapshot from mplayerhq.hu and unpack it. Then, type the following commands into the MSYS window to produce the executable mencoder.exe.


    CPPFLAGS='-DHAVE_INT32_T -DLIBTWOLAME_STATIC'./configure --prefix=/mingw --enable-runtime-cpudetection --enable-static --enable-theora --yasm=/mingw/bin/yasm

    make mencoder

    strip *.exe

    mv -iv mencoder.exe /c/Windows

    This produces a static executable mencoder.exe and copies it into the C:\WINDOWS folder.




If you'd like to try my mencoder build, download it from here. Its filename is MPlayer-svn-r30521-snapshot-3.4.5.zip.

About This Blog

KBlog logo This blog is about current events and issues concerning general population. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger