Pratik
Pratik

Reputation: 1

How to record audio and video using gstreamer in c code

I am able to record video and audio together using below gstreamer command.

gst-launch-1.0 -e qtiqmmfsrc camera=1 name=qmmf ! video/x-raw,format=NV12,width=1920,height=1080,framerate=20/1 ! qtic2venc ! h264parse ! queue ! mux. alsasrc device=hw:0,0 buffer-time=50000 ! queue ! audioconvert ! audioresample ! avenc_aac ! aacparse ! queue ! mpegtsmux name=mux ! filesink location=/data/Pratik/test.mp4

Muxer will be used to combined video and audio data together and store it in file. But how to convert command logic in c gstreamer code? Can you please provide me one sample c code which can record audio and video together in one file?

Upvotes: 0

Views: 218

Answers (1)

MALPY
MALPY

Reputation: 23

Here is the generic way to mux two sources together: simply link them both with the muxer:

gst_element_link(video_source, muxer);
gst_element_link(audio_source, muxer);
gst_element_link(muxer, sink);

In your case, video_source is qtiqmmfsrc, audio_source is alsasrc, muxer is mpegtsmux and sink is filesink.
To link multiple elements at once (your converters for example), you can use

gst_element_link_many

Don't forget to add these elements to the pipeline first.

Let me know if you need help instanciating these elements or setting the pipeline to the playing state.

In any ways, the gstreamer tutorials are a very good starting point to start using gstreamer in c. For example tutorial 7, which accomplishes the opposite of what you are trying to do.

Upvotes: 1

Related Questions