[RESOLVED] Any way to select specific frame types (ipb) only? (mostly AVC)

Support forum for DGDecNV
Post Reply
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

[RESOLVED] Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

I'm looking for an easy way to select only certain frame types, i/p/b, in an avisynth script.

I know for FFMS2, there's "FFPICT_TYPE" to help get I frames only, for example.

I'd prefer to use DGdecodeNV.

Is there any way to do this with DGdecodeNV?
Maybe some sorcerer knows a script to read out of the DGI file for frame types. :twisted:

Although, it looks like frame type values are different depending on codec used. MPEG != AVC values for frame types in DGI file, so maybe some extra footwork is required.

So far, I've been opening the DGI file in a text editor and searching for frame types.
"Find all" for " 6 " (with spaces) for B frames, for exmaple.
For faster usage, I just skip through frames in AvsPmod with "Show=true" and hope a B frame is nearby (although, sometimes some scenes don't include B frames and are all just I/P frames).

Any pointers/shortcuts would be appreciated. :bow:
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

What do you mean by "get the frames"? Are you just trying to determine which frames are I frames? Are you trying to create a stream with only I frames? What would be your ideal output and how would you use it?

E.g., you can open the file in DGIndexNV and single step watching the Info dialog (if you step from the beginning then the frame number is the Coded # minus 1). But knowing exactly what you want and need, I may be able to offer you more, including an enhancement to the code.
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

I basically would like to see something like this:

Code: Select all

SelectEvery(frame_type=b) #or i/p/b
"Are you trying to create a stream with only I frames?"
Essentially, yes. Of any selected frame type.
That way when I open the script in AvsPmod, and frame step from start to finish, I see only the selected i/p/b frames.

This would help with taking screenshots.
Selecting any frame type would help jumping to any random frame in AvsPmod while it returns only the selected frame types.

Useful for making wallpapers and comparing test encodes.
(i for most quality, other types for seeing how well it compressed, etc)
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

Got it. Lemme think on it a while.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

Do you know about the DGSource(show=true) option? It will display the frame type.
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

admin wrote:Do you know about the DGSource(show=true) option? It will display the frame type.
Yes, that's what I've been doing so far when not trying to refer to the DGI file.
Largely relying on luck.
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

How does luck enter? Maybe I still don't understand your needs.
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

admin wrote:How does luck enter? Maybe I still don't understand your needs.
If I blindly run through the video in AvsPmod with show=true enabled, I have to keep scanning for b frames or other frame types I want for screenshots.

There's this thread that uses FFMS2 to select frame types...
[link removed]

A case examples from that thread:

Code: Select all

import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
ConvertToRGB32()

return ScriptClip("""chr(FFPICT_TYPE)=="I" 
\         ? Last.ImageWriter("E:\thumbs\filename_prefix-", 
\                    start=current_frame, end=current_frame, type="png")
\         : Last""", 
\         after_frame=true)
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

I have a test version for you that sets the FFPICT_TYPE environment variable. Do you want 32 or 64 bit?
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

admin wrote:I have a test version for you that sets the FFPICT_TYPE environment variable for AVC. Do you want 32 or 64 bit?
32 would suffice. :mrgreen: I rarely use 64 these days.

I tried looking at the source code for ffmpegsource and it looked to work around libav for getting video properties.
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

It's in the binaries area called sparktank.rar. I supported all the video types. Let me know if it works and then I can slipstream it.
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

Alright, it took a little bit to find clips.

For AVC and VC-1, it works perfectly!

Code: Select all

## VC1 source
LoadPlugin("D:\AVS\dgdecnv_test\DGDecodeNV.dll")
DGSource("G:\Clips\Inception\Inception-test.dgi", show=true)
ConvertToRGB32()

return ScriptClip("""(FFPICT_TYPE==3)
\         ? Last.ImageWriter("E:\Temp\Pics\Inception-3-", 
\                    start=current_frame, end=current_frame, type="png")
\         : Last""", 
\         after_frame=true)
^Giving me only screenshots of B frames in the VC-1 source.

Code: Select all

##AVC source
LoadPlugin("D:\AVS\dgdecnv_test\DGDecodeNV.dll")
DGSource("D:\MakeMKV\DARK_KNIGHT_TRILOGY_BONUS_DISC\00064.dgi", show=true)
ConvertToRGB32()

return ScriptClip("""(FFPICT_TYPE==5)
\         ? Last.ImageWriter("E:\Temp\Pics\TDK-", 
\                    start=current_frame, end=current_frame, type="png")
\         : Last""", 
\         after_frame=true)
^Giving me only screenshots of B frames in the AVC source.

Just trying to work out MPEG sourece, however.
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

Don't worry, if it works for one it works for all. This is the first time I have set an Avisynth environment variable. ;)

Be aware that there can be some ambiguity if you have soft pulldown that you are honoring. FFMS returns 'U' for that. I return the type of the base frame, i.e., the coded frame whose field is not pulled down in the displayed frame. So be careful with soft pulldown. You're unlikely to want to select such frames for your PNGs, but I thought it was worth mentioning it.

Thank you, sparktank, for your suggestion and your testing. I'll slipstream it tomorrow.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

Now I think I should use the character indicators 'I', 'P', and 'B' rather than the numbers, because the numbers are different for different video types. I'll do that before I slipstream it.
User avatar
hydra3333
Posts: 394
Joined: Wed Oct 06, 2010 3:34 am
Contact:

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by hydra3333 »

admin wrote:set an Avisynth environment variable
Just checking on the off chance ... it won't break vapoursynth will it ? :)
I really do like it here.
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

I don't see why it would. You can test it for us. ;)
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

:bravo: :bravo: Awesome work!

Yeah, I thought about how it would work on DVD rips, so I'll definitely keep that in mind.


This will open up some new ways to look at things. I vaguely saw a script where you can return only I frames with scriptclip. It depended on FFMS2 largely, so I'll have to hammer it out to work for DGdecNV.

Thanks a bunch for this!
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

:scratch: I wonder if it should be renamed to "DGPIC_TYPE" instead of "FFPIC_TYPE" for sake of clarity, in case someone has ffms2 in their auto-load plugin directory.

And maybe update the document? Those with sorcery skills can eventually start showing their work on the interwebs for more things to do with this.

So far, I am loving this function so much.
Already have over 4K images to siphon through for candidate wallpapers.
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
User avatar
admin
Posts: 4551
Joined: Thu Sep 09, 2010 3:08 pm

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by admin »

I doubt the name matters because people won't be using FFMS2 and DGDecodeNV together.

There is an explanation at the start of the DGSource() section of the manual. Did you miss it or are you referring to something else?

Glad you like it and thanks for the suggestion.
DAE avatar
sparktank
Posts: 64
Joined: Thu Mar 28, 2013 5:24 pm
Location: Gotham City

Re: Any way to select specific frame types (ipb) only? (mostly AVC)

Post by sparktank »

I did miss it. :oops:

That seems to be it. :D
Nvidia GeForce GT 1030 | GPU Caps Viewer
Windows 10 Annversary (x64) | ASVPlus_x64
Region A/R1
Post Reply