Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 13th January 2012, 06:09   #1  |  Link
parent5446
Registered User
 
Join Date: Dec 2011
Location: Staten Island, NY
Posts: 14
x264 Video Filters

Quick question about the inner workings of x264's filter chain. I'm experimenting around and writing some new filters so that hopefully I can avoid Avisynth and other similar programs for basic pre-processing (primarily out of platform independence concerns). I've managed to figure out the basic interaction and have written filters for some of Avisynth's built-in filters (Reverse, FreezeFrame, SelectRangeEvery, and Trim), and now I'm looking to mess around with maybe a deinterlacing filter.

The only problem is that I have no idea how interlaced video is stored within x264. I've deduced that in progressive video each frame is stored in a cli_image_t (within a cli_pic_t) with an array of values for each plane in the image, but how is it done with interlaced video? My first guess would be that two fields are combined and stored as one frame, but it could be just as likely that each field is stored in a separate cli_image_t.

My secondary question is what the functionality of x264's cache filter. I mean the name makes it sound obvious, but I'm a little confused about how it would be used (or when it should be used) in the filter chain. The select_every filter uses a cache the size of the step_size, but I'm not entirely sure why because the filter doesn't technically need to rewind to other frames in the pattern in order to provide the next frame. And in the case of a deinterlacing filter, the filter would need access to the adjacent fields of the video, so would it be necessary to set up a cache for just two-three frame storage?

Thanks for the help.
parent5446 is offline   Reply With Quote
Old 13th January 2012, 07:18   #2  |  Link
Dark Shikari
x264 developer
 
Dark Shikari's Avatar
 
Join Date: Sep 2005
Posts: 8,690
Interlaced is just weaved, it's two fields per frame.
Dark Shikari is offline   Reply With Quote
Old 14th January 2012, 00:23   #3  |  Link
kemuri-_9
Compiling Encoder
 
kemuri-_9's Avatar
 
Join Date: Jan 2007
Posts: 1,348
the select every filter can rewind depending on the pattern supplied,
e.g. step=5,4,3,2,1,0 is a full reverse of each 5 frame set, this is a rewind operation and the frames need to be cached to allow this.

as such, if you're ever rewinding then you will particularly need to use the cache_filter to cache the frames that arrive.

This is primarily because of x264's ability to read in piped input where naturally rewinding is impossible, but you may want to filter it in certain ways anyway.

most of x264's input system currently assumes rewinding is impossible so even for inputs where it could rewind, it doesn't allow for it.
__________________
custom x264 builds & patches | F@H | My Specs
kemuri-_9 is offline   Reply With Quote
Old 14th January 2012, 07:55   #4  |  Link
parent5446
Registered User
 
Join Date: Dec 2011
Location: Staten Island, NY
Posts: 14
Thanks for the help! This will definitely help with the implementation of yadif as an x264 filter. In that case there's definitely going to need to be a small cache of one or two frames for the temporal prediction calculations. The interesting part is going to be implementing modes 1 and 3, which double the framerate and thus require new frames to be produced.

Also, kemuri-_9, I noticed your site has a patch that adds audio filters. Does this still work? I'm interested in what exactly is does.

Last edited by parent5446; 14th January 2012 at 08:00.
parent5446 is offline   Reply With Quote
Old 14th January 2012, 09:07   #5  |  Link
J_Darnley
Registered User
 
J_Darnley's Avatar
 
Join Date: May 2006
Posts: 959
Should I point out that a patch for that already exists? Okay, I haven't updated it in a long while. It wasn't very hard to make it double the frame rate.
__________________
x264 log explained || x264 deblocking how-to
preset -> tune -> user set options -> fast first pass -> profile -> level
Doom10 - Of course it's better, it's one more.
J_Darnley is offline   Reply With Quote
Old 14th January 2012, 15:32   #6  |  Link
kemuri-_9
Compiling Encoder
 
kemuri-_9's Avatar
 
Join Date: Jan 2007
Posts: 1,348
Quote:
Originally Posted by parent5446 View Post
Also, kemuri-_9, I noticed your site has a patch that adds audio filters. Does this still work? I'm interested in what exactly is does.
there was once a failed GSOC project that was to add audio input, filtering, and encoding support to x264 cli.
What you found is one such patch from when it was actually being developed.
I was the one primarily reviewing the student's work on it, as I wrote the existing video filter system.
Don't use that patch - there has been work done since then, so you can find a newer patch elsewhere if you are still inclined to look at it.

and J_Darnley is correct, he already wrote a patch to add yadif functionality to the video filter system.

inserting new frames is not particularly hard, simply indicate that you're adding frames during the filter initialization (if there is a non-zero framecount to begin with) then make those frames when they're requested.
__________________
custom x264 builds & patches | F@H | My Specs

Last edited by kemuri-_9; 14th January 2012 at 15:39.
kemuri-_9 is offline   Reply With Quote
Old 14th January 2012, 19:40   #7  |  Link
parent5446
Registered User
 
Join Date: Dec 2011
Location: Staten Island, NY
Posts: 14
Well if a patch already exists then that saves me a hell of a lot of time. XD Where is the patch now?
parent5446 is offline   Reply With Quote
Old 14th January 2012, 21:12   #8  |  Link
J_Darnley
Registered User
 
J_Darnley's Avatar
 
Join Date: May 2006
Posts: 959
There's probably an old one linked to around here somewhere. There will definitely be an old one on doom10, the filter thread in the h264 sub-forum. Regardless, it probably needs some changing due to the (not so) recent changes to the input and filter system. I'll see to it when I get back in front of the machine with it on.

[EDIT] Sorry, that will have to be in the morning. I did go to find this for you though: http://doom10.org/index.php?topic=177.0
__________________
x264 log explained || x264 deblocking how-to
preset -> tune -> user set options -> fast first pass -> profile -> level
Doom10 - Of course it's better, it's one more.

Last edited by J_Darnley; 15th January 2012 at 01:30.
J_Darnley is offline   Reply With Quote
Old 16th January 2012, 02:52   #9  |  Link
roozhou
Registered User
 
Join Date: Apr 2008
Posts: 1,181
Quote:
Originally Posted by kemuri-_9 View Post
inserting new frames is not particularly hard, simply indicate that you're adding frames during the filter initialization (if there is a non-zero framecount to begin with) then make those frames when they're requested.
Is it impossible to add a filter that adaptively add or remove frames? Since x264 always pull frame by its frame No. instead of timestamps.
roozhou is offline   Reply With Quote
Old 16th January 2012, 22:01   #10  |  Link
parent5446
Registered User
 
Join Date: Dec 2011
Location: Staten Island, NY
Posts: 14
Quote:
Originally Posted by roozhou View Post
Is it impossible to add a filter that adaptively add or remove frames? Since x264 always pull frame by its frame No. instead of timestamps.
You can adaptively add/remove frames. All you need to do is make sure to adjust the framerate in order to compensate for difference in frame count (or if you'r removing different amounts of frames in different sections, adjust the cli_pic_t.duration for VFR).
parent5446 is offline   Reply With Quote
Old 17th January 2012, 01:31   #11  |  Link
kemuri-_9
Compiling Encoder
 
kemuri-_9's Avatar
 
Join Date: Jan 2007
Posts: 1,348
Quote:
Originally Posted by roozhou View Post
Is it impossible to add a filter that adaptively add or remove frames? Since x264 always pull frame by its frame No. instead of timestamps.
Indeed x264cli does pull frames by number, and not by pts.
It standardly reads up until the number of known frames from the result of the filter chain, or the user specified count.

As such, the only way I can see to do this as freely as you seem to be desiring it, is to have your filter set the frame count to 0.
With this, the filter system will keep processing until something returns a failure code, as it has no clue how many frames there will be.
You can then add new frames or discard frames from previous filters in the chain fairly arbitrarily upon the requests to your specific filter.

If you don't specify the frame count as 0 then removing frames arbitrarily should still be applicable,
but adding them arbitrarily can prove to be limited as x264 will only read up to a certain number of frames before stopping.
__________________
custom x264 builds & patches | F@H | My Specs
kemuri-_9 is offline   Reply With Quote
Reply

Tags
filters, x264 dev

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:47.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.