Log in

View Full Version : encoding mp2 interlaced to avc progressive


Chumbo
3rd December 2011, 20:12
I'm running into an odd situation that I'm blanking on. I have some old DVD stuff that I had ripped to MKV files. These are mpeg2 interlaced files @ 29.970. Here's a sample mediainfo output for one of the files
General
Unique ID :
Complete name : file.mkv
Format : Matroska
Format version : Version 2
File size : 544 MiB
Duration : 16mn 16s
Overall bit rate mode : Variable
Overall bit rate : 4 678 Kbps
Encoded date : UTC 2011-11-25 17:04:26
Writing application : MakeMKV v1.6.16 win(x64-release)
Writing library : libmakemkv v1.6.16 (1.2.0/1.1.0) win(x64-release)

Video
ID : 1
Format : MPEG Video
Format version : Version 2
Format profile : Main@Main
Format settings, BVOP : No
Format settings, Matrix : Custom
Codec ID : V_MPEG2
Codec ID/Info : MPEG 1 or 2 Video
Duration : 16mn 16s
Bit rate mode : Variable
Bit rate : 4 393 Kbps
Maximum bit rate : 9 000 Kbps
Width : 720 pixels
Height : 480 pixels
Display aspect ratio : 4:3
Frame rate : 29.970 fps
Standard : NTSC
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Interlaced
Scan order : Top Field First
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.424
Stream size : 511 MiB (94%)
Language : English
Default : Yes
Forced : No

Audio
ID : 2
Format : AC-3
Format/Info : Audio Coding 3
Mode extension : CM (complete main)
Codec ID : A_AC3
Duration : 16mn 16s
Bit rate mode : Constant
Bit rate : 192 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 22.3 MiB (4%)
Title : 2/0
Language : English
Default : Yes
Forced : No
I want to encode this file and other like it to AVC using x264 encoder but no matter how I configure the encoding I get vide/audio that is not in sync. Basically they don't match and it's driving me nuts.

I was hoping someone, with x264 encoding expertise, can provide some guidance please. Since it's marked as interlaced @ 29.970, shouldn't the audio sync up to 23.976p video? That's essentially how I am encoding it, i.e., x264_64.exe --pass 1 --bitrate 233 --fps 24000/1001 --tff --index "file.mkv.ffindex" --stats "file.stats" --output NUL "file.mkv"
x264_64.exe --pass 2 --bitrate 233 --fps 24000/1001 --tff --index "file.mkv.ffindex" --stats "file.stats" --output NUL "file.mkv"Thanks for any help you can provide.

b66pak
3rd December 2011, 20:16
change "--fps 24000/1001" to "--fps 30000/1001"...
_

Chumbo
3rd December 2011, 20:21
change "--fps 24000/1001" to "--fps 30000/1001"...
_
Yep, I just tried that as the encoding just finished and it didn't work. Basically the audio runs the 16m 16s but the video finishes at around 13m 04s. [beating my head against the wall emoticon goes here]

[edit1]Oh, here's the line:x264_64.exe --pass 1 --bitrate 233 --fps 30000/1001 --sar 10:11 --tff --vbv-maxrate 8000 --vbv-bufsize 8000
--index "file.mkv.ffindex" --stats "file.stats" --output NUL "file.mkv"

[edit2] The line below produces a 16m 20s output file so there's a 4 second discrepancy which is why the audio/video are not insync all the way through as wellx264_64.exe --pass 1 --bitrate 233 --fps 24000/1001 --sar 10:11 --tff --vbv-maxrate 8000 --vbv-bufsize 8000
--index "file.mkv.ffindex" --stats "file.stats" --output NUL "file.mkv"

[edit3] The version of the x264 encoder I'm using: x264 core:119 r2106 07efeb4

nm
3rd December 2011, 20:40
What movie is it? Maybe there are a few 30i sequences within the mostly soft-telecined film. Does audio drift constantly more and more or does the sync change quickly at certain points during the movie?

If it's a hybrid source, I'd suggest the AviSynth & TIVTC route.

Chumbo
3rd December 2011, 20:45
No, it definitely drifts. It's an old Three Stooges episode I ripped from my DVD collection. Here's a bit more info. I am using ffms to create the index file, however, when x264 runs, I just noticed this:ffms [info]: 720x480i 8:9 @ 24100/1001 fps (cfr)I don't understand the 8:9 and 24100. Ideas? How can I tell if x264 is using my .ffindex file or not? Maybe that's the problem? I was hoping to avoid AVISynth to be honest. Let me scan the file with DGIndex and see what it finds. I didn't think about this until you said hybrid.

[edit1] Okay, DGIndex did find a field shift near the end of the file which it corrected as follows:D2V Fix Output

Field order transition: 0 -> 2
900 5 0 401064408 0 0 0 72 73 d0 f1 f2 e3 f0 f1 e2 f3 f0 e1
900 5 0 401402021 0 0 0 72 73 d0 f1 f2 e3 f0 e2 f3 f0 e1
corrected...
900 5 0 401064408 0 0 0 72 73 d0 f1 f2 e3 f0 f1 e2 f3 f0 e1
900 5 0 401402021 0 0 0 72 73 d0 f1 f2 e3 f1 e2 f3 f0 e1

And here's the DGIndex info of the file:Stream_Type=0
MPEG_Type=2
iDCT_Algorithm=6
YUVRGB_Scale=1
Luminance_Filter=0,0
Clipping=0,0,0,0
Aspect_Ratio=4:3
Picture_Size=720x480
Field_Operation=0
Frame_Rate=29970 (30000/1001)
Location=0,0,0,440e4

b66pak
3rd December 2011, 20:56
use "--fps 24100/1001" and i bet you will get a in sync file...8:9 is the sar...so use "--sar 8:9" to get a 640x480 file...
_

Chumbo
3rd December 2011, 21:03
use "--fps 24100/1001" and i bet you will get a in sync file...8:9 is the sar...so use "--sar 8:9" to get a 640x480 file...
_
I'm using 720x480 which is what the source is so I'm trying to figure out how 8:9 is being calculated and where's the 24100 coming from?

I encode using the CLI so in order to figure out info like FPS and DAR/SAR, I use mediainfo to get that info. Why would ffms report something different you think? I'll try what you suggest and see the results. I went ahead and used the MEGUI 64 UI for now to create an AVS script that uses TIVTC and should be done shortly. I'm curious to see the results.

[edit1] Quick question. Since that info is in the ffms index file, do I need to specify the --fps and --sar? I'm wondering if I can just leave those out and let the encoder use what it finds in the ffms index file right?

b66pak
3rd December 2011, 21:06
720:480 x (8:9) = 640:480 = 4:3...please trust ffms...
_

L.E.

13m04s x 30000/1001 = 23496 frames

16m20s x 24000/1001 = 23496 frames

now 23496 frames: (24100/1001) = 16m16s

so here are your 4 seconds...
_

Chumbo
3rd December 2011, 21:17
720:480 x (8:9) = 640:480 = 4:3...please trust ffms...
_
Oh I do, that's why I'm letting it do the work. :) Of course the non-letterboxed area is 4:3, so yes, that part is 640x480.

So here's the deal. The TIVTC script worked great using the D2V file DGIndex generated (the fixed one).LoadPlugin("E:\MultiMediaTools\megui64\tools\dgindex\DGDecode.dll")
DGDecode_mpeg2source("file.d2v", info=3)
LoadPlugin("E:\MultiMediaTools\megui64\tools\avisynth_plugin\ColorMatrix.dll")
ColorMatrix(hints=true, interlaced=true, threads=0)
LoadPlugin("E:\MultiMediaTools\megui64\tools\avisynth_plugin\TIVTC.dll")
tfm(order=1).tdecimate()
I'm now tyring the encode without the --fps and --sar and see how it turns out.

b66pak
3rd December 2011, 21:22
what do you mean by great? is the encode in sync? if it is, then that is your best method to deal with it...
_

Chumbo
3rd December 2011, 21:41
what do you mean by great? is the encode in sync? if it is, then that is your best method to deal with it...
_
I wasn't being sarcastic if that's what you mean. Not sure how you would get that in this context. So, yes, great=I got the results I'm looking for and a/v in sync. :D

I was just hoping to not have to use yet another tool, i.e., DGIndex to to determine issues like this. Hopefully only a few files will have this and I can batch encode the rest without issues. Thanks a lot for the help on this. :)

Chumbo
3rd December 2011, 21:52
Quick question regarding ffms. I realize the executable ffmsindex indexes the file but doesn't provide info like the mediainfo CLI. Is there anything that uses ffms to provide the info so I can get that correctly, i.e., the 8:9 and 241001?