Log in

View Full Version : Different crop values in different scenes


bokonon
8th June 2008, 12:55
I want to change the crop to include a caption that appears a few times in a video, but i don't want to encode black bars for the rest of the clip (which doesn't make use of the space where the caption appears). Is it possible to do this and still maintain correct AR with anamorphic encoding? Or will i need to resize each part to actual resolution and then merge them somehow? Here is my script at the moment:

http://img93.imageshack.us/img93/1235/asdasdasdu9.png

martino
8th June 2008, 13:24
You could do
Trim(0,999).Crop(something).Lanczos4Resize(last.width,last.height)++Trim(1000,9999).Crop(somethingelse)..Lanczos4Resize(last.width,last.height)
and so on. Then you could encode them separately with each part having a different AR set in the video stream (x264 --sar xx:xx) or in the container (there are probably tools which can calculate you what the value needs to be given the original resolution and AR, etc), mux them to MKV and use ordered chapters and segment linking to join them "virtually" into one file (read (http://www.uppcon.se/thefluff/hurfdurf/?p=8)). Or perhaps you can append video streams to each other in mkvmerge with different ARs, I never actually tried to do this myself. Perhaps worth a look too.

Could be rather lengthy, but I'm not sure whether there are other ways without introducing an AR error when cropping parts with different values, and if I understand correctly you're not talking about 1% or 5% error values here.

Stakiman
8th June 2008, 14:30
resw=500
resh=350
a=trim(0,999).crop(....).spline36resize(resw,resh)
b=trim(1000,0).crop(....).spline36resize(resw,resh)
clip=a+b
return clip

This should do it. :) No need to play with containers and stuff. ;-) (if you don't want to, actually)
Basically the important thing is to keep it in the same resolution.

mikeytown2
8th June 2008, 18:54
If you give me some more details, i think ZoomBox (http://forum.doom9.org/showthread.php?p=1111789#post1111789) can do the trick and keep the AR perfect.

A quick example. But if you give me more details, it could most likely be done a better way.

#set some variables
Width=720
Height=480
DAR=16.0/9.0
Resizer="LanczosResize"

#load file & apply filters.
video = MPEG2Source("file.d2v")
audio = WavSource("file.wav")
AudioDub(video,audio)

#set up for square pixel input, resize Video for DVD output as well.
#Change Align=-5 to 5 or read the ZoomBox documentation for more info on what align does
Video_full = ZoomBox(Width,Height,Resizer, TargetDAR=DAR, Align=-5 )
Video_crop = Crop(10,106,-6,-40).ZoomBox(Width,Height,Resizer, TargetDAR=DAR, Align=-5 )


#cut up file, using trim
partA = Video_full.trim(0,100)
partB = Video_crop.trim(101,200)
partC = Video_full.trim(201,300)
partD = Video_crop.trim(301,0)

#combine parts
PartA + PartB + PartC + PartD

bokonon
9th June 2008, 00:13
Thanks for all your replies! I like the sound of Zoombox, looks like a really nifty plugins. Here are some more details, hopefully u can help me implement it in your script, cuz I'm pretty useless at AVIsynth plugins:

Frames 94-284 and frames 5347-5585 are where the caption takes place. For this section here are the crop, size and DAR details:

size: 704x416
crop: (10,32,-6,-32)
DAR: 91:59

For all the other frames (0-93, 285-5346 + 5586-5665) the values are as follows:

size: 704x272
crop: (10,106,-6,-102)
DAR: 92:39

If you need any more details let me know :)

45tripp
9th June 2008, 01:12
there seems to be a fair amount of black still at the bottom,
what about overlaying the caption?

mikeytown2
9th June 2008, 01:38
I could use the DAR of the mpeg2 file. Without doing a crop, what do you have to resize it to, in order for it to look correct?

Also what the the DAR setting in your encoder, 16/9? I need to know that as well.

This is all I need, thus you shouldn't have to do all the AR calculations, but since you did i can still use them.


Using the values you gave me, this will not show any black bars, but it will crop more to make the image fit. There is no way around this, you have to crop, show black bars, or have a distorted image. To show black bars change Align to -5.

Using the trick that martino is talking about is interesting, but is sounds like it would be quite difficult to do. Using the MKV trick would allow the player to undistort the encoded video, by setting a custom DAR, or have a video with 2 different frame sizes.


#set some variables
Width=704
Height=416
DAR=91.0/59.0
Resizer="LanczosResize"

#load file & apply filters.
video = MPEG2Source("file.d2v")
audio = WavSource("file.wav")
AudioDub(video,audio)

#deinterlace?

video_full = Crop(10,32,-6,-32).ZoomBox(Width,Height, sourceDAR=91.0/59.0, align=5)
video_Crop = Crop(10,106,-6,-102).ZoomBox(Width,Height, sourceDAR=92.0/39.0, align=5)

p1 = video_crop.trim(0,93)
p2 = video_full.trim(94,248)
p3 = video_crop.trim(285,5346)
p4 = video_full.trim(5347,5585)
p5 = video_crop.trim(5586,5665)

p1+p2+p3+p4+p5

bokonon
9th June 2008, 10:27
Thanks for all the help mikeytown2: I used your script,which now looks something like this #set some variables
Width=704
Height=416
DAR=91.0/59.0
Resizer="LanczosResize"

#load file & apply filters.
video = DGDecode_mpeg2source("D:\[[ Encoding ]]\06 - amores perros extras\3 Music Video 1 - Julieta Venegas\VTS_03_1.d2v",info=3)

ConverttoYV12
ColorMatrix()
tfm().tdecimate()
RemoveGrain(1)
#deinterlace?

video_full = Crop(10,32,-6,-32).ZoomBox(Width,Height, sourceDAR=91.0/59.0, align=5)
video_Crop = Crop(10,106,-6,-102).ZoomBox(Width,Height, sourceDAR=92.0/39.0, align=5)

p1 = video_crop.trim(0,93)
p2 = video_full.trim(94,248)
p3 = video_crop.trim(285,5346)
p4 = video_full.trim(5347,5585)
p5 = video_crop.trim(5586,5665)

p1+p2+p3+p4+p5

Unfortunately my audio track is not wav (it is ac3) so i can't seem to dub it. Also my filters aren't recognized by AVsP so i must be doing something wrong there.

Without cropping at all, 640x480 corrects the aspect ratio (PAR 8:9)

When i come to encode x264 takes the DAR values and converts them to SAR - is this what you need to know?

mikeytown2
9th June 2008, 19:35
Unfortunately my audio track is not wav (it is ac3) so i can't seem to dub it. Also my filters aren't recognized by AVsP so i must be doing something wrong there.

Without cropping at all, 640x480 corrects the aspect ratio (PAR 8:9)

When i come to encode x264 takes the DAR values and converts them to SAR - is this what you need to know?

If you want to add AC3 into your script, I recommend NicAudio (http://www.codeplex.com/NicAudio).

"x264 takes the DAR values" what are these DAR values? I'll come back, after I change ZoomBox and post a simpler example (in terms of math calculations needed). Because right now, you do need to calculate the 91/59, but in the future this shouldn't be necessary. So this script is done, in terms of ZoomBox usage.

Also thanks for giving ZoomBox a spin. ZoomBox can do crops, but then it doesn't use the Align/DAR options on the interal crop. I need to add in that functionality, thus the crop() in front of zoomBox can be used inside of it and then you don't need to do the AR calculations. Me personally i hate doing AR calculations, that is part of the motivation behind ZoomBox. I figured DAR is the easiest to do Conceptually because it's, what do i need to resize this clip to in order for it to look correct.

mikeytown2
12th June 2008, 10:52
I attempted to get ZB working with the crop inside, but it was getting ugly fast. I did implement PAR though so for this example you could write the code like this


#set some variables
Width=704
Height=416
PAR=8.0/9.0
Resizer="LanczosResize"

#load file & apply filters.
video = DGDecode_mpeg2source("D:\[[ Encoding ]]\06 - amores perros extras\3 Music Video 1 - Julieta Venegas\VTS_03_1.d2v",info=3)

ConvertToYV12()
ColorMatrix()
tfm().tdecimate()
RemoveGrain(1)

video_full = Crop(10,32,-6,-32).ZoomBox(Width,Height, sourcePAR=PAR, align=5)
video_Crop = Crop(10,106,-6,-102).ZoomBox(Width,Height, sourcePAR=PAR, align=5)

p1 = video_crop.trim(0,93)
p2 = video_full.trim(94,248)
p3 = video_crop.trim(285,5346)
p4 = video_full.trim(5347,5585)
p5 = video_crop.trim(5586,5665)

p1+p2+p3+p4+p5


For this example to work you need to get the June 12th version of ZoomBox. If you do try this code out, let me know if it worked correctly!