ffmpeg - Stream webcam - RTP h264 + audio - audio

I am trying to create a rtp stream using ffmpeg. I am taking input from my logitech C920 which has built in h264 encoding support and also has a microphone. I wanted to send both video(h264 either with the built in encoder or ffmpeg's encoder) and audio(any encoding) through RTP and then play the stream using ffplay.
So far I am able to send only the video with the following command:
ffmpeg -i /dev/video0 -r 24 -video_size 320x240 -c:v libx264 -f rtp rtp://127.0.0.1:9999
and also the audio separately using the command:
ffmpeg -f alsa -i plughw:CARD=C920,DEV=0 -acodec libmp3lame -t 20 -f rtp rtp://127.0.0.1:9998
and play the sdp file with:
ffplay -i -protocol_whitelist file,udp,rtp test3.sdp
ffplay -i -protocol_whitelist file,udp,rtp test4.sdp
I'm on Ubuntu 14.04
How can I play the two streams with a single ffplay command as ffplay cannot take two inputs and I can't send two streams using a single RTP stream(or can I?).
Also, how can I use the built in h264 encoder of my webcam?
Thank you!

Related

Webrtc streaming issue with Wowza and FFMPEG

I am trying to stream video and audio from a Camera in a browser using Webrtc and Wowza Media Server (4.7.3 version).
The camera stream (h264/aac) is first of all transcoded by using FFMPEG (version N-89681-g2477bfe built with gcc 4.8.5, last available version on ffmpeg website) in VP8/OPUS and then pushed to the Wowza Server.
By using the small Wowza webpage I ask for the Wowza stream to be displayed in the browser (Chrome Version 66.0.3336.5 Build officiel canary 32 bits).
FFMPEG used command :
ffmpeg -rtsp_transport tcp -i rtsp://<camera_stream> -vcodec libvpx -vb 600000 -crf 10 -qmin 0 -qmax 50 -acodec libopus -ab 32000 -ar 48000 -ac 2 -f rtsp rtsp://<IP_Address_Wowza>:<port_no_ssl>/<application_name>/test
When I click on Play stream I have a very bad quality video and audio (jerky video and very bad audio).
If I use this FFMPEG command:
ffmpeg -rtsp_transport tcp -i rtsp://<camera_stream> -vcodec libvpx -vb 600000 -crf 10 -qmin 0 -qmax 50 -acodec copy -f rtsp rtsp://<IP_Address_Wowza>:<port_no_ssl>/<application_name>/test
I will have a good video (flowing, smooth) but no audio (the camera micro is ON).
If libopus is the problem (as this test first shows), I tried libvorbis but with Chrome console I have this error "Failed to set remote offer sdp: Session error code: ERROR_CONTENT". Weird, cause libvorbis is one of the available codecs for Webrtc.
Is someone experiencing the same issue ? Did someone experience the same issue ?
Thanks in advance.
You probably have no audio because opus must have sample rate of 48000
You should add the flag:
"-ar 48000"
to the output settings
I also experienced the "bad quality video and audio issues".
I finally solved the issue by adding:
"-quality realtime" to the output settings .
That work well for me, I hope this will help you.

FFmpeg RTP_Mpegts over RTP protocol

I'm tryin to implement a client/server application based on FFmpeg. Unfortunately RTP_MPEGTS isn't documented in the official FFmpeg Documentation - Formats.
Anyway i found inspiration from this old thread.
Server Side
(1) Capture mic audio as input. (2)Encode it as pcm 8khz mono and (3) send it locally as RTP_MPEGTS format over rtp protocol.
ffmpeg -f avfoundation -i none:2 -ar 8000 -acodec pcm_u8 -ac 1 -f rtp_mpegts rtp://127.0.0.1:41954
This works, but on initiation it alerts "[mpegts # 0x7fda13024600] frame size not set"
Client Side (on the same machine)
(1) Receive rtp audio stream input (2) write it in a file or playback.
ffmpeg -i rtp://127.0.0.1:41954 -vcodec copy -y "output.wav"
I'm using -vcodec copy because i've already verified it in another rtp stream in which -acodec copy didn't work.
This stuck and while closing with Ctrl+C shortcut it prints:
Input #0, rtp, from 'rtp://127.0.0.1:41954':
Duration: N/A, start: 8.956122, bitrate: N/A
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0: Data: bin_data ([6][0][0][0] / 0x0006)
Output #0, wav, to 'output.wav':
Output file #0 does not contain any stream
I don't understand if the client didn't receive any stream, or it cannot write rtp packets into "output.wav" file. (Client or server problem?)
In the old thread is explained a workaround. On server could run 2 ffmpeg instance:
One produces "tmp.ts" file due to mpegts, and the other takes "tmp.ts" as input and streams it over rtp. Is it possibile?
Is there any better way to do implement this client/server with the lowest latency possible?
Thanks for any help provided.
I tested this with an .aac file and it worked:
Streaming:
(notice I use a multicast address.
But if you test the streaming and receiving on the same machine you might use your 127.0.0.1 as loopback address to the local host.)
ffmpeg -f lavfi -i testsrc \
-stream_loop -1 -re -i "music.aac" \
-map 0:v -map 1:a \
-ar 8000 -ac 1 \
-f rtp_mpegts "rtp://239.1.1.9:1234"
You need a video source for the rtp_mpegts muxer. I created one with lavfi.
I used -stream_loop to loop the .aac file forever for my test. You don't need this with a mic as input.
Capture stream:
ffmpeg -y -i "rtp://239.1.1.9:1234" -c:a pcm_u8 "captured_stream.wav"
I use the -c:a pcm_u8 while capturing on purpose, because using it in the Streaming did not work on the capturing side.
The output is a low quality 8bit, 8kHz mono audio file but that was what you've asked for.

Streaming mp4a to localhost using udp and ffmpeg

I am using the following command to stream a video and it's audio to localhost:
ffmpeg -re -i out.mp4 -map 0:0 -vcodec libx264 -f h264 udp://127.0.0.1:1234 -map 0:1 -acodec libfaac -f mp4a udp://127.0.0.1:2020
FFmpeg is not recognising my audio codec and my audio format so I get the following error message:
Error
What audio format and codec do I need to use? The codec information of the video I wish to send is as follows:
Codecs used
When I convert the audio track to mp3 I can run the above command and stream the video and audio properly. However I dont want to convert all my video audio-tracks to mp3.
(I am confused by all the encoders, decoders, codec names in the ffmpeg documentation) Is there a way of finding the right encoder to use with the mp4a audio codec other than reading the whole list of codecs and options?
Thanks.

When converting mkv to mp4, the audio is lost

I have converted my .mkv file into an .mp4 by using the command:
sudo avconv -i input.mkv -codec copy output.mp4
I am trying to play the mp4 file in the browser, but the audio is not playing. The video player shows that it is on mute, but the button is disabled so you cannot turn it off of mute.
Other mp4s are working, but they were not converted from .mkv. Any help would be much appreciated.
In an MP4 container, browsers usually support only H.264 video and either AAC or MP3 audio. The output from your avconv command should show the format of your video and audio; look under "Input #0" for the lines that start with "Stream #". If you audio is not already AAC or MP3 you will want to convert it instead of just copying it to the MP4 container. You can copy the video and convert only the audio with a command like this:
avconv -i input.mkv -c:v copy -c:a libmp3lame -q:a 2 output.mp4
The -c:v copy will copy the video, and -c:a libmp3lame will convert the audio to MP3 using the libmp3lame encoder. -q:a 2 sets the audio quality; use a lower number for better quality (and a larger file). You could instead convert to AAC audio if your avconv was configured with non-free codecs enabled and a good quality AAC encoder.

h264 restream works when i have no audio in ffserver conf but does not work when i try to add audio

I am trying to restream an h264 video stream from a camera. All works well when I have NoAudio in my conf file. However when i add audio, even the video stream does not work. Has anyone ever encountered thiss?
ffmpeg -i rtsp://*** -s 320x240 -vcodec copy -acodec copy -s 320x240 -ab 64k http://*:8091/feed1.ffm

Resources