Page 1 of 1

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

Posted: Tue Apr 04, 2017 12:15 pm
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:

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

Posted: Tue Apr 04, 2017 12:34 pm
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.

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

Posted: Tue Apr 04, 2017 1:03 pm
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)

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

Posted: Tue Apr 04, 2017 1:35 pm
by admin
Got it. Lemme think on it a while.

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

Posted: Tue Apr 04, 2017 1:59 pm
by admin
Do you know about the DGSource(show=true) option? It will display the frame type.

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

Posted: Tue Apr 04, 2017 2:01 pm
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.

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

Posted: Tue Apr 04, 2017 2:41 pm
by admin
How does luck enter? Maybe I still don't understand your needs.

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

Posted: Tue Apr 04, 2017 2:56 pm
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)

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

Posted: Tue Apr 04, 2017 4:20 pm
by admin
I have a test version for you that sets the FFPICT_TYPE environment variable. Do you want 32 or 64 bit?

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

Posted: Tue Apr 04, 2017 4:39 pm
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.

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

Posted: Tue Apr 04, 2017 5:08 pm
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.

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

Posted: Tue Apr 04, 2017 7:29 pm
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.

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

Posted: Tue Apr 04, 2017 7:58 pm
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.

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

Posted: Wed Apr 05, 2017 5:58 am
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.

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

Posted: Wed Apr 05, 2017 6:35 am
by hydra3333
admin wrote:set an Avisynth environment variable
Just checking on the off chance ... it won't break vapoursynth will it ? :)

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

Posted: Wed Apr 05, 2017 7:24 am
by admin
I don't see why it would. You can test it for us. ;)

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

Posted: Wed Apr 05, 2017 7:43 am
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!

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

Posted: Wed Apr 05, 2017 5:15 pm
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.

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

Posted: Wed Apr 05, 2017 8:01 pm
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.

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

Posted: Wed Apr 05, 2017 8:51 pm
by sparktank
I did miss it. :oops:

That seems to be it. :D