Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 3rd March 2014, 10:04   #1  |  Link
fieliapm
Himawari Tachibana
 
fieliapm's Avatar
 
Join Date: Nov 2013
Location: Taipei, Taiwan
Posts: 8
VideoInputSource - grab video frame from video capture card or webcam in real-time

It is developed for my work in the beginning. But I think somebody might need this to processing real-time captured video, so I post here and wish I could help anyone who use AviSynth to do some prototyping easily.

One day, I am asked to import and process real-time captured video and merge with video from files in AviSynth for making some prototype.
In the beginning, I grabbed video frame from DirectShowSource() with grf file as input. However, I found that DirectShowSource() won't duplicate or skip frame when some video capture device (ex. webcam) cannot produce next frame ontime. This phenomenon will cause AviSynth's frame feeding slow down while playing AviSynth script.
For this reason, I made a AviSynth source filter which capture video from video capture device. It is based on a simple video capture library named VideoInput.



binary:
VideoInputSource.dll

source:
VideoInputSource on github



The usage of this source filter is as below:
Code:
VideoInputSource(device_id,connection_type,width,height,"fps_numerator","fps_denominator","num_frames","frame_skip")



# device_id: the n-th number of video capture device in your computer

# connection_type: can be these string: "Composite","S_Video","Tuner","USB".
#     I leave this parameter because videoInput library offer this option.

# width, height: the width and height of frames captured from video capture device.

# fps_numerator, fps_denominator: FPS numerator and denominator.
#     Default is 30/1 (30.0fps)

# num_frames: How many frame will be captured from video capture device.
#     This will tell AviSynth the length of this video source.
#     Default it will be the value which makes video source length become 24 hours.

# frame_skip: enable/disable frame skip while next new frame from video capture device is not ready.
#     Default is true.


For example:

Code:
VideoInputSource(0,"Composite",1920,1080,24,1)
Will grab video from video capture device #0, 1920x1080, 24.0 fps, 24 hours long.



videoInput always output BGR24 packed pixels. For efficiency, current version of VideoInputSource supports AviSynth RGB24 color format only, and cannot be imported into VapourSynth script yet. Since I sometimes use VapourSynth for video processing, I might focus on compatibility of VapourSynth in the future.

By the way, It can work with MP_Pipeline very well since I often test this plugin in separate process generated by MP_Pipeline. However this plugin exclusively accesses to video capture device, so don't create video source from the same video capture device at the same time.

Last edited by fieliapm; 4th March 2014 at 04:43.
fieliapm is offline   Reply With Quote
Old 26th April 2014, 11:40   #2  |  Link
althor1138
Registered User
 
Join Date: Jan 2012
Location: Sweden
Posts: 22
Thanks for doing this! It works fantastic for me using a diamond theater750-pcie card. I am running avisynth 2.5.8 atm. Would it be possible to enable support for yuy2 capture?
althor1138 is offline   Reply With Quote
Old 26th April 2014, 13:57   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Many thanks kind sir.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 26th April 2014, 16:24   #4  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
I tried to capture with my Logitech C525 webcam, I set compression to use lagarith in virtualdub. But the video came out as it were in super slow-mo. What am I missing?

Code:
VideoInputSource(0,"USB",1280,720,30,1)
lansing is offline   Reply With Quote
Old 3rd October 2016, 07:55   #5  |  Link
Chromix
Registered User
 
Join Date: May 2009
Posts: 3
I had the same problem when using this source for encoding instead of viewing. What happens is that the clip says "I'm 30 FPS" like you specified in VideoInputSource. That's fine for players, but encoding tools of course try to be faster than the frame rate of the clip. So they just keep requesting frames as fast as possible, and the source just says "well, the frame hasn't changed, but here you go anyway". Thus the encoded clip is slow-mo due to tons of duplicated frames.

I've added a parameter to VideoInputSource: frame_wait (false by default). If you set it to true then VideoInputSource will simply block until there is a new frame available. It's a bit of a hack but works fine for me. The modified source code and new DLL is attached in the zip.

First you need to figure out the frame rate your capture device provides (careful, webcams can change that dynamically under low-light conditions!). Just encode a clip with null output or fast compression, and check for the encoding FPS. VirtualDub e.g. displayed 8.33 FPS for my cam during low-light. So the VideoInputSource setting should be 25/3 in this case. This helps to get the audio sync (almost) right. Sometimes it needs to be tweaked a bit afterwards.
Attached Files
File Type: zip himawari_avs_plugin-master.zip (84.9 KB, 144 views)
Chromix is offline   Reply With Quote
Old 8th April 2017, 09:55   #6  |  Link
fieliapm
Himawari Tachibana
 
fieliapm's Avatar
 
Join Date: Nov 2013
Location: Taipei, Taiwan
Posts: 8
The problem which lansing and Chromix met might be due to getPixels() is non-blocking at their environment or usage.
However when I use VirtualDub to encode, with my capture card and Microsoft LifeCam Cinema under Windows 7, GetFrame() always blocks at getPixels() while there is no new frame coming.
To ensure new frame coming by asking function isFrameNew() (as Chromix did in modified version), I refined my original source code and put it here:

binary:
VideoInputSource.dll

source:
VideoInputSource on github

Just make frame_skip = false, it will acts like frame_wait in Chromix's mod.

I also use BitBlt() from AviSynth script env instance plus _aligned_malloc() to accelerate frame data copy, because AviSynth offers BitBlt() which support SSE instruction set when it availabie, it might be more efficient while running on various CPUs.

It is based on old stable release videoInput 0.1995 as previous revision.
However, anyone who want to use newer version (ex. 2014) of videoInput from author Theodore Watson's github (videoInput on github), feel free to switch source code belong to videoInput 0.1995 to newer version.



BTW, let me re-introduce this source plugin again.

The usage of this source filter is as below:
Code:
VideoInputSource(device_id,connection_type,width,height,"fps_numerator","fps_denominator","num_frames","frame_skip")

# device_id: the n-th number of video capture device in your computer

# connection_type: can be these string: "Composite","S_Video","Tuner","USB".
#     I leave this parameter because videoInput library offer this option.

# width, height: the width and height of frames captured from video capture device.

# fps_numerator, fps_denominator: FPS numerator and denominator.
#     Default is 30/1 (30.0fps)

# num_frames: How many frame will be captured from video capture device.
#     This will tell AviSynth the length of this video source.
#     Default it will be the value which makes video source length become 24 hours.

# frame_skip: enable/disable frame skip while next new frame from video capture device is not ready.
#     Default is true.
For example:

Code:
VideoInputSource(0,"Composite",1920,1080,24,1)
Will grab video from video capture device #0, 1920x1080, 24.0 fps, 24 hours long.

videoInput always output BGR24 packed pixels. For efficiency, current version of VideoInputSource supports AviSynth RGB24 color format only, and cannot be imported into VapourSynth script yet. Since I sometimes use VapourSynth for video processing, I might focus on compatibility of VapourSynth in the future.

By the way, It can work with MP_Pipeline very well since I often test this plugin in separate process generated by MP_Pipeline. However this plugin exclusively accesses to video capture device, so don't create video source from the same video capture device at the same time.

Last edited by fieliapm; 8th April 2017 at 09:58. Reason: typo
fieliapm is offline   Reply With Quote
Old 8th April 2017, 14:30   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Thank you, I've just got it up working on remote machine, and serving to local machine via TcpServer(), Tcpsource(), pair, works fine.

EDIT: As not posted in Avisynth Usage forum, might want to consider posting link to developer forum thread in Avisynth Usage, New Plugins and Filters thread (let people know that its available, not every user visits the Devs forum)..

EDIT: Something on TcpSource and TcpServer here:- https://forum.doom9.org/showthread.php?p=1802408
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 29th March 2020 at 18:00.
StainlessS is offline   Reply With Quote
Old 9th April 2017, 21:16   #8  |  Link
fieliapm
Himawari Tachibana
 
fieliapm's Avatar
 
Join Date: Nov 2013
Location: Taipei, Taiwan
Posts: 8
Thanks for your suggestion.
I will announce this plugin for end-user since it seems to be stable now.
fieliapm is offline   Reply With Quote
Old 28th March 2020, 06:32   #9  |  Link
Milardo
Registered User
 
Join Date: Nov 2008
Posts: 137
Quote:
Originally Posted by fieliapm View Post
Thanks for your suggestion.
I will announce this plugin for end-user since it seems to be stable now.
Anyway to get audio from a capture card?
Milardo is offline   Reply With Quote
Old 28th March 2020, 11:29   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Thought I'de post link to the thread in Usage forum(only opening post so far):- https://forum.doom9.org/showthread.php?t=174514

Dont miss Milardo's post above, a little earlier today (I have no idea how to answer Milardo query).

EDIT: fieliapm not on-line since Oct 2018.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 29th March 2020 at 15:35.
StainlessS is offline   Reply With Quote
Reply

Tags
avisynth, videoinput, webcam

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:14.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.