This question is an exact duplicate of:
I'm tryng to encode video and audio at the same time using Ffmpeg. At the moment I'm using this command:
ffmpeg -r 24 -pix_fmt rgba -s 1280x720 -f rawvideo -y -i -f s16le -ac 1 -ar 44100 -i - -acodec pcm_s16le -ac 1 -b:a 320k -ar 44100 -vf vflip -vcodec mpeg1video -qscale 4 -bufsize 500KB -maxrate 5000KB OUTPUT_FILE
At first I had this without the information and input from the audio. So, without the audio this works fine:
ffmpeg -r 24 -pix_fmt rgba -s 1280x720 -f rawvideo -y -i -vf vflip -vcodec mpeg1video -qscale 4 -bufsize 500KB -maxrate 5000KB OUTPUT_FILE
To write the frames to the encoder (still not using audio) I'm using the following code:
fwrite(frame, sizeof(unsigned char*) * frameWidth * frameHeight, 1, ffmpeg);
Now, I want to add audio to this encoder (see the first command). I added a new input and added the information about the audio to the command but I have no idea how I should write, and when, the audio to the encoder (together with the video).
I've tried this by adding the following code:
for (int t = 0; t < 44100/24; ++t)
fwrite(&audio, sizeof(short int), 1, ffmpeg);
This should write ~2000 samples of audio per video frame to the encoder. This code is called right after the fwrite() for the video frame.
This does give weird results however. The image is not rendered in the right spot, gives green flashes and there is no audio.
I can't really figure out how (or when) to write the audio to the encoder.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire