How to convert AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_S16P? - c

I use ffmpeg to decode audio and use libmp3lame to encode it into mp3. As libmp3lame inside ffmpeg needs S16P instead of S16, I have to convert audio samples.
I tried using swr_convert but everytime I get a random crash. I started to have doubt if swr_convert accepts S16 as input or not.
So, how can I convert audio samples from AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_S16P?

Related

How to encode pixel data into a video format?

I'm using ESCAPI to capture webcam, it captures the frames in form of RGB pixel data, I've stored the RGB pixel data into a file but the file is huge 200MB for 15s video of 320x240.
I want to encode that pixel data into a video format.
I'm using MinGW on windows.
First use any encoder
I suggest H264 codec for encoding
so find its library for encoding and encode it
Then find any container File formats
I suggest Matroska (.mkv file)
so find its library for muxing encoded h264 in .mkv
Good begining is start with ffmpeg libraries.

Load wave into array + Subtract channels + Save as wave/mp3

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

Re-encode with ffmpeg

I am trying to do following work in C code with the help of ffmpeg library
Decode a mp2 audio file.
Write decoded data to a file named test.sw
Read data from test.sw and re-encode it to mp2 audio file.
For 1 and 2, i followed example given in decoding_encoding.c which is working fine. While reading and re-encoding, i can't understand how to read from test.sw file and encode it. Can anybody help me with that? It will help me a lot if anybody can provide me any tutorial regarding this topic.
As I understood your question you want to encode to mp2 format.I suggest to use the encoding technique used for mp2 format and use the library ,You have one library ffmpeg just check is it having for encoding .If yes then just use that function and pass your decoded file.
You can check it
http://ffmpeg.org/doxygen/trunk/encoding-example_8c-source.html

processing .raw file image with ffmpeg api or C code

I am trying to process a .raw image file captured using vrl2, it's a h264 encoded image with yuv422 color space from a Logitech c920 webcam, dcraw is not working for me however from my previous question this command is working fine with low performance (a 32kb jpg image however using opencv capture I get a 900kb image for the same 640x480 resolution):
ffmpeg -f rawvideo -s 640x480 -pix_fmt yuyv422 -i frame-1.raw
frame-1.jpg
I need a code written in C or the ffmpeg api/OpenCV etc .. to do the same as this command,I don't want to use QProcess in Qt(I am working on a server using Qt where I am trying to send the raw file from a Raspberry PI to the server and process it their), dcraw output is a corrupted image.
http://ffmpeg.org/doxygen/trunk/examples.html
There should be some api samples in there that show how to get the image out with that specific encoding.
When interacting with a RAW file, I have also used IrfanView. If you know the headersize of the file and the width and the height and the bits per pixel per color, you can see what it looks like quickly that way.
EDIT: I tried using Irfanview with your RAW, and I got something close, but not quite. The coloring was always off. I don't think it can handle that particular encoding of a RAW file right now.

Save video encoded by libavcodec to an AVI file format

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.

Resources