directshow.net


Can I get timecode from directshow video?


I'm trying to make a timecode counter for a video player based on GMFBridge and DirectShow.
I'm using a Timer to call GetCurrentPosition() every 200ms but I believe it's not accurate. I'd like at least to get the frame number (from start) of the current frame when a video is running.
Can this actually be done?
I'm using DirectShowLib .NET library.
To my knowledge this is hard to achieve, in a solution I work on I did the following to get 'frame number':
public int NumberOfFrames
{
get
{
return (int)(Duration / AverageTimePerFrame);
}
}
public double AverageTimePerFrame
{
get
{
return videoInfoHeader.AvgTimePerFrame / 10000000.0;
}
}
public int GetCurrentFrame(double currentTime)
{
int noOfFrames = (int)(Duration / AverageTimePerFrame);
return Convert.ToInt32(Math.Min(noOfFrames - 1, Math.Floor(currentTime / AverageTimePerFrame)));
}
I got the videoInfoHeader by doing:
// Get the media type from the SampleGrabber
AMMediaType media = new AMMediaType();
hr = sampGrabber.GetConnectedMediaType(media);
DsError.ThrowExceptionForHR(hr);
if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero))
{
throw new NotSupportedException("Unknown Grabber Media Format");
}
// Grab the size info
videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
DsUtils.FreeAMMediaType(media);
However this is obviously tailored to my own use-case, hopefully it helps you a bit though. Good luck!
Updated
Added CurrentTime code (the locker is for my own usage you can most likely remove that):
public double CurrentTime
{
set
{
lock (locker)
{
IMediaPosition mediaPos = fFilterGraph as IMediaPosition;
int hr;
if (value >= 0 && value <= Duration)
{
hr = mediaPos.put_CurrentPosition(value);
DsError.ThrowExceptionForHR(hr);
}
}
}
get
{
lock (locker)
{
IMediaPosition mediaPos = fFilterGraph as IMediaPosition;
int hr;
double currentTime;
hr = mediaPos.get_CurrentPosition(out currentTime);
DsError.ThrowExceptionForHR(hr);
return currentTime;
}
}
}

Related Links

text overlay issue?
Chaining Shader Effects
MP4 Fast Forward/Rewind
Can I get timecode from directshow video?
Use specific codec or ffdshow folder with DirectShowLib?
File writer filter creating a bigger AVI file then original

Categories

HOME
ontouchlistener
facebook-messenger
writefile
out-of-memory
gallery
minecraft
static-analysis
scheduler
anchor
nexus3
texas-instruments
synthesis
exec-maven-plugin
string-formatting
xsl-fo
cpu-usage
android-custom-view
opam
pe
activeadmin
pymongo
fluent-migrator
tracing
morris.js
crud
bobo-browse.net
spring-annotations
fatfs
mdns
nic
vcenter
steam-web-api
caesar-cipher
cloudera-manager
devtools
android-canvas
aurelia-http-client
python-sounddevice
julius-speech
asihttprequest
jshint
tinyioc
rm
android-5.0-lollipop
ogg
ternary-operator
researchkit
mathjs
data-management
declarative
fiber
perforce-integrate
unsigned
openmrs
flush
pack
android-mapview
variable-length-array
google-maps-api-2
wicked-gem
text-align
incron
microsoft-expression-web
symja
cout
relationships
redpitaya
miglayout
cidr
ivalueconverter
profiles
lync-2010
notifyjs
stty
aero
ofstream
django-filebrowser
tridion-2011
getopt-long
voice-recording
infopath-2007
rtd
photo-management
css-friendly
ognl
channelfactory
cleartype
eventaggregator
inversion
service-factory
bindable-linq

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App