I have a raw stereo audio file.
It is part of a noise cancellation system on the raspberry pi, Microphone 1 records the main voice to the left channel, Microphone 2 the surrounding noises to the right channel. Goal is to subtract the right channel from the left channel. I am going to write what I tried but I don't want you to stick to it and meddle with it if another way is much easier.
Recording takes place using a modified http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html version. I output it to the raw audio file, which is a valid raw file. Advantage of stereo is that they are in sync. See my other question on How to find the right RAW format.
To summarize: How do I
Load a wave file into an array? ( I am asking this because in my other question the wave format never seems right)
Subtract the right channel from the left channel? (I presume sample_left minus sample_right)
Save it as raw or even better mp3 mono. ( I could pipe to lame )
If you are3 giving raw audio file as input or reading raw audio samples from audio device file, You can do following
1.Open raw audio file in binary format and read raw data in to a buffer,if you are using a file to give raw audio data. (or) Read Raw audio samples from audio device fire in to a buffer.
2.We know that Right audio channel is always followed by left audio channel in stereo audio format. So you can simply separate left and right audio channels. For example, if your device is giving 16-bit pcm pulses, that means, first 16-bits are left channel and next 16-bits are right channel.
3.You can simply open a normal binary file and you can make it as a wav file by defining wav header at the stating of the file. Define a wav header and write audio data in to wav file.
For wav file references see here
Related
I'm working on a project that needs to open .mp4 file format, read it's frames 1 by 1, decode them and encode them with better type of lossless compression and save them into a file.
Please correct me if i'm wrong with order of doing things, because i'm not 100% sure how this particular thing should be done. From my understanding it should go like this:
1. Open input .mp4 file
2. Find stream info -> find video stream index
3. Copy codec pointer of found video stream index into AVCodecContext type pointer
4. Find decoder -> allocate codec context -> open codec
5. Read frame by frame -> decode the frame -> encode the frame -> save it into a file
So far i encountered couple of problems. For example, if i want to save a frame using av_interleaved_write_frame() function, i can't open input .mp4 file using avformat_open_input() since it's gonna populate filename part of the AVFormatContext structure with input file name and therefore i can't "write" into that file. I've tried different solution using av_guess_format() but when i dump format using dump_format() i get nothing so i can't find stream information about which codec is it using.
So if anyone have any suggestions, i would really appreciate them. Thank you in advance.
See the "detailed description" in the muxing docs. You:
set ctx->oformat using av_guess_format
set ctx->pb using avio_open2
call avformat_new_stream for each stream in the output file. If you're re-encoding, this is by adding each stream of the input file into the output file.
call avformat_write_header
call av_interleaved_write_frame in a loop
call av_write_trailer
close the file (avio_close) and clear up all allocated memory
You can convert a video to a sequence of losses images with:
ffmpeg -i video.mp4 image-%05d.png
and then from a series of images back to a video with:
ffmpeg -i image-%05d.png video.mp4
The functionality is also available via wrappers.
You can see a similar question at: Extracting frames from MP4/FLV?
I have 2 separate stereo wav files, and I want to create a wav file with the 2 stereo tracks but without mixing them. So that the left channel of file 1 would be mapped to the left channel of track 1 of the multitrack file, etc.
How can you do this with melt?
Thanks
Just as you first said, 4 audio tracks in the output file.Two from the first file and two from the second file.
I would like to know about the meaning of each byte in a wav / mp3 files.
But find nth from google...anyone knows where i can find such information?
(Infact I would like to know all types of multimedia files in the bitstream level)
MP3 files are divided into frames, each begins with a sequence of FRAMESYNC bits so hardware can find the beginning of each frame. More here.
Some info about WAV is here.
I am able to encode video frames using libavcodec, by calling avcodec_encode_video function. How do I save these encoded frames into an AVI file?
Check this out:
http://forum.doom9.org/archive/index.php/t-112286.html
You must open file for binary write, write header in it, and simultaniosly put binary frames in it, I think.
I was wondering if sending a file with a jpg extension through a socket_stream, this automatically makes the transformation of bytes to jpg ? or need to implement some algorithm to transform the lot of bytes to image... Please could somebody explain me the way to do?
JPEG images are nothing but a bunch of bytes organized according to the JPEG format. A network socket isn't going to organize random bytes into the JPEG format. You can send the bytes that make up a JPEG formatted image across a socket as a binary blob, receive it on the other end, and write it to a file with a .jpg extension. An application can interpret this file as a JPEG image based on the extension and try to display it. But you are still responsible for providing a set of bytes that are organized as a JPEG image.