Log in

View Full Version : encoding lectures


niv
18th February 2009, 11:45
Hi ,
I got two issues, that I can't find much answers in google.
1. Is there a setting I should use if I encode lectures in mathematic, which is a white board most of the time with the prof. moving and the formulas on the board are static? grabed at 720x576 btw, so what would be a resnable bitrate I can go down to, can it be less then 500k? I still want to be able to read the forumlas.

2. I assume I can use aac at 64k. I found lots of ways to encode the audio then mux it in to mp4. why shouldnt I just use mecoder to do it all? is the quality better when I use faac?

thanks,
Niv

Audionut
18th February 2009, 12:04
1. Test a sample for yourself.

2. Of course. Yeah. Beats me? Probably not!!

Sagekilla
18th February 2009, 15:10
There's one setting you could use: --keyint 50000 ;) You won't be able to seek at all if x264 decides to use one I-frame. But it would be any static areas would never have to be coded again.

niv
19th February 2009, 15:45
how can I improv on these options, from a video with frames like the sample below?
/usr/bin/nice -n 19 /usr/bin/mencoder -vf pp=ci -oac faac -oacopts ar=24000 -ovc x264 -264encopts bitrate=250:threads=auto:cqm=eqm_avc_hr.cfg:deblock=-3,-3:bframes=5:b_pyramid:weight_b:me=umh:frameref=5:mixed_refs:subq=7:trellis=1:8x8dct:nofast_pskip:nopsnr:nossim:direct_pred=auto:pass=2 -passlogfile tk-x264-pass.dat -o test-x264-video.keyis5k250.mp4 VTS_01_1.VOB
here is a typical shoot from the video:
http://farm4.static.flickr.com/3403/3293055642_37f3f4b61f.jpg

nm
19th February 2009, 16:15
Yadif is a much better deinterlacer than pp=ci. In this case, I'd also denoise heavily with hqdn3d (tune the parameters to remove most of the noise):
-vf yadif=0,hqdn3d


For x264 encoding, I hope you actually used -x264encopts. Also make sure that the libx264 version that MEncoder uses is recent enough, preferably the latest git.
The CQM is probably unnecessary and you set deblocking too low. I'd try something like this:
-x264encopts crf=25:threads=auto:bframes=5:b_adapt=2:b_pyramid:weight_b:me=umh:frameref=5:mixed_refs:subq=9:trellis=1:8x8dct
You could also experiment with "trellis=2" and psy-trellis: "psy_rd=1.0,0.5"

-o test-x264-video.keyis5k250.mp4
This output is actually AVI, not MP4 since you haven't changed it with the -of parameter. MEncoder's MP4 muxing (-of lavf -lavfopts format=mp4) is also somewhat broken, or at least it was when I last checked. You should write a raw H.264 stream (which doesn't contain audio) with "-of rawvideo -o output.264", then encode audio separately and mux them together with MP4Box, for example.

You could also consider using neroaacenc or some speech codec to encode the audio instead of faac to get better quality/bitrate.

Blue_MiSfit
19th February 2009, 21:51
Yes, Nero's AAC encoder is quite a bit better than FAAC last I checked. HE-AAC should be the order of the day.

As far as x264 settings, here are my suggestions:

1) Keep deblocking at default settings
2) Don't use a CQM. x264's VAQ and psychovisual optimizations
3) Keep trellis at 1, if you're trying psy-trellis, keep it at low-ish settings like .2
4) Use subq=9, I'd take it over me=umh.

~MiSfit

niv
20th February 2009, 17:58
here is what I am using now, can someone tell me why it fails in the second pass?
are these options ok?

$ mencoder -vf yadif=0,hqdn3d -oac faac -ovc x264 -x264encopts bitrate=250:crf=25:threads=auto:bframes=5:b_adapt=2:b_pyramid:weight_b:me=umh:frameref=5:mixed_refs:subq=9:trellis=2:psy_rd=1.0,0.5:8x8dct:nopsnr:nossim:pass=2 -passlogfile tk-x264-pass.dat -o test-x264-video.keyis5k250.avi VTS_01_1.VOB
MEncoder dev-SVN-r28058-4.1.2 (C) 2000-2008 MPlayer Team
CPU: Intel(R) Xeon(R) CPU E5430 @ 2.66GHz (Family: 6, Model: 23, Stepping: 6)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2

success: format: 0 data: 0x0 - 0x3ffdd800
MPEG-PS file format detected.
VIDEO: MPEG2 720x576 (aspect 2) 25.000 fps 3750.0 kbps (468.8 kbyte/s)
[V] filefmt:2 fourcc:0x10000002 size:720x576 fps:25.000 ftime:=0.0400
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 48000 Hz, 2 ch, s16le, 256.0 kbit/16.67% (ratio: 32000->192000)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
Opening video filter: [pp=ci]
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
VDec: vo config request - 720 x 576 (preferred colorspace: Mpeg PES)
[PP] Using external postprocessing filter, max q = 6.
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: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffmpeg2] vfm: ffmpeg (FFmpeg MPEG-2)
==========================================================================
VDec: vo config request - 720 x 576 (preferred colorspace: Planar YV12)
[PP] Using external postprocessing filter, max q = 6.
VDec: using Planar I420 as output csp (no 1)
Movie-Aspect is 1.33:1 - prescaling to correct movie aspect.
x264 [info]: using SAR=16/15
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 PHADD SSE4 Cache64
x264 [error]: constant rate-factor is incompatible with 2pass.
x264_encoder_open failed.
FATAL: Cannot initialize video driver.

Exiting...

nm
20th February 2009, 18:31
here is what I am using now, can someone tell me why it fails in the second pass?
My example was perhaps a bit misleading: you are now telling x264 to use both CRF (constant rate-factor) and 2-pass ratecontrol at the same time. They are mutually exclusive.

- CRF is 1-pass, quality-based mode that keeps approximately the same quality level across different input videos, but does not guarantee a specific average bitrate.

- ABR and multi-pass encoding lets you specify a bitrate, but quality will vary greatly depending on the input video.

For more details, just google it or search the forum. In short, it is better to use CRF if you don't need to limit the output to a certain size. If you intend to stream your files (not progressive download, actual streaming), 2-pass is better for encoding under VBV limits, but then you need to add the vbv parameters to the command line too.

So either use one-pass CRF with "crf=X" where X is the quality level that you want (try 20-28), or 2-pass with "bitrate=Y" and "pass=N". Don't set "bitrate" and "pass" when using CRF.

are these options ok?
Looks fine otherwise, except that putting H.264 and AAC to AVI is probably a bad idea, especially if the video is encoded with B-frames and audio is not CBR.

Sharktooth
21st February 2009, 02:59
looks fine except you specified "pass=2" and "crf=25".
drop "pass=2"...

niv
21st February 2009, 16:01
well, now it is clear, should I post a bug to request mplayer to tell me my demands can't work?

cogman
21st February 2009, 17:10
well, now it is clear, should I post a bug to request mplayer to tell me my demands can't work?

Uhh, no? You cant tell x264 to use bitrate and crf in the same statement. crf is a bitrate calculation method, and bitrate is saying "use this bitrate". Both are mutually exclusive.

nm, AFAIK you can actually use CRF in two pass, but you don't gain anything from it. It's better in most cases to just use straight CRF (if you don't care about final file size all that much, IE you aren't shooting for trying to put one lecture on a CD or DVD or something).

kemuri-_9
21st February 2009, 18:34
nm, AFAIK you can actually use CRF in two pass, but you don't gain anything from it. It's better in most cases to just use straight CRF (if you don't care about final file size all that much, IE you aren't shooting for trying to put one lecture on a CD or DVD or something).


if( h->param.rc.i_rc_method == X264_RC_CRF && h->param.rc.b_stat_read )
{
x264_log(h, X264_LOG_ERROR, "constant rate-factor is incompatible with 2pass.\n");
return -1;
}

You can NOT CRF with 2pass in x264!

niv
21st February 2009, 18:51
do I need to run a first pass to generate the -passlogfile for the second crf pass without telling it is a second pass, or is CRF a single pass?

Snowknight26
21st February 2009, 19:11
CRF mode is the equivalent of one pass.

Sagekilla
21st February 2009, 19:56
In fact, crf is nothing more than a special case of one pass: One where it's not bitrate constrained. You can use a stats file from crf as input to a second pass, but CRF can -only- be used as a first pass.

niv
5th March 2009, 16:58
thanks you all , I was kind of stressed when asking and didnt understand your answers the first time. I managed to squeese a dvd down to 288Mb , and it looks fine, I am now wan to see how low I can go,
what is the best CRF value - you think I should try?

Niv

LoRd_MuldeR
5th March 2009, 17:40
thanks you all , I was kind of stressed when asking and didnt understand your answers the first time. I managed to squeese a dvd down to 288Mb , and it looks fine, I am now wan to see how low I can go,
what is the best CRF value - you think I should try?

There is no "best" per definition and you are not allowed to ask for it. You must find the highest possible CRF value that still looks good for your eyes!

Anyway, if you are now targeting for a specific file size, then CRF is not for you. Simply do a 2-Pass encode and that's it.

aaar9800
7th March 2009, 03:06
I was encoding some lectures a couple of months back, so I figured I'd share my experience in this thread.

It was a full class - 28 lectures and I wondered whether I could fill them all onto a single layer dvd. Deinterlacing the video with yadif and resizing to 576x432 produced a clear enough picture, so it was x264's turn.

First I encoded a couple of lectures with a lot of different settings for crf, keint, ref, bframes and qcomp to get a feeling for how they affect size and what looks good to my eyes. I put qcomp at 1, because x264 was throwing 2MBs for the first 1500 frames, which were made up of two static images. With qcomp at 1, they made up a tenth of what they did before. Maybe I should have used zones instead, but I didn't notice any adverse effects on the image.

The lectures had quite a bit of computer images - MATLAB simulations and such, so high ref and bframes numbers helped. Even though keint at 600 produced slightly smaller files, I ended up keeping keint at 10xFPS, as I wanted to have a finer control of seeking.

Having played with about 3 episodes, I had a pretty a good idea of the final file size. I then made some rough calculations to put video portion at about 3500MBs and that came out to be crf 24. I then encoded all of the video files and they totaled ~3450MB. The audio took the rest - encoded with vorbis at q0.4, which I found to produce the necessary ~66kbps.

Final lecture file sizes ranged all the way from 97MB to 193MB. I'm quite pleased with the result.

Here is the x264 command line I used:

--crf 24.0 --level 3.1 --keyint 300 --ref 8 --mixed-refs --bframes 5 --b-adapt 2 --b-pyramid
--weightb --direct auto --subme 9 --trellis 2 --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --qcomp 1.0
--me tesa --threads auto --thread-input --sar 1:1