Gstreamer: Encode microphone audio using AAC encode to mp4 - audio

Wondering if it is possible to encode using AAC into mp4 container
I have tried using the following
gst-launch-1.0 alsasrc device="hw:0,0" ! "audio/x-raw,rate=48000,channels=2,depth=16" ! queue ! audioconvert ! avenc_aac ! qtmux ! filesink location=audio.mp4
The program runs without a fault but when I inspect the file content, it gives me a null content
However when i run with avimux, the file content gives the encoding and details like lenght of audio
gst-launch-1.0 alsasrc device="hw:0,0" ! "audio/x-raw,rate=48000,channels=2,depth=16" ! queue ! audioconvert ! avenc_aac ! avimux ! filesink location=audio.mp4
Wander what is wrong as I would need AAC encoding (for later rtsp streaming) and need to use mp4 as container and qtmux
thanks

You don't really say what you are doing exactly. But most likely you are missing the -e option for gst-launch-1.0. With that an EOS signal is propagated through the pipleine to correctly finalize the mp4 file. Other file formats are not that picky, but mp4 needs to write a proper index when all samples have been written.

Related

How to solve a RAW stream playback problem with GStreamer and VAAPi

I am currently experiencing a small problem with GStreamer, here are more details:
Configuration:
Intel i7-6700
Intel HD Graphics 530
Ubuntu 18.04 LTS
GStreamer1.0
VAAPI plugin
I receive a UDP stream from a video source, this stream is sent in RAW UYVY format. Here is my command line to decode it:
gst-launch-1.0 -v udpsrc port="1234" caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)1920, height=(string)1080, colorimetry=(string)BT709-2, payload=(int)96, ssrc=(uint)1188110121, timestamp-offset=(uint)4137478200, seqnum-offset=(uint)7257, a-framerate=(string)25" ! rtpvrawdepay ! decodebin ! queue ! videoconvert ! xvimagesink
Problem as we can see on the screenshot below, the CPU load (right) is far too high for this kind of task and we can see the GPU load (left) which is almost zero.
To overcome this problem, I want to use the VAAPI graphics acceleration as I did in a previous project with H264 of which here is the command line below:
gst-launch-1.0 -v udpsrc port=1234 caps= "application/x-rtp, media\=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)640028, payload=(int)96, ssrc=(uint)2665415388, timestamp-offset=(uint)3571350145, seqnum-offset=(uint)18095, a-framerate=(string)25" ! rtph264depay ! queue ! vaapih264dec low-latency=1 ! autovideosink
The line above works perfectly and the CPU has almost no more loads. So I adapt this command line to use it with a RAW stream, here is the command:
gst-launch-1.0 -v udpsrc port="1234" caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)1920, height=(string)1080, colorimetry=(string)BT709-2, payload=(int)96, ssrc=(uint)1188110121, timestamp-offset=(uint)4137478200, seqnum-offset=(uint)7257, a-framerate=(string)25" ! rtpvrawdepay ! vaapidecodebin ! videoconvert ! xvimagesink
It is the same line as the one at the beginning but I changed the element decodebin by vaapidecodebin as I had replaced avdec_h264 by vaapih264dec for my H264 stream. Unfortunately it doesn't work and I end up with this error:
WARNING: wrong pipeline: unable to connect rtpvrawdepay0 to vaapidecodebin0
How I can solve this problem? Do you have any leads to solve this problem?
What exactly are you trying to accelerate here? The CPU load is probably either due to the videoconvert as this is run in software to convert UYVY into a format your renderer supports (Hopefully that's another YUV format and not RGB) or it is the data transfer of the uncompressed data from CPU memory to GPU memory.
Note that transferring uncompressed image data is a much higher data rate than compressed H.264 video.
If you think the videoconvert is the expensive part you may want to try to use OpenGL for convert and displaying: .. ! glupload ! glcolorconvert ! glimagesink.
Maybe vaapipostproc can help you with color conversion if you don't want to go the OpenGL route.

GStreamer stream audio and video via UDP to be able to playback on VLC

I am trying to stream audio and video via Gstreamer via UDP but playback on VLC only returns video without audio. Currently I am using a sample of Big Buck Bunny and have confirmed that it does have audio. I am planning to use Snowmix to feed media to Gstreamer output in the future.
Streaming from file source via UDP to playback on VLC I currently perform by:
gst-launch-1.0 -v uridecodebin uri=file:///home/me/files/Snowmix-0.5.1/test/big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 ! queue ! videoconvert ! x264enc ! mpegtsmux ! queue ! udpsink host=230.0.0.1 port=4012 sync=true
which allows me to open a network stream in VLC on my Windows machine to receive packets and only plays video.
What am I missing from my command?
As RSATom stated previously, the audio is missing from the pipeline.
The correct pipeline for video and audio is the next (tested with the same input file):
gst-launch-1.0 -v uridecodebin name=uridec uri=file:///home/usuario/Desktop/map/big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 ! queue ! videoconvert ! x264enc ! video/x-h264 ! mpegtsmux name=mux ! queue ! udpsink host=127.0.0.1 port=5014 sync=true uridec. ! audioconvert ! voaacenc ! audio/mpeg ! queue ! mux.
Remember that in this case you're re-encoding all the content from the source video file, which means high CPU consumption. Other option would be to demux the content from the input file and mux again without encoding (using h264parse and aacparse).

gstreamer pipeline for streaming multiplexed h.264 and aac audio between two raspberry pi's

I have been stuck on this for days now. I am trying to come up with a GStreamer pipeline that will stream h.264 video and compressed audio (aac, mulaw, whatever, I don't really care) over a single rtp stream. The problem seems to always be with the multiplexer. I've tried asf, avi, mpegts, Matroska and flv multiplexers and it seems they are all oriented towards files (not network streaming) and are therefore requiring header information. Anyway, here's my latest attempt:
gst-launch-1.0 -e --gst-debug-level=4 \
flvmux name=flashmux streamable=true ! flvdemux name=flashdemux ! decodebin name=decode \
videotestsrc ! 'video/x-raw,width=640,height=480,framerate=15/1' ! omxh264enc ! flashmux. \
audiotestsrc ! 'audio/x-raw,format=S16LE,rate=22050,channels=2,layout=interleaved' ! flashmux. \
decode. ! queue ! autovideoconvert ! fpsdisplaysink sync=false \
decode. ! queue ! audioconvert ! alsasink device="hw:1,0"
This pipeline removes rtp and simply feeds the decoder with the encoder. Also, this attempt uses raw audio, not encoded. Any help will be greatly appreciated!
To stream video+audio you should use 2 different ports.
Using rtpbin element to manage rtp session
Example http://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/tests/examples/rtp/server-v4l2-H264-alsasrc-PCMA.sh

gStreamer Video Recording Memory Leak

HI I am trying to record rtsp stream coming from camera(H264 format).
I am using following gst command to do recording in MPEG4 Format
gst-launch -e rtspsrc location=rtsp://10.17.8.136/mediainput/h264 latency=100 ! decodebin ! ffenc_mpeg4 ! avimux ! filesink location=test.mp4
and H264 format
gst-launch-0.10 -e rtspsrc location="rtsp://10.17.8.136/mediainput/h264" latency=100 ! rtph264depay byte-stream=false ! capsfilter caps="video/x-h264,width=1920,height=1080,framerate=(fraction)25/1" ! mp4mux ! filesink location=testh264.mp4
Both are doing recording but i have observed that There is RAM mermory is gradually increasing.
Does gStreamer has memory leak. or there is problem in my pipeline command?
That is not a leak, the mp4 muxer is building the index table in memory, before writing it out to disk on eos.

How to record Audio using Microphone in AAC codec format

How to record Audio using Microphone in AAC codec format in mp4 file using gstreamer ?
Please reply with pipeline info.
Thanks in advance.
If your default audio source is Microphone, then you can try
gst-launch autoaudiosrc ! audioconvert ! faac ! mp4mux ! filesink location=aac_audio.mp4
However if you have multiple audio sources and mic is not default audio source, then you have to specify device identifier of the mic input. Plus you need to know whether you have ALSA or OSS driver.
My suggestion would be to try
gst-launch alsa-src device=<device identifier for mic input> ! audioconvert ! faac ! mp4mux ! filesink location=aac_audio.mp4
or
gst-launch oss-src device=<device identifier for mic input> ! audioconvert ! faac ! mp4mux ! filesink location=aac_audio.mp4
depending on which driver you have.

Resources