c# DirectShow graphbuilder output filename issue - c#

I'm new to using Directshow. I'm more than willing to post the pages of code I've writen but I'm hoping someone could explain or hint in the right direction for a solution so I can figure it out myself.
Basically I have a WPF program that displays a window that has a preview of my webcam - this is done and working. Now I'm trying to get it to record the preview - done using graphBuilder.SetOutputFileName
However everytime I show the window to record another session is just overwrites the last file it recorded, even though I'm calling graphBuilder.SetOutputFileName again!
So my question is how can I change the outputfilename to record a second video. I know I'm missing something but don't know what.
Thanks in advance.
Rich

Filter graphs normally create media files starting from scratch on your initial Run and closing the file on your Stop. Next time you repeat the calls, you just start it from fresh from empty (overwritten) file. There is no appending. If you want to keep the previously recorded content, you need to switch files by providing new name, or copying/renaming the completed file.

Related

My System.IO.File.WriteAllText coding doesn't create a file after it has once been deleted in Windows Explorer

CONCLUSION AT BOTTOM OF POST
I'm a novice with C# and have only just begun using System.IO, but haven't been able to find information on my issue so wanted to ask the guys here:
I have a program that when run, creates a directory, then writes to a .txt file what the most recent value of a certain variable was, so that if the program is interrupted or the computer loses power, restarting the program will retrieve that stored number from the .txt file.
I've simply done this:
string INSTATR = LastValue.ToString();
System.IO.File.WriteAllText(#"C:\\DotTempFiles\\"+Instrument.Name+"ATR.txt", INSTATR);
My first time running this program, the file was created, and I found that on every cycle the number in the file was being overwritten to the last valid number just as I wanted.
However, once I went to the DotTempFiles directory and deleted the .txt file using Shift+Del, the file has never returned upon running the program as I thought it would. If I delete the entire directory and run the program, the directory is recreated but still not the file.
If I run the program using a different Instrument.Name, that new file is created as expected, but the original one that I once manually deleted is still not showing, even after computer restarts.
I can't find any information leads online, so does anyone have an idea? Thank you!
EDIT (more info): People asked a few questions so I'm adding more information (thank you)
There are no errors being reported. It compiles fine, and when running, there is an output window that usually alerts me to errors like if I reference an object that is null, or try to read from an empty file, etc. No errors like this are occurring.
More background on what the program is. There is a stock trading program called NinjaTrader that has their own API based on C#. They wouldn't support the questions I have because it's outside the normal scope of the script development they intended people to use, and that's ok with me. The program itself is a trading strategy that is run within NinjaTrader, and it exposes default programmer access to these two main methods:
Initialize()
protected override void OnBarUpdate() //this is the main part of the program that gets called every time a change has occurred to one of the bars on the stock chart.
In the variable declaration section I have this:
System.IO.DirectoryInfo di = Directory.CreateDirectory(#"C:\\DotTempFiles");
And in OnStartUp() I have this:
//Set up ReadMe file in the temp directory in case people wonder why it keeps appearing
string README = "This DotTempFiles directory is created by the strategy every time it is run, and temporary text files with the name [instrumentsymbol]ATR.txt are written into it containing the last highest ATRStopValue for the strategy, which if it is stopped and restarted with an open position, it will read from that file to get back the best value instead of recalculating it with possibility of a lower unwanted value.";
System.IO.File.WriteAllText(#"C:\\DotTempFiles\\README.txt", README);
Every time OnBarUpdate() is called, which can be up to a few times per second, it first calculates a double called LastValue which is a number related to the stock price, then it converts it to a string INSTATR, then writes it to a .txt file.
string INSTATR = LastValue.ToString();
System.IO.File.WriteAllText(#"C:\\DotTempFiles\\"+Instrument.Name+"ATR.txt", INSTATR);
And this is every single piece of code I have connected to this issue. As I mentioned above, it created the file the first time, but since I've deleted the file in windows explorer, it isn't able to recreate it. However, deleting the directory and restarting the strategy program does recreate that directory.
OnTermination() is not being used to close or delete the file in any way (just in case people wanted to ask) -- I am not using any other code to interact with the file than the ones already shown. Thanks!
EDIT 2 (Update after reading comments): Thank you guys for your comments and help. What I'll do when I get back to my home is try recreating the minimal version of this with an empty program containing just these lines of code and see what the outcome is, and I'll post updates in either way.
EDIT 3: Thank you Steve, that is a very good idea that I should use from now on for these kinds of things.
EDIT 4 (Conclusion): Well, I found out that I overlooked something simple about my own code logic. I was setting the File.WriteAllText to trigger any time the Double variable increased in value, not on every call of the OnBarUpdate method. Because of this, the file would not be written except once every few hours or so and now I see that everything is working properly. I am sorry that I made all these people read this post since it was based on another issue of my own fault. However, I am very thankful to everyone for their comments that helped me get to this point, and to Steve and Mark Lakata for their tips that I learned some new good things from.
I found out there is nothing wrong with the file creation, it was the fact that my coding logic was just calling for it far less frequently than I assumed it was (once every few hours vs several times per second)

powerpoint record rehearsal timings

Does anyone know how to set powerpoint's record slideshow/rehearsal timings using c# or VB? Can it be done in the open xml files? Or what developer references am I overlooking? I want to be able to choose a different method for timing up a self running presentation.
Here's code to add a 2 1/2 second rehearsal Timing to Powerpoint
slide.SlideShowTransition.AdvanceTime =2.5f;
slide.SlideShowTransition.AdvanceOnTime = MsoTriState.msoTrue;
Took me forever to find this, so hoping it helps others
Happy Programming!
AdvanceTime is stores the duration of the whole slide the event trigger time is stored in tag.xml file as Timing the values are stored as a pipe delimiter values like '|34.0|34|3|5.4'

Pause & Resume live video capture from webcam using DirectX.capture

hi i am following this link
http://www.codeproject.com/KB/directx/directxcapture.aspx
to capture data from webcam.Its working fine but when i pause and do resume then the file that contains data, its size increases but old data is lost and only new data persists.
can anybody point me towards a working example/tutorial where pause feature works.
i tried/searched many links but still landed nowhere.
can anybody provide me some help!!!
There are a number of comments about this in the article:
Searching "pause" inside the article comments
All search results for "pause" in the article comments
I tried the pause behavior of directShow.net but somehow it did not worked.
when i paused a avi file was created and when i resumed i found that the new contents are written on the previous file. the size of the file increased but the older content was washed away.
So i tried this:
1) When i paused a file say test.avi was generated.
2) when i resumed i renamed test to test1.avi and created new test.avi
file and merged them when user clicks on stop.
In this way i achieved pause feature. though its indirect but its still working for me..
hope i could implement the direct way.

Pause Download & Resume (Merge The Existing File)

I'm making a downloader using C#, I want to add a feature of Pause & Resume download, I googled & implemented the suggestions but it didn't work for me; was resuming from the correct position but had problem merging with the downloaded part. I tested it by downloading a video file but after pausing the download & starting it again the result file played for while (it played the portion which it downloaded before pausing but not the portion after pausing).
How can i merge the 2 portions successfully.
We can't figure out what's wrong with your code, because we can't see your code (it's not always enough to post the source using which you made your own code).
Either way, you can try this: Create a file with some easy to spot bit pattern (like 0101010101010101...) using some hex-editor, and try to see where it breaks.
If, for instance, the second part of the download keeps running over the few last bits of the first part, that would give you some clue.

How to Save Controls that are inside a form

Hi this question or problem i have its very hard i have search and ask in the university and i have no idea how to make this happen, or even if it is possible.
Here we go...
I am making a photo or image editor with the variation of letting the user to insert buttons in top of the edited image(this buttons when clicked plays an audio file) all of this works so far.
BUT at the end when the user finish his work i need him to save it, so it can be send and view by others.
Now I think I know how to save an edited image but that dose not contain the buttons (controls) .... its like when we save a file at power point and we send it to others they contain audio and the image. Hope fully you guys understand if so can any one point me in a direction to do this or show me how if possible.
( Some people told me to use meta-data others the manifest file but I am so confuse).
too bad i cant post pictures of the work until i get 10 points......
Thanks For the first four quick response and sorry mistake of not telling that I am working on C# 3.5 .Net and in Windows Form app.
It seems you all quite understand what i am trying to do here. I will post the picture thanks to the points i receive from TheVillageIdiot. and about the XML I have never ever used that before ill try my best to understand you guys but if any one can show me an example two or were to read ( dose xml works on Windows form app.?) Here is ...( sorry if the picture its too big) an example of what the program it's doing so far that black transparent box its the MouseOverBackColor... when clicked it loads a player that plays x_x the sound. Its like tagging but with audio.
I really need help i reached my limit don't know were to look and the time is killing me.
HI I am back again this time with a simple sample of what i need to learn how to save the dinamic buttonarray
Today is 10/11/10 (i made a acount with !##$%share to share the sample with you guys i hope this dosent bother any one here) here is the Link . i will explain again what i need to do and i have no idea or code on how to do it.Imagine a person that uses the program and create like 5 buttons any were in the form , it needs to be save so he can send it to others that have the same program, this way others can view the buttons the user created.
hopefully you guys can help me out with a simple example i really neeed some sample working code. Note: I am working on windows form app WFA C# 3.5 .net M.V.studio2010 (the file I gave above has a backup with a 2008 vercion) thanx in advance.
Similar to jim's answer, I would suggest having an archive of some sort (ZIP or otherwise) containing all the media necessary.
Store the images and sounds files by name or checksum in the archive and keep the meta-data (button positions, names, what media they use, etc, we'll call it the definition file) in a file also stored in the archive. You may be able to use XML to make that human-readable.
The entire package will then be simple to distribute and use, as everything will be contained in the archive. Your application simply needs to scan for archives, check each archive for a valid definition file, and load the ones that are needed.
Edit: Going from the screenshot you posted and my understanding of the problem, I'm going to suggest the following:
When a user creates a button (defined as a rectangular area or "hotspot"), open a dialogue asking for a sound file to associate. Then, store the top-left and bottom-right corners of the button and the filename in a XML file, something like this:
<Button name="myButton!">
<Position top="128" left="128" />
<Size height="200" width="200" />
<Audio filename="something.mp3" />
</Button>
Now, when compiling a plugin, create a ZIP archive. Inside, place the XML file and all the audio files you need.
When loading a plugin, read the XML file first and find the audio file (assume all audio files are in the same archive as the XML file). Then create the button and add the audio filename as, say, its Tag property. Assign all buttons one generic OnClick event, and in the OnClick event, play the audio file given by the current object's Tag.
If you don't understand what I mean, I'll try to elaborate further. I think that method should work neatly and be pretty simple to work with. :)
One solution: Create a ZIP file that contains both audio and images.
Basically, you've got two things you want to save.
The edited image, and then the locations of the buttons and their actions.
You've got the image-saving part happening, so now you need to save the other information. This can be considered "metadata", and you can save it in some format that you invent, such that it allows you to load it back. Typically it would be easiest to do this via XML Serialization. So look into that.
Assuming you are writing a stand-alone application and no web - application.
If you are adding the Button as a .NET component (new Button()) there is no way to do that unless you supply your own player software with it.
If you want to supply your own player, create a (seperate) file with the info about the button and read the file and then re-create the button.
(Be aware though that all the resources - jpeg, mp3) also have to be available at the target PC) Alternatively, pack all you info into one file (jpeg, button infos, mp3's) and save that file.
hth
Mario
You have two choices
Create your own format and then make a player app that read it and play the results
Find some format that supports your features and create that kind of file. This works well if you expect others to have a player.
For #2, here are some formats that could support what you want to do
Flash
PDF
Compiled HTML Arhive -- need IE to play http://en.wikipedia.org/wiki/MHTML
EXE -- create code with resources and compile it -- basically your player + resources
PowerPoint

Categories

Resources