Log in

View Full Version : How to read fourcc in avi and use it in avisource?


Guest
20th March 2005, 14:59
I wonder if there ia a way to read the fourcc(codec)in avi file, before opening it with avisource - in order to open the avi with the proper codec?

I want to get avisynth to do this automaticly so any avi can be opened with the right codec if it is installed.

On reading the fourcc's I found this:
If you open the AVI file in Windows Wordpad (in Start/Programs/Accessories) you should see something along the lines of "vidsXXXX" somewhere in the top few lines of garbage displayed. In this case, the XXXX is the FOURCC that the AVI file needs to decode its video.
It's from here! (http://www.fourcc.org/index.php?http%3A//www.fourcc.org/fccwhich.php)

Has anyone found a solution to this?

Tin2tin

Leak
20th March 2005, 15:41
Originally posted by Guest
I wonder if there ia a way to read the fourcc(codec)in avi file, before opening it with avisource - in order to open the avi with the proper codec?

I want to get avisynth to do this automaticly so any avi can be opened with the right codec if it is installed.

Ummm... how else do you think AviSynth is handling this? It looks at the FourCC of the AVI file you specify and tries opening it with the codec that's registered with Windows for this FourCC.

If the FourCC is bogus, or you want to use a different codec, use a different FourCC by adding a FourCC="...." parameter to your AVISource call...

Isn't this what you're looking for? :confused:

np: Markus Guentner - Regensburg 1 (Regensburg)

Guest
20th March 2005, 16:36
Oh, so avisynth is all ready doing this automatically!? I didn't know. :eek:

Thanks,

Tin2tin

Maximillius
20th March 2005, 21:49
Originally posted by Guest
Oh, so avisynth is all ready doing this automatically!? I didn't know. :eek:

Of course. It's no different then when opening an avi in virtualdub or in any media player and it reads the fourcc info in the avi header and tries opening it using that codec. It's nothing magical.

SeeMoreDigital
20th March 2005, 23:03
And if you want to change your Mpeg4 .AVI's 4CC code, you can always use "Nic's FourCC changer": -

http://img162.exs.cx/img162/8281/nicsminiavifourccchanger6jx.gif


Cheers

Guest
20th March 2005, 23:23
The reason for my question is that I'm trying to figure out an error free way to load any avi file into avisynth from my DVD slideshow GUI (http://www.videohelp.com/~tin2tin/) - or at least find a way to throw a warning/avoid loading/suggest a codec - if the user is loading an avi with an unsupported/uninstalled codec.

Thanks for your replys,
Tin2tin

ShawnFumo
23rd March 2005, 17:01
Actually, I'd love to have access to the FourCC of an AVI within avisynth itself, to help with the NLE I'm trying to build on it. There may be some CLI program that can spit back a FourCC, but I'd like to keep as much of the loading process within Avisynth itself as possible.

When I first load a file, I'm using WriteFileStart to create a text file with the clip's original properties (height, framecount, colorspace, etc). Having access to the FourCC so that I could write it out in the same place would be quite helpful. I was able to make a function to spit out colorspace (using the various isRGB24, etc), but I don't think there's any current way to get the FourCC.

So, would someone be able to hack together a variation on AVISource that just returns the FourCC as a string instead of returning the actual clip? That'd be great for my own uses (and Tin2tin's) and could also help automation in other people's scripts. Like if you know the file is DV, you can assume that it needs to be de-interlaced and take that into account.

Many thanks,
Shawn

Guest
23rd March 2005, 21:10
I got some help on solving this on the wxbasic forum. (http://wxbasic.sourceforge.net/phpBB2/viewtopic.php?t=814)
I guess that this solution could be ported to a c function, since there is no readfile(txt) in avisynth yet(as far as I know). But I'm not into c. :eek:
Tin2tin

ShawnFumo
24th March 2005, 05:24
Hmmm, now that you mention it, I should be able to grab the FourCC using Python's various file-reading commands. I still think it'd be more elegant to be able to grab it from within Avisynth, though. Maybe I'll try tackling an avisynth plugin eventually, but I don't want to pull myself in too many directions at the moment.

I didn't realize that wxBasic existed! I think I'll stick with wxPython since it seems so well-supported, but that's really cool that wx apps can be done in basic. I've been meaning to try out your DVDSlideshowGUI but haven't had a chance yet.

Cheers,
Shawn

Wilbert
14th April 2005, 21:56
@Guest,

Trev created a small plugin (and i tweaked it a bit):

http://www.geocities.com/wilbertdijkhof/AVIInfo_v02.zip

It opens an avi without decompressing any frames, and is able to give info about the video/audio streams. It always outputs to a string.

Example usage:


# returns framerate of video
clip = ...
Value(clip.AVIInfo(framerate,1)) # value converts string to int (actually float i guess)

# returns fourCC
clip = ...
clip.AVIInfo(fourCC,1)

tin3tin
15th April 2005, 10:15
Very nice! Thanks!
:)

danpos
16th April 2005, 21:15
@Wilbert

Hi! Is there some way to redirect the AVIInfo output for a text file?

Cheers,

danpos
16th April 2005, 23:36
@Wilbert

I´ve tried the AVIInfo plugin and it worked (almost) like a charm, because of a information about sample rate of audiostream was bogus (38 KHz instead of 44.1 KHz)...:eek: I've used in this way:

c="movie.avi"

BlankClip

\Subtitle("Stream 1: " + c.AVIInfo("type",1),20,20).

\Subtitle("Codec: " + c.AVIInfo("fourCC",1),20,40).

\Subtitle("Framerate: " + c.AVIInfo("framerate",1),20,60).

\Subtitle("# de frames: " + c.AVIInfo("length",1),20,80).

\Subtitle("Largura: " + c.AVIInfo("width",1),20,100).

\Subtitle("Altura: " + c.AVIInfo("height",1),20,120).

\Subtitle("Stream 2: " + c.AVIInfo("type",2),20,140).

\Subtitle("Samplerate: " + c.AVIInfo("framerate",2),20,160).

\Subtitle("# de amostras: " + c.AVIInfo("length",2),20,180)

BTW, it's a good plugin that can to be used in a lot of situations ...

Cheers,

EDIT: I've tried the above script using a another avi file with framerate of 23.976 for video stream. AVIInfo returns 23.00000000 as the framerate value. So, I think that (perhaps) the rounding routine must be reviewed ...

stickboy
17th April 2005, 04:18
Originally posted by danpos
Hi! Is there some way to redirect the AVIInfo output for a text file?You can use one of the WriteFile functions to output a string to a text file.

Wilbert:
The documentation to AVIInfo is misleading; its first argument is a filename, not a clip.

Looking through the code regarding that rounding error:
float fps = float(psi.dwRate/psi.dwScale);
should be:
float fps = float(psi.dwRate)/psi.dwScale;(BTW, why bother with the enums if you use hard-coded magic numbers? :p)

trevlac
17th April 2005, 04:34
@Wilbert,



//*** Change this ****
float fps = float(psi.dwRate/psi.dwScale); // framerate (audio: samplerate)

//*** To this ****
float fps = float((float)psi.dwRate/(float)psi.dwScale); // framerate (audio: samplerate)


I think because both rate and scale are integers, the result of their division is an integer. Then it is being changed to a float. Very subtle bug.

@danpos

AVIInfo is looking at the stream header. For Audio, the sample rate is also in the actual audio stream. This might be why you get 38 vs 44. Maybe the header level one is not the best to look at. I think wilbert is going to enhance AVIInfo to add channels for audio. Then he will be looking at the actual audio stream.


--------------
damb ... stickboy pointed out the bug and I didn't even notice his post. Must be late. :)

Wilbert
17th April 2005, 13:45
Oops. Thanks for your comments.

BTW, why bother with the enums if you use hard-coded magic numbers?
Because I couldn't find out how to use it properly :) Isn't it possible to do it soft-coded?

Anyway, the following version should work properly

http://www.wilbertdijkhof.com/AVIInfo_v03.zip

@danpos, could you check it? The 38 KHz should also be fixed.

@Trev,
Maybe the header level one is not the best to look at.
The samplerate is taken from the stream level. It's related to this rounding error.

I think wilbert is going to enhance AVIInfo to add channels for audio.
Later :)

edit: updated link

stickboy
17th April 2005, 20:59
Originally posted by Wilbert
Because I couldn't find out how to use it properly :) Isn't it possible to do it soft-coded?You really should use the enums instead... It's much more readable.
enum info_t { type, fourCC, framerate, width, height, length, skew };
info_t info;

// ...

if (lstrcmpi(_info, "type") == 0)
info = type;
else if (lstrcmpi(_info, "fourCC") == 0)
info = fourCC;
// ... et cetera ...

danpos
18th April 2005, 02:08
@stickboy

Thanks for the hint about to output the AVIInfo informations to text file! :)

@Trevlac

Thanks for your support and good explanation about the question!:)

@Wilbert

I´ve tried the new version of plugin and it's returning the correct video stream framerate, but the audio stream sample rate remains bogus (now, I´ve tried with a .avi file which audio stream presents 48 KHz as sample rate :( ) ... BTW the plugin will help me a lot with a little utility that I´m developing for now ...;)

Keep up the good work, mate!:D

Wilbert
18th April 2005, 09:21
but the audio stream sample rate remains bogus (now, I´ve tried with a .avi file which audio stream presents 48 KHz as sample rate
Could you give me some info? The duration of those streams, the type of audio (although that shouldn't matter) ...

edit: ok. This happens with mp3 in avi (uncompressed audio in avi works fine).

danpos
20th April 2005, 01:18
Originally posted by Wilbert

edit: ok. This happens with mp3 in avi (uncompressed audio in avi works

fine).

yep, I do confirm that audio stream in .avi that I've used to test the pluglin is .mp3 ..;)

Cheers,

StainlessS
2nd July 2019, 04:14
AviFileInfo v0.4,
See MediaFire (HOSTED folder) in my sig below this post.

Avs v2.58, avs/+ v2.6 x86 and x64 dll's + source + VS 2008 Project files.

Not much testing. [ Time for bed said Florence, boing said Zebedee. ]

EDIT:

FN="D:\Parade.avi"

AviSource(FN)

Types=RT_String("Type\nFourCC\nFrameRate\nWidth\nHeight\nLength\nSkew\n")

nTypes=RT_TxtQueryLines(Types)

SSS=""

For(n=0,nTypes-1) {
TypeName = RT_TxtGetLine(Types,n)
S=AVIInfo(FN, info=TypeName, stream=1)
SSS=RT_String("%s%d] %s\\n",SSS,n,S)
}

Subtitle(SSS,lsp=0)

https://i.postimg.cc/13DtN3tz/avsinfo-00.jpg (https://postimages.org/)

videoFred
6th July 2019, 12:27
I have tho following problem:
In AvsPmod, Avisource is displayed like this:
I just have to click in the box to change the source file, very useful for me. (It's using windows explorer)

http://www.super-8.be/Doom/Avisource_AvsPmod.jpg

But I need the same path and filename for AviInfo, like this:

codec= AviInfo("Z:\VDP\vdp_sp12.0.avi",info="fourCC")

AviInfo will not accept a variable for the filename and path.

For example, this will not work:

a= AviSource("Z:\VDP\VdP_Sp1.avi")
codec= AviInfo(a,info="fourCC")


So the question is: how do I get path and filename into AviInfo without having to type it in the script?

I hope my question is clear :D

Fred.

StainlessS
6th July 2019, 13:24
Yeh well, thats the main reason that I dont use AvsPMod at all.

Dont know how, but when I use eg FileName=RT_FSelOpen(...) to get a file name, it somehow or other hijacks the line of code and inserts the filename itself into the code, thereby f***ing up my scripts.
No idea at all how it does that and wish it did not, as I then have to go unf*** it every time afterwards.

Somebody that uses AvsPMod (and that aint me) would be better to sort this out, maybe Gispos (or sombody that speaks snake) would be in a better position.
You out there gispos ?, any way to override so as to get result of whatever the file selector (and I dont even know if that is result of RT_Stats RT_FSelOpen,
or some AvsPMod builtin stuff).


Fred, Do you click on some dialog/menu in AvsPmod to bring up File selector ? and what is in source script to enable that to work ?

videoFred
6th July 2019, 16:19
Fred, Do you click on some dialog/menu in AvsPmod to bring up File selector ? and what is in source script to enable that to work ?

It's in the "options" menu, type string(filename)
AviSource(whatever) in the source script enables it to work.

http://www.super-8.be/Doom/AvsPmod_Options.jpg

StainlessS
7th July 2019, 00:56
OK fred, just downloaded gispos latest [dont seem as bad as I remember, actually not too bad at all <only used it for like 2 minutes though>].

Pretty easy solution actually.


vFN="" # <<<<<===== Insert FileName between double quotes. <Menu/Edit/Insert/Insert Filname[Shift/F9]>
AviSource(vFN)
FOURCC = AviInfo(vFN,info="fourCC")
Subtitle(FOURCC)


That as required ?

3 or four minutes of further playing about, still not bit me yet. Think I may give it a bit longer to upset me :)

EDIT: Or prev given script minus the original supplied filename.

FN="" # Place cursor between double quotes and SHIFT/F9, Insert Filename

AviSource(FN)

Types=RT_String("Type\nFourCC\nFrameRate\nWidth\nHeight\nLength\nSkew\n") # backslash n, replaced with Chr(10) by RT_String formatting.

nTypes=RT_TxtQueryLines(Types) # count number of newlines [ie Chr(10), using string as a sort of Chr(10) separated pseudo array]

SSS="" # zero subs string

For(n=0,nTypes-1) {
TypeName = RT_TxtGetLine(Types,n) # Get single line from multi-line pseudo array
S=AVIInfo(FN, info=TypeName, stream=1) # Extract attribute
SSS=RT_String("%s%d] %s\\n",SSS,n,S) # Add to subs string together with line number & Subtitle style NewLine [using DOUBLE backslash n, which ESCAPES/Avoids turning backslash n into Chr(10)]
}

Subtitle(SSS,lsp=0)

Bernardd
7th July 2019, 08:45
Hello Fred,
Have you try AvsPmod Tag selection for toggling to change source ?

videoFred
7th July 2019, 12:56
That as required ?

No :D

I have so many files on several harddisks. The "Avisource" box in AvsPmod is so easy to use, without having to do anything manual in the script. I just have to click on a file in Win explorer and it is written in the script as AviSource("path,file")

What I need is a way to get the filename and path into a variable without having to do anything myself.

For example:
AviSource("Z:\VDP\VdP_Sp1.avi")
# here should be a line of code to get "Z:\VDP\VdP_Sp1.avi" into a variable, then I could use AviInfo




Fred.

videoFred
7th July 2019, 13:00
Hello Fred,
Have you try AvsPmod Tag selection for toggling to change source ?

Hi Bernardd,

Thank you for the suggestion, but that will not solve my problem. I want to change (and locate) source files fast and easy.

Fred.

StainlessS
7th July 2019, 14:39
What I need is a way to get the filename and path into a variable without having to do anything myself.
[EDIT: I dont really see what the problem is, whether put filename into string or filename into source filter, you gotta do something either way.]


Not even FFMS [ffInfo] can return name of source file from Avisynth clip (I thought it did), it can return colorspace, but then so can Avisynth), it does not return any FourCC.


function FFInfo(clip c, bool "framenum", bool "frametype", bool "cfrtime", bool "vfrtime", string "varprefix",
\ bool "colorspace",bool "colorrange",bool "cropping",bool "sar",bool "version",bool "showprefix") {

framenum = default(framenum,true)
frametype = default(frametype,true)
cfrtime = default(cfrtime,true)
vfrtime = default(vfrtime,true)
varprefix = default(varprefix, FFVAR_PREFIX)
colorSpace = default(colorspace,true)
colorrange = default(colorrange,true)
cropping = default(cropping,true)
sar = default(sar,true)
version = default(version,true)
showprefix = default(showprefix,false)

c.frameevaluate("""
fftempstring = ""
varprefix = """" + varprefix + """"
""")

version ? frameevaluate("""fftempstring = fftempstring + "Version: " + FFGetVersion + "\n" """, after_frame=true) : nop()
framenum ? frameevaluate("""fftempstring = fftempstring + "Frame Number: " + string(current_frame) + " of " + string(framecount()) + "\n" """, after_frame=true) : nop()
frametype ? frameevaluate("""fftempstring = fftempstring + "Picture Type: " + FFPictType(eval(varprefix + "FFPICT_TYPE")) + "\n" """, after_frame=true) : nop()
cfrtime ? frameevaluate("""fftempstring = fftempstring + "CFR Time: " + FFFormatTime(round((current_frame * 1000) / framerate())) + "\n" """, after_frame=true) : nop()
vfrtime ? frameevaluate("""fftempstring = fftempstring + "VFR Time: " + FFFormatTime(eval(varprefix + "FFVFR_TIME")) + "\n" """, after_frame=true) : nop()
colorspace ? frameevaluate("""fftempstring = fftempstring + "ColorSpace: " + FFColorSpace(eval(varprefix + "FFCOLOR_SPACE")) + "\n" """, after_frame=true) : nop()
colorrange ? frameevaluate("""fftempstring = fftempstring + "Color Range: " + FFColorRange(eval(varprefix + "FFCOLOR_RANGE")) + "\n" """, after_frame=true) : nop()
cropping ? frameevaluate("""fftempstring = fftempstring + "Cropping: " + FFCropping(eval(varprefix + "FFCROP_LEFT"),eval(varprefix + "FFCROP_TOP"),
\ eval(varprefix + "FFCROP_RIGHT"),eval(varprefix + "FFCROP_BOTTOM")) + "\n" """, after_frame=true) : nop()
sar ? frameevaluate("""fftempstring = fftempstring + "SAR: " + FFSampAR(eval(varprefix + "FFSAR_NUM"),eval(varprefix + "FFSAR_DEN")) + "\n" """, after_frame=true) : nop()
showprefix ? frameevaluate("""fftempstring = fftempstring + "Prefix: '" + varprefix + "'\n" """, after_frame=true) : nop()

return scriptclip("subtitle(fftempstring, lsp = 1)", after_frame=true)
}


Dont know of anything that can expose filename from Avisynth clip.
You need the name assigned to variable before you attempt open the clip, only the source filter could know clip name after open.
Might be possible (if implemented in avisynth) to extract filename from Avisynth builtin source filters but not for external source filter plugins
(which might also exclude avisynth+ supplied externals like DirectShowsource).

[Could probably extract filename from the clip Windows file stream, but is very likely that the stream is private to the source filter and
not at all accessible to avisynth directly, and so cannot ask operating system what the filename of the unknown file stream is.]

Maybe others could give more definite answer.

EDIT: Could maybe do something like this

Function FredVideoSource(String vFN) {
Global G_Fred_Video_FileName=vFN
return Avisource(vFN)
}


But would need to implement (somehow) in AvsPMod a new Source Filter in the AvsPMod DBase, [ask a snake speaker for that].
Then somehow Insert call to your new source filter.

Also, within Fred source filter, could make decision about which actual source filter to use (maybe based on name extension), and set some global with a FourCC
and whatever else you like.
So something like the example function I posted recently, ie GetSeq()

EDIT: Maybe something like this


Function FredVideoSource(String vFN, String "aFn") {
Function IsISOFileName(String s) {s=RT_GetFileExtension(s) Return(s==".mov"||s==".mp4"||s==".m4v"||s==".3gp"||s==".3g2"||s==".mj2"||s==".dvb"||s==".dcf"||s==".m21")}
Function IsRiffFileName(String s) {s=RT_GetFileExtension(s) Return(s==".avi"||s==".wav")}
myName="FredVideoSource: " aFn = Default(aFn,"") aFn = (aFn=="") ? vFn : aFn
Assert(vFn!="",RT_String("%sVFn Cannot be ''",myName)) vFn = vFn.RT_GetFullPathName IsRiffV = vFn.IsRiffFileName IsIsoV = vFn.IsISOFileName
Assert(aFn!="",RT_String("%saFn Cannot be ''",myName)) aFn = aFn.RT_GetFullPathName IsRiffA = aFn.IsRiffFileName IsIsoA = aFn.IsISOFileName
c=0 a=0
Try { # 1st Try specialized AVI
c = (IsRiffV) ? vFn.AviSource : NOP
(c.IsClip) ? RT_DebugF("AviSource opened Video\n '%s'",vFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }
Try {
a = (c.IsClip && c.HasAudio && aFn==vFn) ? c : (IsRiffA) ? aFn.WavSource : NOP
(a.IsClip && a.HasAudio) ? RT_DebugF("%s opened Audio\n '%s'",(c.IsClip && c.HasAudio && aFn==vFn)?"AviSource":"WavSource",aFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }

# Next try specialized ISO LSMash
Try {
IsOpenV=(c.IsClip && c.HasVideo)
c = (IsIsoV) ? LSMASHVideoSource(vFn) : c
(IsIsoV) ? RT_DebugF("LSMASHVideoSource opened Video\n '%s'",vFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }
Try {
IsOpenA=(a.IsClip && a.HasAudio)
a = (IsIsoA) ? LSMASHAudioSource(aFn) : a
(IsIsoA) ? RT_DebugF("LSMASHAudioSource opened Audio\n '%s'",aFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }

# Next try FFMS2
Try {
IsOpenV=(c.IsClip && c.HasVideo)
(!IsOpenV) ? FFIndex(vFn) : NOP
c=(!IsOpenV) ? FFVideoSource(vFn) : c
(!IsOpenV) ? RT_DebugF("FFVideoSource opened Video\n '%s'",vFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }
Try {
IsOpenA=(a.IsClip && a.HasAudio)
a=(!IsOpenA) ? FFAudioSource(aFn) : a
(!IsOpenA) ? RT_DebugF("FFAudioSource opened Audio\n '%s'",aFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }

# Next try LSmash non ISO Video
Try {
IsOpenV=(c.IsClip && c.HasVideo)
c = (!IsOpenV && !IsIsoV) ? LWLibavVideoSource(vFn) : c
(!IsOpenV && !IsIsoV) ? RT_DebugF("LWLibavVideoSource opened Video\n '%s'",vFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }
Try {
IsOpenA=(a.IsClip && a.HasAudio)
a = (!IsOpenA && !IsIsoA) ? LWLibavAudioSource(aFn) : a
(!IsOpenA && !IsIsoA) ? RT_DebugF("LWLibavAudioSource opened Audio\n '%s'",aFn,name=myName) : NOP
} catch (msg) { RT_DebugF("Catch: %s",msg,name=myName) }

Assert(c.IsClip, RT_String("%s failed open on\n '%s'",myName,vFn))
(!c.HasAudio && a.IsClip && a.HasAudio) ? AudioDubEx(c,a) : c
(!HasAudio) ? RT_DebugF("Audio failed Open on\n '%s",aFn,name=myName) : NOP
Global G_Fred_Video_FileName=vFN
Global G_Fred_Audio_FileName=aFN
return Last
}


EDIT:
I tried adding this to end of the AvsPMod dbase "filterdb.dat"

FredVideoSource(
string vFN,
string "aFN" =""()
)

And on trying to insert source to open a WebM file, AvsPMod just defaults to inserting a DirectShowSource filter call.
I have no further suggestions, need gispos or sombody that knows how this stuff works.