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 > Capturing and Editing Video > Avisynth Usage
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th August 2008, 23:03   #1  |  Link
buletti
Registered User
 
Join Date: Jun 2007
Posts: 42
Frame Interpolation using MVTools

Hi folks,

I'm trying to created a script to convert 24 fps to 30 fps. Instead of using a pulldown that is basically repeating existing frames to match the frame rate, I wanted to compute new, intermediate frames. Here's the script:

Code:
function convert24to30(clip clp) {
clp
AssumeFPS(24)      # treat 23.976 as 24.00

### segement the base clip in 6 clips of 4 frames
firstSet            = SelectEvery(24, 0,1,2,3)          # frame set of 4 frames
firstEndFrame       = SelectEvery(24, 3)                # remember last frame of the set

secondSet           = SelectEvery(24, 4,5,6,7)
secondEndFrame      = SelectEvery(24, 7)

thirdSet            = SelectEvery(24, 8,9,10,11)
thirdEndFrame       = SelectEvery(24, 11)

fourthSet           = SelectEvery(24, 12,13,14,15)
fourthEndFrame      = SelectEvery(24, 15)

fifthSet            = SelectEvery(24, 16,17,18,19)
fifthEndFrame       = SelectEvery(24, 19)

sixthSet            = SelectEvery(24, 20,21,22,23)
sixthEndFrame       = SelectEvery(24, 23)

### interpolate a fifth frame for the set of four frames 
newFrameFive        = generateFrame(firstEndFrame)
### create sequence 0,1,2,3,new frame
firstSetOfFive      = UnalignedSplice(firstSet, newFrameFive.AssumeFPS(firstSet))

newFrameTen         = generateFrame(secondEndFrame)
secondSetOfFive     = UnalignedSplice(secondSet, newFrameTen.AssumeFPS(secondSet))

newFrameFifteen     = generateFrame(thirdEndFrame)
thirdSetOfFive      = UnalignedSplice(thirdSet, newFrameFifteen.AssumeFPS(thirdSet))

newFrameTwenty      = generateFrame(fourthEndFrame)
fourthSetOfFive     = UnalignedSplice(fourthSet, newFrameTwenty.AssumeFPS(fourthSet))

newFrameTwentyfive  = generateFrame(fifthEndFrame)
fifthSetOfFive      = UnalignedSplice(fifthSet, newFrameTwentyfive.AssumeFPS(fifthSet))

newFrameThirty      = generateFrame(sixthEndFrame)
sixthSetOfFive      = UnalignedSplice(sixthSet, newFrameThirty.AssumeFPS(sixthSet))

### combine the 6 5-frame-sets
UnalignedSplice(firstSetOfFive, secondSetOfFive, thirdSetOfFive, fourthSetOfFive, fifthSetOfFive, sixthSetOfFive)

return last
}


function generateFrame(clip clp) {
global idx1         = 10 
idx1                = idx1 + 1
backward_vec        = clp.MVAnalyse(isb = true,  truemotion=true, blksize=8, overlap=4, pel=2, search=3,
\                                   searchparam=10, sharp=2, idx=idx1, dct=1)
forward_vec         = clp.MVAnalyse(isb = false, truemotion=true, blksize=8, overlap=4, pel=2, search=3,
\                                   searchparam=10, sharp=2, idx=idx1, dct=1)
newFrame            = clp.MVFlowInter(backward_vec, forward_vec, time=50.0, mL=80.0, thSAD=300, idx=idx1)

return newFrame
}
The script works fine in respect of increasing the frame rate. However, I'm wondering about the results of MVFlowInter. The generated frames look exactly the same as their originating frames. I cannot see that MVFlowInter creates a "picture at some intermediate time moment between current and next frame". Considering the "time" parameter I expected a frame that is temporally located in the middle between "current" and "next". Instead I just get another "current".
Any hints are appreciated.
buletti is offline   Reply With Quote
Old 4th August 2008, 23:28   #2  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Code:
function generateFrame(clip clp) {
# global idx1     = 10  ## <-- move this assignment to the very start your script! (NOT inside of any function{} block.)
global idx1       = idx1 + 1  ## <-- add this "global" verb
...etc...
Try like that. You original code did reset the global idx to 10 every time when generateFrame() was called. That caused the wrong subpel clip to be used ... there it went down the drain.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 5th August 2008, 05:58   #3  |  Link
Alex_ander
Registered User
 
Alex_ander's Avatar
 
Join Date: Apr 2008
Location: St. Petersburg, Russia
Posts: 334
@buletti
Why don't you use MVFlowFPS() instead? It will rebuild all frames and that's necessary here.
Alex_ander is offline   Reply With Quote
Old 6th August 2008, 20:03   #4  |  Link
buletti
Registered User
 
Join Date: Jun 2007
Posts: 42
@Didée: Thanks for the hint about the global idx variable. However, I still can not get the expected result. Using the script in FFDShow seems to merely repeat every fourth frame. Using the script in AvsP or VirtualDub gives strange results likely due to the wild clip merging.

@Alex_ander: I wanted to use the script during playback in FFDShow. So, I assumed that interpolating 6 new frames could be feasible whilst interpolating 30 new frames with MVFlowFPS is not. However, why is it a bad idea to reuse the existing 24 frames?
buletti is offline   Reply With Quote
Old 6th August 2008, 20:11   #5  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
Why would interpolating 6 new frames with MVFlowFPS be impossible I've interpolated content from 30p to 60p before, I don't see why it can't do 24p to 30p.

Last edited by Sagekilla; 6th August 2008 at 20:18.
Sagekilla is offline   Reply With Quote
Old 6th August 2008, 20:23   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by buletti View Post
Using the script in FFDShow seems to merely repeat every fourth frame.
Replace
Code:
UnalignedSplice(firstSetOfFive, secondSetOfFive, ..., sixthSetOfFive)
with
Code:
Interleave(firstSetOfFive, secondSetOfFive, ..., sixthSetOfFive)
The movement won't be as fluid as using MVFlowFPS but, as you say, the latter is too slow for real-time playback.

EDIT: No, Interleave done as above is still wrong because it takes one frame at a time from each group. What you need if you are going to use this approach is something like
Code:
c0 = SelectEvery(4, 0)
c1 = SelectEvery(4, 1)
c2 = SelectEvery(4, 2)
c3 = SelectEvery(4, 3)
new = ??? # what goes here?
Interleave(c0, c1, c2, c3, new)
where new is the new set of additional frames. But I don't think your GenerateFrame will give you the right frames anyway, so a rethink is required.

You're probably better off just using ChangeFPS or ConvertFPS.

Last edited by Gavino; 6th August 2008 at 20:55. Reason: Correction
Gavino is offline   Reply With Quote
Old 6th August 2008, 21:14   #7  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
What do you mean? It's very possible to do RT MVFlowfps, if you're trying to do it for playback. Just use faster settings (pel=1, overlap=0, chroma=false, blksize=16) and it should work perfectly fine. You'll get more artifacts that way, but I don't think you'll actually notice them most of the time. Only if you're encoding would you avoid that..
Sagekilla is offline   Reply With Quote
Old 7th August 2008, 13:35   #8  |  Link
Alex_ander
Registered User
 
Alex_ander's Avatar
 
Join Date: Apr 2008
Location: St. Petersburg, Russia
Posts: 334
Quote:
Originally Posted by buletti View Post
... why is it a bad idea to reuse the existing 24 frames?
Because this would produce jerkyness due to local slowdown at each 5th frame (considering original motion with constant speed, e.g. panning) after setting all frames equidistantly. Speed variations would be more noticeable than with pulldown, which inserts a field (not full frames) into each pair of input frames.
It is quite possible to only insert interpolated frames e.g. first using ChangeFPS(30) for addition of repeated frames, then using this function:
http://forum.doom9.org/showthread.php?t=104294
which replaces repeating frames with ones created by MVFlowInt(), but I'd still prefer MVFlowFPS().
Alex_ander is offline   Reply With Quote
Reply


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 05:26.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.