Log in

View Full Version : How to change the Scan Order of avi?


P.J
20th February 2016, 18:40
Anyway to change the Scan Order of AVI container (DVsd) from BFF to TFF without re-encoding?
ReStream can do it but only for MPEG2/VOB :(

Emulgator
22nd February 2016, 17:35
From what I read, this can not be specified in DV, it is always assumed to be BFF.
If you have to manipulate DV fields around you will have to do this physically, I guess.

P.J
23rd February 2016, 10:26
What if I remux it in .mov?

Music Fan
25th February 2016, 19:15
If you need real TFF, you will have to convert, as suggested by Emulgator.
A simple header change is only appropriate when the Scan Order is wrong (for example if you specify TFF when you encode your avi while it's actually BFF).
MPEG4Modifier can do this with divx5 (an Xvid), maybe not with DVsd.

P.J
27th February 2016, 20:55
MPEG4Modifier can't do it :(
Does any other container except avi support DVsd format?

Music Fan
28th February 2016, 01:02
Maybe mkv but even if you find a way to change the parity, don't do it. If you specify TFF while it's BFF, the video won't be decoded properly.

WorBry
28th February 2016, 15:22
Maybe mkv but even if you find a way to change the parity, don't do it. If you specify TFF while it's BFF, the video won't be decoded properly.

Agree entirely. Only way to do it AFAIK is by reversing the field dominance using the AVISynth ReverseFieldDominance filter:

http://avisynth.org.ru/docs/english/externalfilters/reversefielddominance.htm

So, yes, that will mean re-encoding if you plan to keep it in DV format. In which case you'd be wanting to transcode to the vfwMatrox DV codec which is TFF. Otherwise a lossless intermediate. Or use the Matrox DV codec as the decoder for AVISynth if you want to output TFF for transcoding to another TFF format.

Many moons ago I used to use the Matrox DV codecs before Cedocida came along.

http://www.matrox.com/video/en/support/windows/vfw_software_codecs/downloads/softwares/version1.0/

P.J
28th February 2016, 18:01
Mkvtoolnix couldn't do it.
I don't wanna re-encode to avoid quality loss :(

Music Fan
28th February 2016, 18:06
From Dvsd to Dvsd (with an avisynth process between both files), you won't see easily any difference.

By the way, ReStream don't transform tff in bff (or bff in tff), it only corrects bad parity, as MPEG4Modifier does with divx.
Parity can not be changed without re-encoding, whatever the codec.

WorBry
28th February 2016, 19:01
From Dvsd to Dvsd (with an avisynth process between both files), you won't see easily any difference.


Exactly. If you do that though, use Cedocida's DV codec for the initial decode:
http://www.cithraidt.de/cedocida/index.html

and configure the output:

http://i.imgur.com/cANJFFH.png

It's been a while since I used it, but IIRC the "DV" YV12 chroma sampling option is for direct pass-thru and only applies to PAL DV sources.

Edit: Ah yes, the explanation is given there in the codec description:

Some remarks on "YV12 (DV)" input/output option in combination with NTSC video:
Because NTSC DV uses 4:1:1 subsampling type, you will see weird color when viewed with a normal YV12 program which assumes 4:2:0. This is no bug. If you need YV12 format for producing DVD content, use the option "YV12 (MPEG 2 *)".

P.J
29th February 2016, 12:00
Would you explain in depth? I'm not familiar with AviSynth and encoding =/

WorBry
29th February 2016, 15:18
Have you used AviSynth and/or VirtualDub before at all ?

What system are you going to be putting these files into and for what goal - transcoding to another TFF format?

In other words, do you actually need DVsd.avi files with the fields reversed or is there scope for frame-serving TFF from AVISynth?

WorBry
5th March 2016, 05:36
As per your PM, you confirmed that you want to create a DV file with the field order reversed.

It's been a while since I worked with DV, but having run a few tests I recall now that the Matrox DV codecs
are a PITA to use (and only output RGB) and that it can all be done using the Cedocida DV codec and
the ReverseFieldDominance filter.

You will need to get a little acquainted with AVISynth and processing scripts in VirtualDub, but there's no
lack of documentation for beginners - the AVISynth wiki for one:

http://avisynth.nl/index.php/Main_Page

So, here’s the procedure:

1.Install AVISynth:
https://sourceforge.net/projects/avisynth2/

2. Install VirtualDub:
https://sourceforge.net/projects/virtualdub/files/?source=navbar
Note: "Open-up VirtualDub" in the procedures below means clicking on the VirtualDub.exe file in the folder that
you extracted the zip file to. For convenience create a shortcut to the exe file on your desktop.

3.Install ReverseFieldDominance plugin
http://web.archive.org/web/20091028073306/http://geocities.com/siwalters_uk/reversefielddominance.html

Download and unzip version 1.2 and copy the reversefielddominance.dll to the AVISynth plugins folder:

32bit Windows: C:\Program Files\AviSynth 2.5\plugins
64bit Windows: C:\Program Files (x86)\AviSynth 2.5\plugins

4. Install Cedocida DV codec
http://www.cithraidt.de/cedocida/index.html
Download and upzip version 0.2.3. Right click on the cedocida_dv_only.inf file and Install.
Open up VirtualDub >Video>Compression and you should see the Cedocida DV codec listed there.

http://i.imgur.com/w8iwtY2.png

Click on the Cedocida codec > Configure, and configure like so:

http://i.imgur.com/VyfR068.png

Set the appropriate aspect ratio for your DV source.
Click OK, to save configuration.

5. Open up Notepad and paste in this script:

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\ReverseFieldDominance.dll")
#LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\ReverseFieldDominance.dll")
#
AVISource("C:\...path...\Video.avi", audio=false).AssumeFPS(30000,1001)
AssumeBFF()
ReverseFieldDominance()
AssumeTFF()

Where,
AVISource("C:\...path...\Video.avi", audio=false).AssumeFPS(30000,1001)
is the path of your DV video and AssumeFPS is the framerate:
AssumeFPS(30000,1001) for NTSC 60i DV
AssumeFPS(25,1) for PAL 50i DV

Set the path of the ReverseFieldDominance.dll as appropriate for your system.

Name and save script as .avs file.

6.Open up the DV video file in VirtualDub and extract the WAV audio:
File>Open Video File>Save WAV. The encode job should autostart.

7.Open up the avs script in VirtualDub:
File>Open Video File and select the avs script. The video output should display.
Go to Video>Compression again, select the Cedcocida DV codec. Check the codec configuration is still as above. Click OK.
Select Fast Recompress
Go to Audio> Audio from another file, and select the extracted WAV audio
Go to File> Queue Batch operation>Save as AVI. Name and save the output avi file.
Go to Job>Start, to start encoding

The encoded avi file should now be DV with TFF field order.

I think that’s adequately in-depth, and serves as a good introduction to using AVISynth

P.S. Sorry about the text formatting.

WorBry
7th March 2016, 04:03
@P.J. So were you successful in applying the above method ?

P.J
8th March 2016, 20:46
Thank you very much :thanks:

I'll try it soon, hope I can do it :D

WorBry
9th March 2016, 02:45
Just follow the steps.

Mounir
9th March 2016, 18:23
with avisynth you can use this code to change the field dominance:
avisource()
separatefields().trim(1,0).weave()
or also (u have to convert in yuy2 before):

converttoyuy2(interlaced=true).crop(0,1,0,0).addborders(0,0,0,1).converttoyv12(interlaced=true)

WorBry
9th March 2016, 21:19
The Reverse Field Dominance plugin requires YUY2 also - that's why I advised configuring the Cedocida codec as shown.

Music Fan
9th March 2016, 21:29
The Reverse Field Dominance plugin requires YUY2 also - that's why I advised configuring the Cedocida codec as shown.
Thus you should add converttoyuy2(interlaced=true) before ReverseFieldDominance() in your script.
And if you put converttoyv12(interlaced=true) after ReverseFieldDominance() in this script, you can configure the input as yv12 in the Cedocida settings, otherwise Cedocida will convert itself yuy2 to yv12 ; I don't know if it's as well done as with avisynth.

WorBry
9th March 2016, 22:08
Thus you should add converttoyuy2(interlaced=true) before ReverseFieldDominance() in your script.

Why? Note in the screenshot, Cedocida is configured to output YUY2.

And if you put converttoyv12(interlaced=true) after ReverseFieldDominance() in this script, you can configure the input as yv12 in the Cedocida settings, otherwise Cedocida will convert itself yuy2 to yv12 ; I don't know if it's as well done as with avisynth.

As I recall, way back when, there was a lengthy forum discussion in which Cedocida himself clarified the internal color space transforms that take place, and there was confidence that all is performed correctly. So, yes, I could have just as easily added ConvertToYV12(interlaced=true) to script and configured the Cedocida encoder for YV12 input with "MPEG-2 interlaced" chroma subsampling. I tested the described method "as-is" and it works fine. So, for the O.P's benefit, probably best not to complicate matters with alternative approaches that amount to the same thing.

P.J, just do it as described and it will work just fine.
If you want to satisfy yourself that the field order is indeed changed to TFF, simply load the encoded avi file with this script:

AVISource("C:\...path...\EncodedVideo.avi", audio=false).AssumeFPS(30000,1001)
AssumeTFF()
SeparateFields()

And then, using the >> control button at the bottom of the VirtualDub screen, advance the video frame by frame. If it is TFF, the motion will be 'normal'. If it were BFF, it would jerk back and to.

The only thing that could complicate matters is if your source DV is in Type I format. In which case, you'll need to convert it to Type II beforehand:

http://www.videohelp.com/software/DV-Type-1-to-DV-Type-2-Converter

(As long as the source file is <4GB)

And let us know how you get on. We're all rooting for you ;)

Music Fan
9th March 2016, 22:40
Why? Note in the screenshot, Cedocida is configured to output YUY2.
What does the output mean in this case ? Dvsd is always in yv12, right ?

WorBry
9th March 2016, 23:23
It means Cedocida internally converts DV 4:2:0 (PAL) or 4:1:1 (NTSC) to YUY2 for output....correctly.

http://forum.doom9.org/showthread.php?p=844231#post844231

WorBry
12th March 2016, 16:19
Would you explain in depth? I'm not familiar with AviSynth and encoding =/

Which I did.

So, for the O.P's benefit, probably best not to complicate matters with alternative approaches that amount to the same thing.

P.J, just do it as described and it will work just fine.

.......And let us know how you get on. We're all rooting for you ;)

Wonder why I bothered now.

P.J
13th March 2016, 15:30
Wow, thanks a lot!
Just followed your tutorial and it fixed the problem :D

Edit: Which script is better? the first one or this: (since I know, DV is mostly BFF)
AVISource("C:\...path...\EncodedVideo.avi", audio=false).AssumeFPS(30000,1001)
AssumeTFF()
SeparateFields()

And how to detect if my source is DV Type I or II?

WorBry
13th March 2016, 16:12
Wow, thanks a lot!
Just followed your tutorial and it fixed the problem :D

There you go :) - I guess it did amount to a tutorial.

Edit: Which script is better? the first one or this: (since I know, DV is mostly BFF)
AVISource("C:\...path...\EncodedVideo.avi", audio=false).AssumeFPS(30000,1001)
AssumeTFF()
SeparateFields()

As explained, that script is purely to confirm the field order - not to change it:

If you want to satisfy yourself that the field order is indeed changed to TFF, simply load the encoded avi file with this script:

AVISource("C:\...path...\EncodedVideo.avi", audio=false).AssumeFPS(30000,1001)
AssumeTFF()
SeparateFields()

And then, using the >> control button at the bottom of the VirtualDub screen, advance the video frame by frame. If it is TFF, the motion will be 'normal'. If it were BFF, it would jerk back and to.


And how to detect if my source is DV Type I or II?

If it had been Type I you wouldn't have been able to load it with AVISynth, at least not as an AVISource using the Cedocida DV codec.

Edit: Correction on that - just dug out and tested a Type I DV.avi file that I had archived. Actually it loads OK. I recall now, what used to happen with VirtualDubMod is that you couldn't extract the WAV audio. Not a problem with VirtualDub 1.10.4. So you would have been OK even if it was Type I.

Music Fan
13th March 2016, 16:34
It means Cedocida internally converts DV 4:2:0 (PAL) or 4:1:1 (NTSC) to YUY2 for output....correctly.

http://forum.doom9.org/showthread.php?p=844231#post844231
Thus output means this setting is used when playing (decoding) it ?
Why does it have to be converted into yuy2 when played ?

WorBry
13th March 2016, 16:57
Why does it have to be converted into yuy2 when played ?

It doesn't. I merely configured Cedocida for YUY2 output in this instance because ReverseFieldDominance requires YUY2. That's all.

P.J
13th March 2016, 17:10
Thanks again :)

The last problematic video is .TS H.264 50fps progressive that need to be converted to 25fps interlaced.
The source's frames are all interlaced and also duplicated (AABBCCDD, all interlaced)
How is it possible to fix it with minimal quality loss? :(
Not sure if I should create a new topic for it or not =/

WorBry
13th March 2016, 17:28
Might be a good idea, since it's not DV related.

Music Fan
13th March 2016, 18:12
edit : I believe I understand what you mean, I forgot that Cedocida was also used in the first script's line (and not only for re-encoding), and the video becomes yuy2 from the first line because Cedocida's output is set on yuy2. And as the video is re-encoded with Cedocida too, the input and output work at the same time.
Anyway I find it confusing, I prefer to use Avisynth conversion and configure Cedocida's input and output in yv12.

Music Fan
13th March 2016, 18:34
Thanks again :)

The last problematic video is .TS H.264 50fps progressive that need to be converted to 25fps interlaced.
The source's frames are all interlaced and also duplicated (AABBCCDD, all interlaced)
How is it possible to fix it with minimal quality loss? :(
Not sure if I should create a new topic for it or not =/
Yes, in the Avisynth part ;
http://forum.doom9.org/forumdisplay.php?f=33

WorBry
13th March 2016, 18:46
Anyway I find it confusing, I prefer to use Avisynth conversion and configure Cedocida's input and output in yv12.

Yes, like I said, I could have set it out that way, and if it was with a view to further YV12 filtering with AVISynth I would do the same i.e. output YV12 with "MPEG2 interlaced" chroma sampling. But in this instance, the ReverseFieldDominance requires YUY2, and configuring Cedocida accordingly kept it simple for the OP.

P.J
14th March 2016, 21:07
Just wanted to update the topic, it wasn't the video file's issue.
The hardware de-interlacer had problem while detecting the field order's flag:
http://forum.doom9.org/showpost.php?p=1760751&postcount=20658

I'll update again if I found any clue to fix it <3