I wrote a C# code that captures video from a video capture card, and writes it in a AVI file. I'm using the XviD encoder (DirectShow).
I'm using the IAMVfwCompressDialogs interface to get the configuration form open, and I am also trying to configure it going to the same form in the start menu.
I need to record 30 minutes of video, without audio, and I need this file to be 2Mb big.
I set the Target bitrate property of the Video Encoder of the Xvid to 10 (kbps), and the Target Quantizer property to 16.
The file size did not changed.
Then I tryed to modify those two property to many different combinations, but I get no change.
My problem is: I changing the XviD configurations to change the file size, modifing the bitrate and the quality properties, but the result is aways the same.
Is there any way I can set 30 minutes video file size to be around 2Mb big, even by modifing the bitrate or quality, with 1 fps, 240x192 framesize, very low video quality? Is there any problems with XviD filter when using it on a C# service? Is there any other good filter to use with DirectShow on c# applications?
Thanks in advance.
I found out how... It may sound weird, but when I set the windows service to inicialize with the same user that installed the Xvid codecs, it works fine.
Related
I developed a socket based p2p system where i stream mp4 video from a client to a server. The video data are transferred using byte[].
The transfer works, however i am struggling to figure out how i could play, in continuous, a mp4 file being transferred to another PC? The PC application, that would play the file, is in WPF.
I tried using a MediaElement to play the file, being written to the disk, but for some reason it doesnt play at all. I can play it with VideoLan tho.
Any hint of where to look? I am lost from here!
Thanks in advance!
Its going to be different with every player. Mp4 is probably the worst possible container for this application. The container is designed to be used with random access media, such has a hard disk. The player has the ability, and sometimes requirement to seek around within the file, and not just plat start to finish. Either you need to make the protocol mp4 aware (parse the file, and download the block that will most like be needed next), or use a streamable container such as TS, or flv.
Its is also possible that the player knows the file is incomplete. The atoms sizes are encoded within the file. If the file size doest match, the combined atom sizes, the player could assume a corrupt file.If this is what is happening, you can try to pre allocate the file. it may trick the player enough to play
I've been trying to find a way to show the stream of my webcam with a 30 second delay.
I found out that VLC is able to do this, but the problem is that the framerate is much too low and it's not smooth or viewable at all. I have to run this on a fairly old laptop with a better webcam that I own now, so I guess it's not an option.
I am able somewhat familiar with c#/c++ and python so I thought that I might make a solution of my own as the task seems fairly easy. Though, the problem is, I don't know where to start and any nudges in the right direction would be much appreciated.
My initial idea was to record first 30 seconds of the stream to the disk, then use VLC to view partial file (AFAIK it's able to do that). Is it an idea worth working on or should I scratch it and use some sort of a buffer for the video frames in the last 30 seconds?
Again, any nudges in the right direction will be much appreciated, thanks!
Take a look at OpenCV.
It can retrieve and show images from a webcam.
A lot a of tutorials are also available; e.g. http://opencv.willowgarage.com/wiki/CameraCapture
So simply create an array (or whatever) to hold the amount of pictures to be expected in 30 sec (FPS*30).
Start to retrieve images and as soon as the array is filled start to play from position 0.
Newly retrieved images can than be stored at the position from the "just" shown image.
Miguel Grinberg has written an excellent video streaming tutorial in Python which sends JPEG frames successively. Check his blog post here:
http://blog.miguelgrinberg.com/post/video-streaming-with-flask1
Each of these JPEG can be quickly reviewed and then broadcasted. [To take the required Delay in consideration]
As far as getting the input video feed is concerned, you can interface a webcam using OPENCV. OpenCV uses VideoCapture which returns raw images as bytes. These bytes needs to be encoded to JPEG and interfaced with Miguel's code.
import cv2
class VideoCamera(object):
def __init__(self):
# Using OpenCV to capture from device
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# so we must encode it into JPEG in order to correctly display the
# video stream.
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()
This approach will help you cater all the required features:
No internet required
Adjustable delay - Easily control the delay and the processing you want to perform on each frame
Good Quality
Record on Demand - Store the captured frames as per need
Have a record back feature, by just saving the previous 24*x frames (24fps stream)
I am using direct show to capture video and save it to file. I have tried in vain to find ways to decrease the resultant video size but cannot manage. I would like to know if anyone can tell me how I can:
Decrease the frame rate of the video
Decrease the quality of the video (even down to 320 x 240)
Apply a compression on the video (mpeg? etc).
Raw video is huge in size, and to size-efficient storage assumes you compress the video. You are to use one of the video encoders, such as MPEG-4 AVC (H.264) or Windows Media. You typically insert an additional filter into your pipeline between capture filter and multiplexer/file writer. Read up on this in multiple past topics:
Using video codecs like XVid in c#
Real-time video encoding in DirectShow
How to properly build a directshow graph to compress video...
My requirement is to create an application that records desktop activities, along with audio, as a movie. After searching, I found that Microsoft Expression Encoder can be used to record desktop activities as a movie but the output file size is very large. For 10 seconds of video, it occupied around 30 to 40 MB. Also, it uses xesc format.
Is there is any other free API available to do this job?
Before you give up on Expression Encoder try adjusting:
ScreenCaptureJob.ScreenCaptureVideoProfile.Quality
Reducing the quality can greatly reduce the file size. Try it and see if the results are acceptable for you.
Reducing the framerate is actually unhelpful; I guess it forces a fixed framerate, whereas the default is to use a variable framerate based on activity.
If you don't like .xesc files you can transcode the video after you've captured it.
But 30 to 40MB for ten seconds is still way too much. I recorded ten seconds of (admittedly not very large, 1366x768) full-screen video at the default quality. With not much going on it took 300K; with lots of activity (constantly switching between full-screen apps) it took at most 1.5MB.
Reducing the quality reduced file sizes by about 50%.
Unless you're playing a full-screen video and trying to record that, you shouldn't see anything like 30 to 40MB. Perhaps you should look at your audio settings.
ScreenRecorderLib from nuget is good.
SharpAVI is taking too much of my disc space.
You will need to be careful for ScreenRecorderLib, it would require some time saving mp4 file in the end.
Make sure your program won't end before that happens.
I use FileInfo.Length to check if the file size is not growing anymore. This will determine if the saving is finished or not.
I know of many utilities that can tell me the bitrate of an MP3 file, but I've never seen one that can tell me whether or not the MP3 file is VBR (variable bit rate - the bit rate fluctuates within the file) or a CBR (constant bit rate - the bit rate stays the same within the file). My guess is that most programs aren't interested in finding this out since it involves analyzing the file somewhat to see if the bitrate changes, which takes away from speed.
So, in lieu of finding a utility, I'd like to write one - so how could I programmatically determine whether or not an MP3 file is VBR or CBR? I have about 15,000 files to go through to find this out for, so I need to automate the process.
MP3 files are essentially build of so called frames. Each frame has a small header that stores information about the frame. The header also stores which bitrate was used for the frame. In CBR files, all frames use the same bitrate and therefore every header has the same bitrate information.
To detect if a file uses VBR, you have to go through every frame of the file, look at the header and check if the bitrate field changes. If it does, its an VBR MP3.
A full description of the MP3 format is here: http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
Check this MP3Header Class, it has a method that tells you if the mp3 file is VBR, and all the mp3 header information...
...
boolVBitRate = LoadVBRHeader(bytVBitRate);
...