convert video files to flv format in c# - c#

How do I get video file from user and convert it into flv format?

A solution to have multimedia support that converts virtually ANYTHING you throw at it is to use FFmpeg and MEncoder, you'll have quite a good input/output support:
Input Image Sequence: jpg, pgm, png, ppm (with sequentially numbered-ONLY filenames)
having the same filename numbered-ONLY format. Example: 0001.jpg --up to--> 0999.jpg
note that this format will NOT work name_0001.jpg --up to--> name_0999.jpg (take out name_)
Input Video format: 3gp, 3g2, amv, asf, avi, dat, dvr-ms, fli, flc, flv, m2ts, mpg, mkv, mov
m4v, mp4, nsv, ogm, qt, rm(vb), str, swf, ts, trp, ty, ty+, tmf, viv, vob, wmv ..
Input Audio format: aac, ac3, amr, flac, mmf, m4a, mp2, mp3, mpc, ogg, ra, wav, wma ..
Input AviSynth Script Files: avs. To write a script and specify advanced encoding commands using AviSynth scripts!
(taken from SUPER's website)
NOTE: it has MUCH more support than "just" that. those are just some of the capabilities!! :D

Here is some example code and a C#/.NET library that will convert audio to video, and vice versa using an FFMpeg wrapper. It's explained here:
http://ivolo.mit.edu/post/Convert-Audio-Video-to-Any-Format-using-C.aspx

Related

Video Thumbnail creation in landscape or portrait mode

I'm using Nreco Video converter to create video thumbnails. Here is the C# code that I'm using.
(new NReco.VideoConverter.FFMpegConverter()).GetVideoThumbnail(fileSource, thumbNailPath, (float)0.1);
It simply works fine. The only issue being the orientation. The videos for which I'm trying to create thumbnails are recorded on a mobile app. So irrespective of whether the video is in portrait or landscape mode, the thumbnail generated is randomly in portrait or landscape mode.
Does any one know how to create a thumbnail of a video in a particular mode(landscape or portrait).
There is a rotation-parameter in video files that you can read by using various other ffmpeg wrapper libraries. Many players use it to actually rotate the screen. See here. As NReco does not support this directly, you would have to read this value with some other library and use it to rotate the jpeg in the stream.
I suggest using a ffmpeg wrapper where you can directly invoke ffmpeg process instances, as ffmpeg is able to read various properties from the file.
You can use ffmpeg for getting rotation from video metadata and apply appropriate rotation filter during thumbnail extraction. Since NReco VideoConverter is a .NET ffmpeg wrapper it also can be used for doing that:
Extract video orientation metadata from ffmpeg console (LogReceived event) with Invoke or ConvertMedia methods that actually doesn't perform any conversion. Rotation data can be matched with simple regex.
Compose FFMpeg arguments for appropriate rotatation filter (like: -vf "transpose=1" )
Extract thumbnail with ConvertMedia method that accepts extra ffmpeg command line arguments (see code snippet below)
(internally GetVideoThumbnail uses ConvertMedia method):
var thumbSettings = new ConvertSettings() {
VideoFrameCount = 1,
VideoFrameRate = 1,
MaxDuration = 1, // extract exactly 1 frame
Seek = 0, // frame seek position
CustomOutputArgs = String.Format(" -vf \"{0}\"", rotateFilter ) // rotation filter parameters
};
ffMpegConverter.ConvertMedia(inputFile1, null, thumbJpegOutputStream, "mjpeg", thumbSettings);
As result you will get video thumnail rotated according to video orientation metadata. Full code that implements all steps can be found in VideoConverter package (Rotate example).

send array of bytes to System.Media.SoundPlayer in c#

I want send string byte to speaker something like this:
byte[] bt = {12,32,43,74,23,53,24,54,234,253,153};// example array
var ms = new MemoryStream(bt);
var sound = new System.Media.SoundPlayer();
sound.Stream = ms;
sound.Play();
but I get this exception:
my problem pic http://8pic.ir/images/g699b52xe5ap9s8yf0pz.jpg
The first bytes of a WAV stream contain info about length, etc.
You have to send this "WAV-Header" as well in the first few bytes.
See http://de.wikipedia.org/wiki/RIFF_WAVE
As you'll see its perfectly possible to compose these few bytes in the header and send them before your raw audio data,
You can use some library for reading data from microphone or playing it to speakers.
I worked successfuly with:
NAudio - http://naudio.codeplex.com/
I would not recommend building a WAV file yourself, it may be too much effort for this.
Note that this library (and probably some others, Bass - http://www.un4seen.com is also widely used) also have built in functionality for saving and reading WAV files.
NAudio is best app to play that functionality. use sample app provided.It may help.

NAudio - Changing Bitrate of Recorded WAV file

i am trying to implement audio recording using NAudio to a Wav file, but the default bitrate set by the WasapiLoopbackCapture class can't be changed programmatically.
I am recording the audio output to a MemoryStream (recordedStream in snippet below). However the default bitrate set by the WasapiLoobpackCapture doesn't fit my needs.
I would like to have a bit rate of 320KBPS and i tried to convert the recorded file programmatically using the WaveFormatConversionStream class, but i couldn't make it work.
WaveFormat targetFormat = WaveFormat.CreateCustomFormat(waveIn.WaveFormat.Encoding,
waveIn.WaveFormat.SampleRate, //SampleRate
waveIn.WaveFormat.Channels, //Channels
320000, //Average Bytes per Second
waveIn.WaveFormat.BlockAlign, //Block Align
waveIn.WaveFormat.BitsPerSample); //Bits per Sample
using (WaveStream inputStream = new RawSourceWaveStream(recordedStream, waveIn.WaveFormat))
{
try
{
using (var converter = new WaveFormatConversionStream(targetFormat, inputStream))
{
// ...
}
}
catch (Exception)
{
throw;
}
recordedStream.Dispose();
}
I always get an "AcmNotPossible calling acmStreamOpen" conversion exception. As you see i am using exactly the same format as the recorded WAV file (Extension encoding, 44100 etc.), except the bitrate which is lower in the target waveformat.
What would be the correct codeto do the bitrate conversion from a Wav file contained in a MemoryStream? my goal is to get a 320KBPS file.
For a given sample rate, bit depth, and channel count, PCM audio always has the same bitrate (calculated by multiplying those three values together). If you want to reduce the bitrate, you must change one of those three (lowering the sample rate is probably the best option unless you can go from stereo to mono).
Really you should be thinking of encoding to a format like MP3, WMA or AAC, which will let you select your preferred bitrate.

How to Convert PDF File into Image File using ImageMagick

How should I convert pdf file into image (.jpg, .gif etc) using ImageMagick on c# programming platform? or is there any third party library aside from ImageMagick that can be used to do this?
Ghostscript can read PDF (as well as PostScript and EPS) and convert it to many different image formats.
*BTW, ImageMagick cannot do that itself -- ImageMagick also utilizes Ghostscript for exactly that conversion as an external 'delegate'. ImageMagick is great for continuing to process and manipulate image files -- at which jobs it really excels!
The command gs -h (or on Windows: gswin32c.exe -h) should give you an overview about the different devices that are built into your Ghostscript:
GPL Ghostscript GIT PRERELEASE 9.05 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
Usage: gs [switches] [file1.ps file2.ps ...]
Most frequently used switches: (you can use # in place of =)
-dNOPAUSE no pause after page | -q `quiet', fewer messages
-g<width>x<height> page size in pixels | -r<res> pixels/inch resolution
-sDEVICE=<devname> select device | -dBATCH exit after last file
-sOutputFile=<file> select output file: - for stdout, |command for pipe,
embed %d or %ld for page #
Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF
Default output device: x11alpha
Available devices:
alc1900 [....] bmp16 bmp16m [...]
bmp256 bmp32b bmpgray bmpmono bmpsep1 bmpsep8 [....] jpeg jpegcmyk jpeggray
pamcmyk32 pamcmyk4 pbm pbmraw pcl3 pcx16 pcx24b [....]
pcx256 pcx2up pcxcmyk pcxgray pcxmono pdfwrite pgm pgmraw pgnm pgnmraw
png16 png16m png256 png48 pngalpha
pnggray pngmono pnm pnmraw ppm ppmraw [....] tiff12nc tiff24nc tiff32nc tiff48nc
tiff64nc tiffcrle tiffg3 tiffg32d tiffg4 tiffgray tifflzw tiffpack
tiffscaled tiffscaled24 tiffscaled8 tiffsep tiffsep1 [....]
So, to create a series of PNGs from the multipage PDF my_pdf.pdf with a certain image size (I chose DIN A4 paper format at 72 dpi) and resolution, use the pngalpha device. Try this command:
gswin32c ^
-o my_pdf_page_%03d.png ^
-sDEVICE=pngalpha ^
-dPDFFitPage ^
-g595x842 ^
-r72x72 ^
my_pdf.pdf

Converting wav file to wav file (changing format)

Trying to find a workaround for my previous question, I'd like to convert a 16k 8bit mono wav which is written in byte[] (which has wav header) to a 8k 8bit mono stream/byte[].
Is there any .Net library with samples available for this kind of conversion?
Thank you.
Thanks for the answers, I ended up using NAudio and with the following snippet, Voila! Everything works like a charm:
WaveFormat target = new WaveFormat(8000, 8 , 1);
WaveStream stream =new WaveFileReader("c:\\test.wav");
WaveFormatConversionStream str = new WaveFormatConversionStream(target, stream);
WaveFileWriter.CreateWaveFile("c:\\converted.wav", str);
Alvas seems to support conversion as well as the usual features:
http://alvas.net/alvas.audio.aspx

Categories