No audio when streaming to rtmp server using 'rtmpsink' and 'x264enc'

Hello everyone. I’m trying to use gstreamer to push my local video file to a hosted rtmp server. The streaming can be done but with video only and no sound.

Here is how I push streaming to the RTMP server:

gst-launch-1.0 -v filesrc location='D:/Download/test.mkv' ! decodebin ! x264enc ! flvmux ! rtmpsink location='rtmp://localhost/live/test'

and here is how I play the video stream:

 ffplay -i rtmp://localhost:1935/live/test   

I think the problem could be that ‘x264enc’ only handles video but no audio or subtitles. Then how can I push audio or subtitle to rtmp server with video as a whole so we can play them in sync? I cant find a clear solution or idea for this…

Try to add a queue with audio encoding part. I use this one to encode audio
https://gstreamer.freedesktop.org/documentation/voaacenc/index.html?gi-language=c

1 Like

Could try something like this (untested):

gst-launch-1.0 -v flvmux name=mux ! rtmpsink location='rtmp://localhost/live/test' \
    filesrc location='D:/Download/test.mkv' ! decodebin3 name=d  \
    d. ! queue ! videoconvert ! x264enc ! mux. \
    d. ! queue max-size-bytes=0 max-size-time=0 max-size-buffers=0 ! audioconvert ! voaacenc ! mux.

(made audio queue unlimited because x264enc will consume 2-3 seconds of audio video by default before outputting anything in the default configuration; you can drop this if you use x264enc tune=zerolatency)

1 Like

Thanks. It’s helps my problem.

Thanks for your detailed suggestion! Your example works smoothly. I’ve use tune=zerolatency and it works fine, too.