Log in

View Full Version : h264enc for Linux


Pages : 1 2 [3] 4 5 6 7 8 9 10 11 12 13 14 15

microchip8
9th July 2008, 16:46
Yes, but only if i first massage the h264 with h264info.
I've got a thread here about it: http://forum.doom9.org/showthread.php?t=137517

I was hoping that your script would include some missing mencoder options that would eliminate that h264info step.

Haven't got that far yet, but that new version does run with ac3 copy and the ps3 options.

Will not be looking at this for another week (gotta travel now), but will get back to you eventually if it works with the PS3.

you think I should add the insertSEI and contSPS option to tsMuxeR when creating TS files for the PS3? Maybe that's what h264info is doing?

blaz
9th July 2008, 22:37
you think I should add the insertSEI and contSPS option to tsMuxeR when creating TS files for the PS3? Maybe that's what h264info is doing?

Wish I knew. Maybe that would be a good place to start?

Anyway, can't help testing until I get back to my PS3 next week.

microchip8
11th July 2008, 10:17
ChangeLog for version 8.5.4
* Added support for DTS, MP3 and MP2 audio for the TS container
* Optimizations to the TS container batch exporting code
* iPod optimizations to the MP4 muxing code
* Enabled neroAAC and Vorbis audio support for the Matroska container
* Updated the audio part of the PS3 presets. Added audio copy support so a
user can just copy the AC3 stream and later on mux it into a TS transport stream.
Note that I'm not sure if the PS3 can play H.264 TS files since the PS3 doc only
mentions MPEG2 TS and PS
* Added tsMuxeR options "insertSEI" and "contSPS" as default when muxing to the TS container
* Small tunings to the ps3vp preset. Made it main profile instead of high profile -> ps3hqvp is already
high profile so no need for ps3vp to also be high profile
* Disabled weight_b for the anime presets. According to Dark Shikari (an x264 developer) it decreases
the effectiveness of multiref while providing no benefit
* Do not ask for FPS conversion or pullup/pulldown if the user forces an output frame rate

nm
11th July 2008, 20:54
* Updated the audio part of the PS3 presets. Added audio copy support so a
user can just copy the AC3 stream and later on mux it into a TS transport stream.
Note that I'm not sure if the PS3 can play H.264 TS files since the PS3 doc only
mentions MPEG2 TS and PS
It can play H.264 in both TS and PS, as far as I know. Transport and Programs Streams are specified in MPEG-2 Part 1 (PS is also in MPEG-1 Systems), so that's why the documentation mentions MPEG-2. They can carry various video formats, including H.264 and VC-1.

microchip8
11th July 2008, 21:03
Thanks for the info. I'm still doing a bit of research here. As I don't have a PS3 myself, I'm basically tapping in the dark and trying to guess which options are good for the PS3 and which break playback on it... :/

blaz
18th July 2008, 16:08
you think I should add the insertSEI and contSPS option to tsMuxeR when creating TS files for the PS3? Maybe that's what h264info is doing?

Well, I'm back and tried the latest h264enc TS options with h264 and AC3. Everything went smoothly, except the PS3 doesn't like the result, as usual.

But if I go back to the raw h264 created, and run it though h264info, and rebox it with the ac3 copy using tsMuxeR, the PS3 plays it fine.

It's something about the h264 files coming out of mencoder that h264info changes. No idea what it is though.

microchip8
18th July 2008, 16:15
well, i have no idea what exactly to change so the PS3 can accept the files. There must be something that h264info is doing that i cannot reproduce here. I can only hope that a future firmware for the PS3 will make it more compatible

blaz
18th July 2008, 23:55
well, i have no idea what exactly to change so the PS3 can accept the files. There must be something that h264info is doing that i cannot reproduce here. I can only hope that a future firmware for the PS3 will make it more compatible

yup. The ps3 is way too picky for my taste. And being proprietary there's nothing you can do about it. Did try booting linux on it, but the linux audio drivers are only 2 channel so no surround sound.

By the way, I see you are running 64 bit linux.
Any idea how much 64 bit speeds up h264 encoding over 32 bit?
Mencoder's is running both cores on my cpu but it's still just a 32bit debian os.

nm
19th July 2008, 08:57
Any idea how much 64 bit speeds up h264 encoding over 32 bit?
About 10%

noblewolf
22nd July 2008, 01:14
Hi Everyone,
First off, the h264enc is awesome. It has helped me save lots of space on my file server. I am having one problem though and I keep getting a segmentation fault. Let me explain what I had to do. A friend of mine came for a visit and brought their camcorder along. I had problems getting to work with linux, so had to use windoze to get the files over. The only program I had was nero vision for the dv input. Since time was an issue, I just captured every tape to its own file. And would edit later. The files were HUGE. I have one for almost 22 gigs for 1.8 hrs of video. The files end in .avi but I believe there is some kind of nero encoding with them, that none of my editing software for linux can use. I get segmentation faults for almost every program I try, and both xine and mplayer can not play the audio. Is there a special script for h264enc to take that file and make it into a format I can edit with linux (i.e. openmovie editor, cinellera, etc.)

My machine specs are as follows:
E6600 (soon to be switched to a Q6600)
8 gigs of ram
500 gigs of HD space.

Any help on where to go from here? I am lost as to even look for a solution.

Thanks

noblewolf
22nd July 2008, 01:15
Silly me, I'm running Suse 10.3 x64 as my OS.

Rasi
16th August 2008, 17:23
Am I right that if i want to have a final mkv with 2 (or 3) audio streams + 2 (or 3) subtitles, i will have to rip those manually, substract their filesize from final size in order to use h264enc?

If so - How can i archieve encoding the audio streams with them having the right delay and all?

microchip8
16th October 2008, 16:44
ChangeLog for version 8.5.5
* Presets updates: most presets have been updated to reflect the recent
changes made to the subme system in libx264. The options 'bime' and 'brdo' have
also been removed as they are no longer available as separate options in libx264.
'bime' is automatically enabled if a preset uses subme >= 5, brdo has been included
into the subme system. Please upgrade your libx264 to the latest version if you
encounter problems when using the presets.
* Updated the 'preset.cfg' preset skeleton file
* Separated the 'normal' deinterlacers from the frame doubling ones
* More optimizations to the TS container code
* Disabled b_pyramid for the PS3 presets. Should increase compatibility with the PS3 a bit more
* Added Vorbis audio support for the OGM container
* denoise3d & hqdn3d: increased default denoising values to 3:2:3:2
* Removed path specification for MEncoder
* Cosmetics & cleanups

microchip8
19th October 2008, 15:00
ChangeLog for version 8.5.6

* Updated the 'preset.cfg' skeleton file. Added support for psy_rd, Psychovisual optimization
* Improved subtitle handling for video file encodings. Now the user can select to hardcode a given
subtitle into the movie or import it into the MP4 and/or MKV container. Only two subtitle formats are
supported and have been tested: VobSub and SRT
* Added support for sample encoding and previewing. When encoding samples, one can specify the
start position and the duration in seconds for the sample. Sample encoding respects encoding passes
meaning if you execute h264enc in two-pass mode and want to encode a sample before the real encoding
starts, then the sample will also be encoded in two-pass mode with all the options and filters selected by
the user. Sample encoding can further be used to encode only specific parts of a video file or a DVD. In
regards to DVDs, sample encoding does not respect selected DVD chapters meaning the given start position
for the sample will overwrite the selected DVD chapter(s). This is a mencoder problem and there's nothing I can do about it.
* Presets update: most presets for portable devices have been renamed. Please read the man page or
execute 'h264enc --help' for more information
* Added two QuickTime presets - qt and qthq
* denoise3d & hqdn3d: implemented weak/medium/strong denoising presets
* Removed quantization parameters for the spp, uspp, fspp and pp7 deblockers
* Updated the crop preview code. Instead of sleeping for 15 seconds and then killing the PID value of mplayer,
use the -endpos option
* Updated the man page

microchip8
24th October 2008, 22:44
Am I right that if i want to have a final mkv with 2 (or 3) audio streams + 2 (or 3) subtitles, i will have to rip those manually, substract their filesize from final size in order to use h264enc?

If so - How can i archieve encoding the audio streams with them having the right delay and all?

Yes, you are right. At the moment, h264enc supports only one audio stream. If you want more, you'll have to add them manually. The same goes for more than one subtitles.

as for the right delay/synchronization, this can be a touch one. mkvmerge has an option to sync tracks (--delay). You may want to try that one. Sorry for late answer.

Rasi
26th October 2008, 08:40
Yes, you are right. At the moment, h264enc supports only one audio stream. If you want more, you'll have to add them manually. The same goes for more than one subtitles.

as for the right delay/synchronization, this can be a touch one. mkvmerge has an option to sync tracks (--delay). You may want to try that one. Sorry for late answer.

hmmm... i have to do it afterwards? *sigh*

I remember all the windows tools added the delay in mp3's filenames, so it was pretty easy to do this...

microchip8
28th October 2008, 15:42
ChangeLog for version 8.5.7

* Improved DVD handling. Now there's a menu where the user can select the
input type: ISO image, VIDEO_TS folder or DVD drive
* Presets updates: updated the b_adapt option. It supports parameters. Also updated
the standard presets to use level 4.1 instead of 5.1 and enabled psy_rd (psychovisual
optimization) for all presets that use subq 6 or higher
* Added two Archos 605 presets (ar and arhq). The presets are directly lifted from AutoMKV
(thanks buzzqw) but are a bit modified to get a somewhat higher quality
* Added two Blackberry 9000 presets (bb and bbhq)
* Added two Blu-ray presets (bd and bdhq). When using these presets, h264enc can create
a Blu-ray disc structure if tsMuxeR is available on the user's system. Latest tsMuxeR version
for Linux is 1.7.3(b) which has a bug when creating a Blu-ray structure. h264enc has a workaround
for this
* Added access unit delimiters (aud) for the PS3, Blu-ray and HW compatible presets
* Set the field order of the tfields filter to auto detection
* Bugfix: when using the presets for the iPod/iPhone, h264enc didn't set the SAR to 1:1 when remuxing
to MP4. Bug was introduced due to renaming of the portable device presets
* Removed AAC object type complexity menu. AAC (FAAC) is best used in low complexity mode
* Small improvement to the TS container code. Always write the FPS value to the meta file when
muxing to TS. Also use mencoder/mplayer instead of MP4Box to extract video and audio
* Added extra strong denoising preset for the denoise3d & hqdn3d filters
* Implemented configuration file support. As of this version, h264enc automatically generates a config
file in its configuration directory. The config file can be used by the user to modify/set the paths to
various programs. This can be useful if the user has multiple executables of the same program(s) but
wants to use a specific one for the job. It can also be used to set the correct path to a program if the
program in question is not located in a standard location and cannot be found by the system. The configuration
file cannot be used to store encoding settings or other parameters! It is only meant for the tools needed for
the correct operation of h264enc. The config file will be generated in /home/user_name/.h264enc/config.
The config file has its own versioning system and will be automatically updated in case something changes
in future versions of h264enc
* Added -r option to reset the config file in case the user has made any changes to it and wants to restore
the original values of the config file
* Updated the man page

microchip8
10th November 2008, 16:26
ChangeLog for version 8.5.8
* Added support for the aacplusenc AAC+ audio encoder from Matteo Croce
* Updated the MP4 & MKV batch exporting and muxing code to support the aacplusenc encoder
* Display elapsed time when encoding samples
* Added NAL HRD to the Blu-ray presets. This requires a patched x264 with the NAL HRD patch.
The patch along with install instructions can be downloaded from http://h264enc.sourceforge.net/download.html
* Added option nal_hrd to the 'preset.cfg' skeleton file
* In some cases it is possible for h264enc to leave its unique temp directory. Find those directories
and remove them if they are 15 or more days old
* Added support for deinterlacing at half frame rate. Useful for interlaced content that's running
at 50 or 59.940 fps (100i/120i)
* Updated the source_fps_func() function
* Removed support for the MP2, WMA and ADPCM audio codecs. No one uses these codecs in
combination with H.264 video
* Removed support for MPEG-2 AAC audio
* Reduced some code duplication in the set_output_filename_func() function by moving path
and extension checking into its own function
* SSIM and PSNR statistics are now enabled by default
* Removed the noise filter. No real use for it
* Updated the audio_resample_func() function
* Updated the check_audio_codec_func() function
* Updated the genconfig_func() function
* Updated the man page
* Updated the README.h264enc file

Rasi
13th November 2008, 11:11
Hmm... i did this:

i dumped the subtitles and audio tracks i wanted and converted audio to vorbis.

I looked how big those files are together and substracted it from 1400
(1400 - 238 = 1162)

I said yes in h264enc when it asked for a certain fileseize and entered "1162"

After muxing the resulting file was 1300MB instead of 1400... is there a bug?

microchip8
13th November 2008, 14:49
Hi Rasi,

Can you please give me the video length of the movie? I'm not really sure why this is happening. h264enc calculates the target filesize when encoding without audio as follows: TARGET_SIZE_IN_MB * 8192 / VIDEO_LENGTH_IN_SEC

The above formula will calculate the bitrate needed for the given target filesize. I have never seen it miss its target filesize.

Rasi
13th November 2008, 15:01
The movie is 01:59:23...

The numbers above were guesses: Here are the real numbers i used:

262 mb for audio/subtitles - resulting in 1138 mb for video.
The lenth of 1:59:23 results in:
1138 * 8192 / 7163 = 1301.4 - which is ~100 MB less.

microchip8
13th November 2008, 15:35
Hi Rasi,

I think you are doing something wrong here, or maybe misinterpreting. h264enc calculates the video bitrate for a target filesize. You give it a target filesize in Megabytes and it gives you a bitrate value which will reach this target filesize.

so in your case, you want 1138 MB (this is your target filesize) * 8192 / 7163 (the movie length in seconds) and h264enc has calculated a video bitrate of 1301 kbps and presented to you so you can keep or change it. If you keep it, the 1301 kbps value will reach the requested 1138 MB filesize. Why? because if you calculate the target filesize from the the video bitrate (1301 kbps in this case) and movie length it comes at about 1137.5 MB, eg

1301 * 7163 / 8192 = 1137.5 MB

below is the formula

VIDEO_BITRATE * MOVIE_LENGTH_IN_SEC / 8192

so in this case, the calculated video bitrate (1301 kbps) by h264enc is correct.

Rasi
13th November 2008, 15:43
Hi Rasi,

I think you are doing something wrong here, or maybe misinterpreting. h264enc calculates the video bitrate for a target filesize. You give it a target filesize in Megabytes and it gives you a bitrate value which will reach this target filesize.

so in your case, you want 1138 MB (this is your target filesize) * 8192 / 7163 (the movie length in seconds) and h264enc has calculated a video bitrate of 1301 kbps and presented to you so you can keep or change it. If you keep it, the 1301 kbps value will reach the requested 1138 MB filesize. Why? because if you calculate the target filesize from the the video bitrate (1301 kbps in this case) and movie length it comes at about 1137.5 MB, eg

1301 * 7163 / 8192 = 1137.5 MB

below is the formula

VIDEO_BITRATE * MOVIE_LENGTH_IN_SEC / 8192

so in this case, the calculated video bitrate (1301 kbps) by h264enc is correct.


I cant check now, since the logs have been deleted, but i simply hit return when it asked me for bitrate (which was prefilled with the calculated one) - iirc

microchip8
13th November 2008, 15:59
Well, I cannot see anything wrong with the way h264enc calculates this (or maybe I'm just retarded at math and need to go to math class). Like I said before, I always get the correct target filesize when I let h264enc do the calculation, whether I encode with or without audio, it doesn't matter.

Rasi
13th November 2008, 23:33
Ok.. i tried it again and i made sure that i tell h264enc to use the 1301 bps.
After adding my audio and subtitles to the movie, the file is still 1.3 GB...


Same with another movie, here i accidently told h264enc to hit 1,4 GB with no sound and no subtitles checked. It told me to use around 1850 bps. I realised that i told h264enc the wrong filesize (since i had to substract my audio files) and calculated the bitrate manually. I told h264enc my new bitrate and the resulting file was AGAIN 1.3 GB

My versions:

x264 0.60.0+891 2ca4593
MEncoder 1.0rc2-4.3.2
h264enc 8.5.4


*edit* actually its not THAT bad. dolphin just says 1.3GB. The actual file size is:

1438024127 bytes which is
1371.4 megabytes

But still this is 28.6 MB off my desired filesize

Rasi
14th November 2008, 01:23
Another try, this time i will let you know what i am doing by providing a shot :)

http://img99.imageshack.us/img99/9426/movielo2.th.png (http://img99.imageshack.us/my.php?image=movielo2.png)http://img99.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)


In the lower right you see the files that will be added to the final mkv file. As you can see they are 223MB big, which means my final video file has to be 1177MB

This *should* give me a video that is ~1177MB, right? I will update this post tommorow.



*edit* and here is the result, AGAIN, 26MB smaller:

http://img511.imageshack.us/img511/5671/movie2mq4.th.png (http://img511.imageshack.us/my.php?image=movie2mq4.png)http://img511.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)

microchip8
14th November 2008, 12:13
Hi Rasi,

Yes, I see it. I don't know why this is happening though. I also did a few tests myself yesterday and compared h264enc's calculation method to the one used in Avidemux. For a test sample (without audio) of 299 seconds (00:04:59) and target filesize of 1177 MB, h264enc gave me 32247 kbps while Avidemux gave me 32883 kbps - that's 636 kbps higher than h264enc. I have no idea how Avidemux calculates the values, but if you do 32883 * 299 / 8192 = 1209 MB, which is higher than the requested. If you take h264enc's value and do 32247 * 299 / 8192 = 1176 MB which almost hits the requested filesize. Also keep in mind that if the bitrate is high enough, depending on the movie, the encoder may not need to use the full bitrate thus lowering it which results in smaller filesizes.

I do not know any other formula to calculate the target filesize, besides the one used in h264enc. If you know a better one, please tell me. If you keep getting files which are 20-30 MB smaller than the requested, try compensating for this by providing a target filesize which is 20-30 MB higher than the one you want. Also most people will be happy that their files end up being smaller than intended. In your case it is 26 MB smaller, is that such a huge problem?

Rasi
14th November 2008, 12:24
It's no problem at all.. Mainly i wanted to report a possible bug :)

Plus that i am used to hit exactly the filesize i want from megui :)

microchip8
14th November 2008, 12:27
Will have to look how MeGUI is doing it, if the author provides the source code of course...

microchip8
15th November 2008, 01:07
@ Rasi

been trying all day long with various formulas (my head hurts lol), none of them seems to hit the exact target size. I asked buzzqw (dev of AutoMKV) for his formula and the calculated bitrate comes extremely close to the one in avidemux (within 10-20 kbps). However, even this formula misses the target by 25 MB ( requested size: 1177 MB, got 1152 MB with is 25 MB less than requested). I think you'll have to compensate for that, sorry :/

buzzqw
15th November 2008, 17:13
on h264enc are you encoding to h264 or directly to mp4/mkv ?

also.. mkv/mp4 and have a less overhead then avi (the 24bytes*frames).. you can rise the bitrate * 1.005

good work froggy1!

BHH

microchip8
15th November 2008, 17:18
Hi buzzqw :)

h264enc outputs directly to AVI, then remuxes it to mkv/mp4. I'm still doing some tests here. Will see how it turns out

microchip8
20th November 2008, 16:12
ChangeLog for version 8.5.9
* Rewrote the DVD part of the video_subtitles_func() function. It now supports
dumping two subtitles to disk
* Updated the MP4/MKV muxing code to support importing of two subtitles
* Dramatically simplified the MP4/MKV/OGM batch exporting code. This reduces a
lot of code duplication
* Bugfix in the video_subtitles_func() function for SRT subtitles for video files. Wrong variable used
* When encoding samples, make sure to take care of any subtitles that might have been dumped to disk
* Don't exit if the user provides a floating point value for the Vorbis audio codec. Instead warn
and use the default value.
* New formula to calculate the video bitrate for a target filesize. The previous formula, which was
directly taken from the ripdvd project, incorrectly calculates the bitrate which often results by
missing the target filesize by as much as 30 MB. The new formula also uses floating point precision
and has been tested agains the calculators of MeGUI and Avidemux
* Removed support for me-prepass
* Removed neroAacEnc quality-based encoding mode. It is incompatible with video bitrate calculation
for a target size and I cannot find any info on quality -> average bitrate mappings.
* Updated the HW compatible presets. Changed H.264 Level for the SD presets from 3.1 to 3.0 and
for the HD presets from 4.1 to 4.0. Also updated the vbv_maxrate values according to Level specs
* Restructured the Blu-ray presets. Now there are four different Blu-ray presets available: bd40, bdhq40,
bd41, bdhq41. bd40 is Main profile @ Level 4.0, bdhq40 is High profile @ Level 4.0, bd41 is Main
profile @ Level 4.1 and bdhq41 is High profile @ Level 4.1
* Allow CRF encoding to be used with some device presets (ps3, xbox360, appletv)
* Updated the man page
* Some cleanups

mocham
22nd November 2008, 09:22
froggy,

I kind of talked to you in another thread about mencoder batch GUIs/scripts, and the lack thereof under Linux. Your script is the most useful frontend for mencoder on Linux, but really only friendly to single file jobs. I wanted to ask you if you considered adding any features to make batch encoding with your script more flexible? I was thinking if it could do something like encode all the files located in a specified directory, tell h264enc I want to encode a "directory" of files, go though the y/n options, accept those as the default for all the files to be encoded, resulting file names will just be the original file names with appropriate extensions, then to avoid any problems with duplicate file names or overwriting just put all the encoded files into a "h264enc" sub-directory of the directory that was chosen. Is this a doable feature request with your script? Thanks.

microchip8
22nd November 2008, 14:36
froggy,

I kind of talked to you in another thread about mencoder batch GUIs/scripts, and the lack thereof under Linux. Your script is the most useful frontend for mencoder on Linux, but really only friendly to single file jobs. I wanted to ask you if you considered adding any features to make batch encoding with your script more flexible? I was thinking if it could do something like encode all the files located in a specified directory, tell h264enc I want to encode a "directory" of files, go though the y/n options, accept those as the default for all the files to be encoded, resulting file names will just be the original file names with appropriate extensions, then to avoid any problems with duplicate file names or overwriting just put all the encoded files into a "h264enc" sub-directory of the directory that was chosen. Is this a doable feature request with your script? Thanks.

Hi,

I have no idea if this is doable in the code itself at the moment (I think it may be possible). I will have to look though. BUT you can already do such a thing by modifying the batch file and use a "for loop". For example, you configure one of the files you want to encode. Save the settings to the batch file, open it up and add a loop to so it will look something like this


################### START OF COMMANDS ###################

# Change to dir with video files
cd /path/to/dir/with/video/files

# Make an output dir inside the dir with video files
mkdir -p h264enc

for i in *.avi; do

test -d "/home/microchip" || mkdir -p "/home/microchip"
mkdir -p "/home/microchip/.h264enc/$i"
test -e "/home/microchip/H264-20485.avi" && mv -f "/home/microchip/H264-20485.avi" "/home/microchip/H264-20485.avi.old"

/usr/local/bin/mencoder "$i" -o /dev/null -vf softskip,harddup -oac faac -faacopts mpeg=4:br=110:object=2 -ovc x264 -x264encopts bitrate=1000:me=umh:me_range=24:nodct_decimate:nointerlaced:8x8dct:nofast_pskip:trellis=1:partitions=p8x8,b8x8,i8x8,i4x4:mixed_refs:keyint=250:keyint_min=25:psy_rd=0.5,0.3:frameref=4:bframes=16:b_adapt=1:b_pyramid:weight_b:direct_pred=auto:subq=7:chroma_me:cabac:deblock:level_idc=41:threads=auto:ssim:psnr

/usr/local/bin/mencoder "$i" -o "h264enc/$i" -vf softskip,harddup -oac faac -faacopts mpeg=4:br=110:object=2 -ovc x264 -x264encopts bitrate=1000:me=umh:me_range=24:nodct_decimate:nointerlaced:8x8dct:nofast_pskip:trellis=1:partitions=p8x8,b8x8,i8x8,i4x4:mixed_refs:keyint=250:keyint_min=25:psy_rd=0.5,0.3:frameref=4:bframes=16:b_adapt=1:b_pyramid:weight_b:direct_pred=auto:subq=7:chroma_me:cabac:deblock:level_idc=41:threads=auto:ssim:psnr -passlogfile "/home/microchip/.h264enc/$i/h264.log"

sleep 3

test -e "/home/microchip/H264-20485.mkv" && mv -f "/home/microchip/H264-20485.mkv" "/home/microchip/H264-20485.mkv.old"
/usr/local/bin/mkvmerge "$i" -o "h264enc/$i.mkv"
sleep 3

/usr/local/bin/MP4Box -aviraw video "$i" -out "/home/microchip/.h264enc/$i/h264.h264"
/usr/local/bin/MP4Box -aviraw audio "$i" -out "/home/microchip/.h264enc/$i/aac.raw"
mv -f "/home/microchip/.h264enc/$i/*.raw" "/home/microchip/.h264enc/$i/audio.aac"
test -e "/home/microchip/H264-20485.mp4" && mv -f "/home/microchip/H264-20485.mp4" "/home/microchip/H264-20485.mp4.old"
/usr/local/bin/MP4Box -fps $(/usr/local/bin/mplayer "$i" -identify -nosound -vo null -nocache -frames 1 | grep '^ID_VIDEO_FPS' | tail -1 | awk -F= '{print $2}') -tmp /home/microchip/.h264enc -add "/home/microchip/.h264enc/$i/*.h264" -add "/home/microchip/.h264enc/$i/*.aac" "h264enc/$i.mp4"

sleep 3

rm -rf "/home/microchip/.h264enc/$i"

done

#################### END OF COMMANDS ####################


This is an example of a two-pass encoding with mkv/mp4 remuxing. Everything set in bold is modified/changed to work with a "for loop". The example also assumes that you stick to using a MEncoder audio codec instead of using an external audio encoder like neorAacEnc or oggenc or aacplusenc. It also assumes that all the files you want to encode in the directory are AVI files (though you can add very easily others to the loop too)

The output of each file will be stored in the h264enc directory inside the directory with video files you want to encode. If remuxing to mkv/mp4 the mkv's or mp4's will be named something like file.avi.mkv or file.avi.mp4 so you'll have to remove the .avi extensions yourself

If this is too much, you can always configure one file, save the options to the batch file and post it here. I will modify it for you

Also make sure you have enough disk space if you're also going to remux to mp4/mkv/whatever

The above is just and example and I have not tested it, but it should work

mocham
22nd November 2008, 22:40
This is what I was thinking of, a for loop. I just thought it could be implemented within the script. I'll give this a try. Thanks.

microchip8
22nd November 2008, 22:45
It may be possible to implement this, however I have to look since I deal with a lot of audio codecs and container formats, so it won't be that easy... and I need a little break too, been working on h264enc for the past one and a half week :p

you may also want to try Autox264 from buzzqw, which IIRC has a Queue where you can add jobs

microchip8
23rd November 2008, 15:19
ChangeLog for version 8.6.0
* Bugfix: add the $ofps variable to MEncoder when dumping a second subtitle.
Also enable pcm as audio to maintain sync with the video. A small performance hit but it's worth it
* Added support for dumping one more subtitle. This brings it to a total of 3 subtitles that can be dumped
to disk and imported into the MKV and/or MP4 container
* Dramatically simplified the TS/Blu-ray muxing code
* Implemented initial real batch support for files. As of now, one can encode a bunch of video files in a
directory and automatically remux them to MKV/MP4/OGM. The TS container is not supported yet due
to me being lazy. The user only needs to configure one of the files in a given directory, and all the settings
will apply to the other files as well
* Moved the DVD device detection code into its own function to reduce some code duplication
* Made the encoding priority level global. It now applies to audio/video dumping, audio encoding, subtitles
dumping and container muxing

mocham
25th November 2008, 08:47
ChangeLog for version 8.6.0
* Implemented initial real batch support for files. As of now, one can encode a bunch of video files in a
directory and automatically remux them to MKV/MP4/OGM. The TS container is not supported yet due
to me being lazy. The user only needs to configure one of the files in a given directory, and all the settings
will apply to the other files as well

Cool! Seems to be working on some test files I did. Thanks!

microchip8
25th November 2008, 13:59
ChangeLog for version 8.6.1
* Empty variables cleanups
* Bugfix: the vobsubout3 variable was not tested in the MKV/MP4 muxing code. This leads
to the third subtitle not being imported into these containers
* Added support for TS/Blu-ray muxing when batch encoding files in a directory
* Small improvements for batch encoding of video files in a directory
* New formulas to calculate the video bitrate for a target filesize. The user can choose between
MeGUI's formula, h264enc's refactored MeGUI formula and the old h264enc/ripdvd formula

WalterK
26th November 2008, 01:07
froggy1 just about to try h264enc on a dvd and using the latest version i just ran a sanity check to see if i had everything needed installed this is what i got back

h264enc -sc

-> Checking for 'MPlayer'..................... OK
-> Checking for 'MEncoder'.................... OK
-> H.264 video support in MEncoder............ YES
-> AAC (FAAC) audio support in MEncoder....... YES
-> MP3 (LAME) audio support in MEncoder....... YES
-> AC3 (lavc) audio support in MEncoder....... YES
-> FLAC (lavc) audio support in MEncoder...... YES
-> PCM audio support in MEncoder.............. YES

-> Checking for 'bc'.......................... OK
-> Checking for 'pv'.......................... FAILED! [no support for DVD ISO dumps]
-> Checking for 'dd'.......................... OK
-> Checking for 'neroAacEnc'.................. OK
-> Checking for 'aacplusenc'.................. FAILED! [no support for AAC+ audio]
-> Checking for 'oggenc'...................... OK
-> Checking for 'less'........................ OK
-> Checking for 'lsdvd'....................... FAILED! [no support for DVD title scans]
-> Checking for 'dvdxchap' (from ogmtools).... FAILED! [no support for DVD chapters export]
-> Checking for 'mkvmerge' (from mkvtoolnix).. OK
-> Checking for 'ogmmerge' (from ogmtools).... FAILED! [no support for the OGM container]
-> Checking for 'MP4Box' (from gpac).......... OK
-> Checking for 'tsMuxeR'..................... FAILED! [no support for the TS container]

I know ogmtools is installed version 1.5
I know lsdvd is installed version 0.16

I don't know what pv is and well aacplusenc is not installed.
My distro is ubuntu linux 8.10 all installs from the official repos, no custom compiles.

Edit :

Turns out i needed to reset the configuration file but this time i am missing 'pv' what is that?

microchip8
26th November 2008, 01:28
@ WalterK

h264enc simply checks with the "which" command for the programs it requires. If they are not in a standard PATH it won't find them. You may want to check in a console and see if you get something in return

which lsdvd
which dvdxchap
which ogmmerge

if you get nothing, then these programs are not in a valid PATH so the system won't find them. However, if you're sure they are installed and you know their location, you can set the path to these programs in the config file of h264enc which is located in /home/your_username/.h264enc/config

note the . (point) above, it's a hidden directory. Simply open the config file with a text editor and set the paths to the programs.

pv is "pipeviewer" and you can get it from here: http://h264enc.sourceforge.net/links.html (last link in the list)

WalterK
26th November 2008, 02:00
Ok fixed all that everything is found.
Now i get this error after configuring for the rip then encode.

Would you like to save the MEncoder options to a file? [y/n]: y
Where to store the options? [default is /home/corry/batchfile]: /home/walterk/batchfile_h264dvdrip
Would you like to convert the final encode from AVI to MKV? [y/n]: y
Would you like to convert the final encode from AVI to MP4? [y/n]:
Would you like to convert the final encode from AVI to TS? [y/n]:

-> Starting to encode the DVD in 2-pass mode
-> Using "Extreme High Quality" preset
-> Will use '/dev/null' as output for the first pass
-> Will use '/home/walterk/ts/Exchange_Club.avi' as output file for the second pass

Starting to encode in: 5 4 3 2 1
MEncoder 2:1.0~rc2-0ubuntu17+medibuntu1 (C) 2000-2007 MPlayer Team
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 6000+ (Family: 15, Model: 107, Stepping: 2)
CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
Option x264encopts: Unknown suboption psy_rd
There are 3 titles on this DVD.
There are 22 chapters in this DVD title.
There are 1 angles in this DVD title.
audio stream: 0 format: ac3 (stereo) language: aid: 128.
number of audio channels on disk: 1.
number of subtitles on disk: 0
success: format: 2 data: 0x0 - 0x8e329000
MPEG-PS file format detected.
VIDEO: MPEG2 720x480 (aspect 3) 29.970 fps 7500.0 kbps (937.5 kbyte/s)
[V] filefmt:2 fourcc:0x10000002 size:720x480 fps:29.97 ftime:=0.0334
==========================================================================
Opening audio decoder: [liba52] AC3 decoding with liba52
Using SSE optimized IMDCT transform
Using MMX optimized resampler
AUDIO: 48000 Hz, 2 ch, s16le, 224.0 kbit/14.58% (ratio: 28000->192000)
Selected audio codec: [a52] afm: liba52 (AC3-liba52)
==========================================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
Opening video filter: [harddup]
Opening video filter: [softskip]
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 720 x 480 (preferred colorspace: Mpeg PES)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
The selected video_out device is incompatible with this codec.
Try appending the scale filter to your filter list,
e.g. -vf spp,scale instead of -vf spp.
VDecoder init failed :(
Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b
Selected video codec: [mpeg12] vfm: libmpeg2 (MPEG-1 or 2 (libmpeg2))
==========================================================================
VDec: vo config request - 720 x 480 (preferred colorspace: Planar YV12)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
[swscaler @ 0x883f410]SwScaler: using unscaled yuv420p -> yuv420p special converter
FATAL: Cannot initialize video driver.

Exiting...
-> MEncoder has exited with a none-zero value!
-> Exiting in function: mencoder_exit()
I see an X264 error (unknown option psy_rd) and a video error, must be how its trying to rip the dvd disc , so i will first rip to my hd and as an ISO, get the latest svn X264 and compile (its been a while since an update) and see if theres any more troubles with the encode.

microchip8
26th November 2008, 02:03
Please upgrade your x264 library to a more recent version. h264enc uses psy_rd is almost all of its presets. Your x264 is too old and that's why it halts mencoder. You can get the latest x264 from git

git clone git://git.videolan.org/x264.git

PS: I see you have saved the options to a batch file, so you don't need to configure anything anymore. After you're done with x264, just load the batch file with h264enc -b /home/corry/batchfile_h264dvdrip

WalterK
26th November 2008, 03:30
Well now the x264 error is gone and now it seems a colorspace error

MEncoder 2:1.0~rc2-0ubuntu17+medibuntu1 (C) 2000-2007 MPlayer Team
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 6000+ (Family: 15, Model: 107, Stepping: 2)
CPUflags: Type: 15 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
There are 3 titles on this DVD.
There are 22 chapters in this DVD title.
There are 1 angles in this DVD title.
audio stream: 0 format: ac3 (stereo) language: aid: 128.
number of audio channels on disk: 1.
number of subtitles on disk: 0
success: format: 2 data: 0x0 - 0x8e329000
MPEG-PS file format detected.
VIDEO: MPEG2 720x480 (aspect 3) 29.970 fps 7500.0 kbps (937.5 kbyte/s)
[V] filefmt:2 fourcc:0x10000002 size:720x480 fps:29.97 ftime:=0.0334
Input fps will be interpreted as 29.97 instead.
==========================================================================
Opening audio decoder: [liba52] AC3 decoding with liba52
AUDIO: 48000 Hz, 2 ch, s16le, 224.0 kbit/14.58% (ratio: 28000->192000)
Selected audio codec: [a52] afm: liba52 (AC3-liba52)
==========================================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
Opening video filter: [harddup]
Opening video filter: [softskip]
Opening video filter: [pullup]
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 720 x 480 (preferred colorspace: Mpeg PES)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
VDecoder init failed :(
Opening video decoder: [libmpeg2] MPEG 1/2 Video decoder libmpeg2-v0.4.0b
Selected video codec: [mpeg12] vfm: libmpeg2 (MPEG-1 or 2 (libmpeg2))
==========================================================================
VDec: vo config request - 720 x 480 (preferred colorspace: Planar YV12)
Could not find matching colorspace - retrying with -vf scale...
Opening video filter: [scale]
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.

Exiting...
-> MEncoder has exited with a none-zero value!
-> Exiting in function: mencoder_exit()


So i'll be trying with the svn version of mplayer/mencoder to see whats up.

microchip8
26th November 2008, 13:02
configure everything, save to batchfile and upload it to pastebin or here so i can see what's going on

WalterK
26th November 2008, 14:16
Well i compiled the latest svn mplayer and the colorspace error is no longer an issue now its encoding to X264 MKV.
So i guess it was the standard medibuntu version of mencoder that was the problem.

mocham
29th November 2008, 09:19
froggy1,

I just used vers 8.6.1 to batch convert a directory with 93 MPEG2-TS files to MP4's, your script worked great! Exactly what I was looking for! Thanks.

microchip8
29th November 2008, 14:18
mocham,

Glad you like it and it works for you. I've significantly improved the directory encoding code. I'll release a new version tonight, then up to the next challenge (if only I can get this thing to work)

WalterK
29th November 2008, 17:19
Your script works great froggy1 but i think you should make a special note for ubuntu users that they need to update three of the dependencies before use.
Specifically X264, mencoder and mkvtoolsnix, if they decide to create files in the mkv container.
The versions in the ubuntu repos are too old even on 8.10.
At least thats what i found.