I want to receive a RTP Stream and send the raw data received in it over TCP / UDP socket. For this i am trying following commands.
I am sending the RTP stream using following command.
ffmpeg -re -i hello.wav -ar 8000 -f mulaw -f rtp rtp://127.0.0.1:1234
Receiver to re transmit the stream over TCP / UDP socket.
ffmpeg -i rtp://127.0.0.1:1234 -f mulaw tcp://127.0.0.1:5555 -hide_banner
A Player to play this Socket stream to verify.
ffplay tcp://127.0.0.1:5555?listen
My second command shows that its receiving data and transmitting the data to tcp over 5555 port.
Input #0, rtp, from 'rtp://127.0.0.1:1234':
Duration: N/A, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_mulaw (native) -> pcm_mulaw (native))
Press [q] to stop, [?] for help
Output #0, mulaw, to 'tcp://127.0.0.1:5555':
Metadata:
encoder : Lavf58.29.100
Stream #0:0: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
Metadata:
encoder : Lavc58.54.100 pcm_mulaw
But the third command does not receive anything, even i tried dumping the response into a file using FFMPEG in command three but same results.
What am i doing wrong, Please suggest the correct commands using FFMPEG.
Following three commands worked for me.
ffmpeg -re -i music.wav -ar 8000 -f mulaw -f rtp rtp://127.0.0.1:1236
ffmpeg -i rtp://127.0.0.1:1236 -f wav tcp://127.0.0.1:1256
ffplay tcp://127.0.0.1:1256?listen -ar 8000
I am able to send file as RTP, convert it to raw wav and send it over socket and then play it from that socket.
Related
I use this cmd convert s16le to pcmu8, but will lost header info.
ffmpeg -i s16le.wav -f u8 pcmu8.wav
ffmpeg -i pcmu8.wav
# pcmu8.wav: Invalid data found when processing input
I want known, how add this header info into pcmu8.wav?
It should be this:
ffmpeg -i pcmu8.wav
#Input #0, wav, from 'pcmu8.wav':
# Duration: 00:13:39.20, bitrate: 64 kb/s
# Stream #0:0: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 8000 Hz, mono, u8, 64 kb/s
Your first command is outputting to a raw bitstream, not a WAV, so adding a header won't help. Instead use
ffmpeg -i s16le.wav -c:a pcm_u8 pcmu8.wav
I'm having an issue with ffmpeg 3.2.2; ordinarily I ask it to make an MP4 video file with 2 audio streams. The command line looks like this:
ffmpeg.exe
-rtbufsize 256M
-f dshow -i video="screen-capture-recorder" -thread_queue_size 512
-f dshow -i audio="Line 2 (Virtual Audio Cable)"
-f dshow -i audio="Line 3 (Virtual Audio Cable)"
-map 0:v -map 1:a -map 2:a
-af silencedetect=n=-50dB:d=60 -pix_fmt yuv420p -y "c:\temp\2channelvideo.mp4"
I've wrapped it for legibility. This once worked fine, but something is wrong lately - it doesnt seem to record any audio, even though I can use other tools like Audacity to record audio from these devices just fine
I'm trying to do some diag on it by dropping the video component and asking ffmpeg to record the two audio devices to two separate files:
ffmpeg.exe
-f dshow -i audio="Line 2 (Virtual Audio Cable)" "c:\temp\line2.mp3"
-f dshow -i audio="Line 3 (Virtual Audio Cable)" "c:\temp\line3.mp3"
ffmpeg's console output looks like:
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, dshow, from 'audio=Line 2 (Virtual Audio Cable)':
Duration: N/A, start: 5935.810000, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, dshow, from 'audio=Line 3 (Virtual Audio Cable)':
Duration: N/A, start: 5936.329000, bitrate: 1411 kb/s
Stream #1:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Output #0, mp3, to 'c:\temp\line2.mp3':
Metadata:
TSSE : Lavf57.56.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc57.64.101 libmp3lame
Output #1, mp3, to 'c:\temp\line3.mp3':
Metadata:
TSSE : Lavf57.56.100
Stream #1:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc57.64.101 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> mp3 (libmp3lame))
Stream #0:0 -> #1:0 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
The problem i'm currently having is that the produced mp3 are identical copies of line 2 only; line 3 audio is not recorded. The last line is of concern; it seems to be saying that stream 0 is being mapped to both output 0 and 1? Do I need a map command for each file also? I thought it would be implicit due to the way i specified the arguments
Turned out I needed to add a -map x:a between each source and output file, where x was either 0 or 1 depending on if it was the first or second source..
Is there any way to use ffmpeg to accurately break audio files into smaller files of a specific file size, or pull a specific number of samples from a file?
I'm working with a speech-to-text API that needs audio chunks in exactly 160,000 bytes, or 80,000 16-bit samples.
I have a video stream, and I have an ffmpeg command to extract audio from it:
ffmpeg -i "rtmp://MyFMSWorkspace/ingest/test/mp4:test_1000 live=1" -ar 16000 -f segment -segment_time 10 out%04d.wav
So now I have ~10 second audio chunks with a sample rate of 16 kHz. Is there any way to break this into exactly 160kb, 5 second files using ffmpeg?
I tried this:
ffmpeg -t 00:00:05.00 -i out0000.wav outCropped.wav
But the output was this:
Input #0, wav, from 'out0000.wav':
Metadata:
encoder : Lavf56.40.101
Duration: 00:00:10.00, bitrate: 256 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, 1 channels, s16, 256 kb/s
Output #0, wav, to 'outCropped.wav':
Metadata:
ISFT : Lavf56.40.101
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, mono, s16, 256 kb/s
Metadata:
encoder : Lavc56.60.100 pcm_s16le
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
size= 156kB time=00:00:05.00 bitrate= 256.1kbits/s
but now the size is 156kb
EDIT:
My finished command is:
ffmpeg -i "url" -map 0:1 -af aresample=16000,asetnsamples=16000 -f segment -segment_time 5 -segment_format sw out%04d.sw
That output looks perfectly right. That ffmpeg size is expressed in KiB although it says kB. 160000 bytes = 156.25 kB + some header data. ffmpeg shows size with fractional part hidden. If you want a raw file, with no headers, output to .raw instead of .wav.
For people converting video files to MP3s split into 30 minute segments:
ffmpeg -i "something.MP4" -q:a 0 -map a -f segment -segment_time 1800 FileNumber%04d.mp3
The -q option can only be used with libmp3lame and corresponds to the LAME -V option (source)
I have a mov file :
Metadata:
timecode: 09:59:50:00
Duration: 00:00:30.00, bitrate: 117714 kb/s
Stream #0.0(eng): Video: dvvideo, yuv422p, 1440x1080i tff [PAR 4:3 DAR 16:9]
, 115200 kb/s, 25.00 fps
Metadata:
codec_name: DVCPRO HD 1080i50
Stream #0.1(eng): Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Stream #0.2(eng): Data: unknown (tmcd)
I can see from MediaInfo
That the Audio is Muxed into the video. I'm trying to re-wrap this into an XDCAM, and copy over the audio streams. The problem is that I don't know how to map the audio that is wrapped into the video?
This is the command I have so far:
ffmbc -threads 8 -i "input.mov" -threads 8 -tff
-pix_fmt yuv422p -vcodec mpeg2video -timecode 09:59:50:00
.. other tags omitted ..
-acodec pcm_s24le
-map_audio_channel 0.1:0-0.1:0
-map_audio_channel 0.1:1-0.1:1
-f mov -y "output.mov"
-acodec pcm_s24le
-map_audio_channel 0.2:0-0.2:0
-map_audio_channel 0.2:1-0.2:1 -newaudio
When executed this returns "Cannot find audio channel 0.2.0". I changed the input stream identifier to stream 0, and 1 for the audios. Which when executed returned "Cannot find audio channel #0.0.0" presumably because it's trying to find a audio channel within the video stream?
How can I extract the audio from this file?
You may notice I'm using FFMBC, not FFMPEG ( there is no tag for FFMBC ), but I imagine it's the same for both. I'm not constrained to FFMBC, I can move to FFMPEG if it has a solution.
Thanks
has anybody gotten gstreamer to successfully pipe it's video output into ffmpeg?
I've tried playing with /dev/stdout and I keep getting errors:
gst-launch -e v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=1920,height=1080,framerate=5/1' ! nv_omx_h264enc quality-level=2 ! mp4mux ! filesink location=/dev/stdout \
| ffmpeg -y -i - -codec copy -f flv test.flv
...
[aac # 0xebc4c0] Could not find codec parameters for stream 0 (Audio: aac (Main), 7.1, fltp, 1351 kb/s): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
pipe:: could not find codec parameters
Input #0, aac, from 'pipe:':
Duration: N/A, bitrate: 1351 kb/s
Stream #0:0: Audio: aac (Main), 7.1, fltp, 1351 kb/s
[flv # 0xec9280] sample rate not set
Output #0, flv, to 'test.flv':
Stream #0:0: Audio: aac, 7.1, 1351 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
ubuntu#tegra-ubuntu:~$
Running the commands separately (replacing /dev/stdout with a file) works fine.
If you got it to work and can share how you did it, that would be great.
Thanks.
You can not use MP4 as a streaming format, as it cannot be parsed linear, e.g. without random access. Therefore it works with files, but not via a pipe.
Replacing the container format with a format that can be streamed should do the trick:
gst-launch -e v4l2src device=/dev/video0 \
! 'video/x-raw-yuv,width=1920,height=1080,framerate=5/1' \
! nv_omx_h264enc quality-level=2 ! matroskamux \
! filesink location=/dev/stdout \
| ffmpeg -y -i - -codec copy -f flv test.flv