User Info
No avatar Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
May 27, 2019, 09:07:24 AM


Anime Stash Community Forum  |  The Lounge  |  Technology & The Internet  |  GNU/Linux  |  Topic: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
Pages: [1] 2

Author Topic: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS  (Read 17466 times)
Val-Gaav
将軍 (Shogun)
神様 (Kami)
*
Offline Offline

Posts: 5924



H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« on: June 18, 2007, 12:59:11 PM »

Using the magic of GNU/Linux shell scripts and CLI interface can make batch encoding much easier and faster then other methods. What is more bash scripts can automate the work of several programs at once so SOFTSUBING and other things also are automatic.

I'll try to make it as easy as I can :

1) u will need this programs :

-mplayer
-mencoder (sometimes part of mplayer)
-oggenc
-MP4box (it's usally a part of gpac pack)
-mkvtoolnix

How to get those? ....  Well all of them should be in your distro repository ..
- In case of ubuntu u should make sure to universe/multiverse enabled in sunaptic options.
- In case od Debian visit www.debian-multimedia.org and add repos from their site to your apt-get sources.list

The script .... Well just create in any text editor(like kwrite or gedit) a new file and name it as  encoding.sh ... after you save the file  right click it and in the preferences change the file to exacutable one ...
 
anyway here is my script for normal hardsubed animes :
Code:
function enk
{
rm test.mp4

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=300:bframes=3:frameref=1:weight_b:turbo=2:b_pyramid:b_bias=25:pass=1 "$x" -o /dev/null -nosound -of rawvideo -ofps 23.976

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=300:bframes=3:frameref=1:weight_b:b_pyramid:b_bias=25:pass=2 "$x" -o test.264 -nosound -of rawvideo -ofps 23.976

mplayer -ao pcm:file=audio.wav -vo null -vc none "$x"
oggenc audio.wav -q 0 -o audio.ogg
MP4Box -fps 23.976023976 -add test.264 test.mp4
"mkvmerge" -o "$y"  -d 1 -A -S test.mp4 -a 0 -D -S audio.ogg --track-order 0:1,1:0
}

x="/home/val-gaav/MyDownloads/[Shinsen-Subs]_Ghost_Hunt_-_19_[F1D0190C].avi"
y=/home/val-gaav/NIEDOKONCZONE/ova/Ghost_Hunt_19.mkv
enk

x="/home/val-gaav/Desktop/Black_Lagoon_AMV_Mell-Red-Fraction.flv"
y=/home/val-gaav/Desktop/Black_Lagoon_AMV_Mell-Red-Fraction.mkv
enk


x = input file patch (source file that you want to encode)
y =output file patch ( )
enk is a function for encoding ...

U can add new lines of X Y enk .... and basicly it's the only part of script that should be interesting to you as only here you change the input/output directory and file names....
As seen in example I encode two files
-Black Lagoon AMV
-Ghosthunt ep 19

This script will produce two files  ....  also this script works for panoramic animes (widescreen). All new animes are widescreen ....  for normal ones 640:480  u should use  scale=448:336:::  instead of scale=512:288:::

___________________________________________________________
The same script for softsubed dual audio (jap+english audio) animes :

Code:
dual
{
rm test.mp4

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=300:bframes=3:frameref=1:weight_b:turbo=2:b_pyramid:b_bias=25:pass=1 "$x" -o /dev/null -nosound -of rawvideo -ofps 23.976

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=300:bframes=3:frameref=1:weight_b:b_pyramid:b_bias=25:pass=2 "$x" -o test.264 -nosound -of rawvideo -ofps 23.976

mplayer -alang en -ao pcm:file=audio.wav -vo null -vc none "$x"
oggenc audio.wav -q -1 -o audio.ogg
mplayer -alang jpn -ao pcm:file=audio.wav -vo null -vc none "$x"
oggenc audio.wav -q -1 -o audio1.ogg
MP4Box -fps 23.976023976 -add test.264 test.mp4
"mkvmerge" -o "$y"  -d 1 -A -S test.mp4 --language 0:eng -a 0 -D -S audio.ogg --language 0:jpn -a 0 -D -S audio1.ogg --language 4:eng --default-track 4 -s 4 -D -A "$x" --track-order 0:1,1:0,2:0,3:

}

x="/home/val-gaav/MyDownloads/(B-A)Gilgamesh_-_19_(708897A4).mkv"
y=/home/val-gaav/NIEDOKONCZONE/ova/Gilgamesh_-_19.mkv

x="/home/val-gaav/MyDownloads/(B-A)Gilgamesh_-_21_(110FF601).mkv"
y=/home/val-gaav/NIEDOKONCZONE/ova/Gilgamesh_-_21.mkv
dual


dual
Script is much a like the earlier one ... though it process two audio tracks and ads the sofsubs into mkv ...
In the example I encode two eps of Gilgamesh  ep 19 and ep 21 ...
x = input file patch (source file that you want to encode)
y =output file patch ( )
dual is a function for encoding ...
_____________________________________

The same script but for SOFTSUBED animes  (no dual audio)
Code:
soft
{
rm test.mp4

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=300:bframes=3:frameref=1:weight_b:turbo=2:b_pyramid:b_bias=25:pass=1 "$x" -o /dev/null -nosound -of rawvideo -ofps 23.976

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=300:bframes=3:frameref=1:weight_b:b_pyramid:b_bias=25:pass=2 "$x" -o test.264 -nosound -of rawvideo -ofps 23.976

mplayer -ao pcm:file=audio.wav -vo null -vc none "$x"
oggenc audio.wav -q 0 -o audio.ogg
MP4Box -fps 23.976023976 -add test.264 test.mp4
"mkvmerge" -o "$y"  -d 1 -A -S test.mp4 --sync 0:3000 -a 0 -D -S audio.ogg --language 3:eng --default-track 3 -s 3 -D -A "$x" --track-order 0:1,1:0,2:3
}


x="/home/valgaav/MyDownloads/[A-E_&_Saizen]_Toward_the_Terra_10_[6818910A].mkv"
y=/home/valgaav/NIEDOKONCZONE/ova/toward_the_terra_10.mkv
soft
The only file encoded this time is Toward the terra ep 10 ....
x = input file patch (source file that you want to encode)
y =output file patch ( )
soft is a function for encoding ...


After you have the script and named the files you want to encode  just run it thorugh console....
Code:
./encoding.sh

Also if u want your comp to turn off after encoding run this script as root and add the following line to the end of the script  "shutdown -h now"
« Last Edit: June 18, 2007, 01:05:19 PM by val-gaav » Logged
Ryokei
新米 (Shinmai)

Offline Offline

Posts: 5


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #1 on: June 27, 2007, 07:11:09 AM »

/laughs\ My Fedora Core computer stalled trying to execute that, but then I realized that I hadn't made the screen size correct (I musta slipped and held down the zero key)

Thanks a lot for that, I've always wanted to try out an encode on my Linux box.
Logged
Val-Gaav
将軍 (Shogun)
神様 (Kami)
*
Offline Offline

Posts: 5924



Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #2 on: June 27, 2007, 09:34:35 PM »

I'm glad it helped somebody .... I wondered if I should post this guide because well .... I thought it may be to geeky  rolleyes
Logged
Ryokei
新米 (Shinmai)

Offline Offline

Posts: 5


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #3 on: June 28, 2007, 01:47:26 AM »

I'm glad it helped somebody .... I wondered if I should post this guide because well .... I thought it may be to geeky  rolleyes

Well, if someone is browsing the Linux part of the forums, they are generally just as geeky anyway.  grin

By the way, using your code, everything suceeded in no time at all. Thanks again.
Logged
VioletHeart
Insubstantial
浪人 (Ronin)
先輩 (Senpai)
*
Offline Offline

Posts: 480



Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #4 on: June 28, 2007, 02:17:47 AM »

actually i wanna try those codes/scripts but i rarely use my ubuntu for work purpose
mostly in window platform, thanks anyway i'll attempt/screw those someday

by the way i dont think i'm a geek haha i'm just a newbie in linux world, still learning new things from day to day in the net


Logged
zirkov
新米 (Shinmai)

Offline Offline

Posts: 16


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #5 on: July 15, 2007, 06:10:52 PM »

Uh I always failed installing LibVorbis, it's said I didnt install for Ogg but I already did it. Any info about install all of them into CentOs 4 ?
Logged
Val-Gaav
将軍 (Shogun)
神様 (Kami)
*
Offline Offline

Posts: 5924



Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #6 on: July 15, 2007, 06:46:18 PM »

I do not know if it helps but here u have list of additional repos for CentOS :

http://wiki.centos.org/Repositories

_________________

Anyway I do not use Centos/fedora/redhat so I do not know the specifics of this system packages and repos .... anyway  maybe in a last resort you could compile the oggenc manualy ...
Logged
zirkov
新米 (Shinmai)

Offline Offline

Posts: 16


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #7 on: July 15, 2007, 06:49:28 PM »

Well since I'm new in linux, I dont have any idea abour repo -_-. Well I wil try again, if fail, I will give up
Logged
Val-Gaav
将軍 (Shogun)
神様 (Kami)
*
Offline Offline

Posts: 5924



Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #8 on: July 15, 2007, 07:27:54 PM »

repos are the http ftp servers form which you download your packages (software) and install it ...

If u use Centos then you are using ExtendedYUM as far as I know a s a GUI for installing software....  there has to be a section with repos in it where you can add additional adreses ...

and well you should try and  learn .... i also didn't know what a repo is when I used my first mandrake linux  2 years ago grin
Logged
zirkov
新米 (Shinmai)

Offline Offline

Posts: 16


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #9 on: July 15, 2007, 07:32:26 PM »

Btw for compiling mplayer, should I put --enable-x264 because it's didnt support for h.264
Logged
Val-Gaav
将軍 (Shogun)
神様 (Kami)
*
Offline Offline

Posts: 5924



Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #10 on: July 15, 2007, 11:30:40 PM »

I believe the error you got was the lack of x264 and that is an encoding library for mencoder .... so without it you cannot encode with my scripts....

I think you should be interested in :

RPMForge - This repository is a collaboration of Dag, Dries, and other packagers. They provide over 2600 packages for CentOS, including mplayer, xmms-mp3, and other popular media tools.
You can find more information about rpmforge at http://rpmforge.net/

also check this link:
http://wiki.centos.org/Repositories/RPMForge
Logged
zirkov
新米 (Shinmai)

Offline Offline

Posts: 16


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #11 on: July 16, 2007, 03:01:45 PM »

Thanks for helping, but I have 1 problem, I cant compile gpac. When I try do ./configure, I got Access Denied ~_~ and I cant find any gpac repo for CentOs

And I tried encode some file, but it didnt reduce the file size. I set my bitrate into 200 but I still got the same size. Btw here's my code for encoding


mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=225:bframes=3:frameref=1:weight_b:turbo=2:b_pyramid:b_bias=25:pass=1 1.avi -o /dev/null -oac mp3lame -lameopts abr:br=84 -ofps 23.976

mencoder -vf scale=512:288:::,harddup -ovc x264 -x264encopts bitrate=225:bframes=3:frameref=1:weight_b:b_pyramid:b_bias=25:pass=2 1.avi -o test.mkv -oac mp3lame -lameopts abr:br=84 -ofps 23.976
« Last Edit: July 16, 2007, 05:03:00 PM by zirkov » Logged
zirkov
新米 (Shinmai)

Offline Offline

Posts: 16


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #12 on: July 17, 2007, 03:03:26 AM »

Btw I changed my OS into Debian and all command for perfectly, thanks ^_^. Btw can I borrow this guide, of course I will give a credit and link back

btw how to fix this :

New_Face failed. Maybe the font path is wrong.n   0mb  A-V:0.000 [0:0]
Please supply the text font file (~/.mplayer/subfont.ttf).
« Last Edit: July 17, 2007, 03:52:34 AM by zirkov » Logged
Val-Gaav
将軍 (Shogun)
神様 (Kami)
*
Offline Offline

Posts: 5924



Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #13 on: July 17, 2007, 08:27:52 PM »

New_Face failed. Maybe the font path is wrong.n   0mb  A-V:0.000 [0:0]
Please supply the text font file (~/.mplayer/subfont.ttf).
You didn't configure font in mplayer... it's needed if u want to watch movies with softsubs ... it's not needed for encoding ....
mplayer readme :
Code:
You can use any TrueType font installed on your system. Just pass '-font
/path/to/font.ttf' on the command line or add 'font=/path/to/font.ttf' to
your configuration file. The manual page has more details. Alternatively
you can create a symbolic link from either ~/.mplayer/subfont.ttf or
/usr/local/share/mplayer/subfont.ttf to your TrueType font.
you can also choose the font through mplayer GUI ....

and yes you can spread this guide ... and credit will be welcomed since it may increase activity in stash GNU/Linux forum grin
Logged
zirkov
新米 (Shinmai)

Offline Offline

Posts: 16


Re: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
« Reply #14 on: July 18, 2007, 05:42:08 PM »

Thanks for the answer, it's help me a lot. Btw I wan to ask about bitrae option. It's strange even I change to 250, my size file still have around 65 mb. How can it be ?
Logged

Pages: [1] 2  
Anime Stash Community Forum  |  The Lounge  |  Technology & The Internet  |  GNU/Linux  |  Topic: H.264 encoding MENCODER/MKVTOOLNIX/BASH SCRIPTS
Jump to:  



Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
© 2005 animestash.info | Site Disclaimer