sox.core.SoxError: Stdout: Stderr: sox FAIL formats: ‘XXX': WAVE: RIFF header not found when dealing with voice files from wxrobot - voice

I got .wav file from werobot through medie_id with url:"https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s",
Then I use sox to convert the file to demanded:
sox -D -V2 -t wav
/tmp/knime_deepspeech_app/Dc3hVz0p5YqtsFyZ4lXzVfyIrAnee5wMz2N4.wav -b 16 -c 1
/tmp/knime_deepspeech_app/nV2m5YeGhgeJSwMXhnOCnnLqatGEqS3YN1ar.wav highpass -2
150.000000 0.707000q lowpass -2 6000.000000 0.707000q rate -h 16000.000000
Error Info below:

The format of voice from wxrobot is amr, we need to use "ffmpeg -i {filePath_amr} -ar 16000 -ac 1 {filePath_wav}" to convert file from amr to wav, then the sox command runs ok!

Related

How to create an audio file from a Pcap file with Tshark?

I want to make audio data from a Pcap file with Tshark.
I have successfully created audio data from a Pcap file using Wireshark in RTP analysis function.
This Pcap file is created from a VoIP phone conversation.
Next time I want to do the same thing with Tshark.
What command would do that?
I read the Tshark manual to find out how.
but couldn't find it.
do i need any tools?
On Linux, extracting the RTP packets from PCAP file is possible with tshark together with shell tools tr and xxd, but then you might need other tools to convert to an audio format.
If you have a single call recording in the pcap, so all rtp packets belong to it, try with:
tshark -n -r call.pcap -2 -R rtp -T fields -e rtp.payload | tr -d '\n',':' | xxd -r -ps >call.rtp
If the pcap has the recordings from many calls, then you have to identify the calls and their RTP streams by source/destination IPs or SSRC and build the filter accordingly, for example if SSRC is 0x7f029328:
tshark -n -r call.pcap -2 -R rtp -R "rtp.ssrc == 0x7f029328" -T fields -e rtp.payload | tr -d '\n',':' | xxd -r -ps >call.rtp
Tools like sox or ffmpeg can be used to convert from call.rtp file to wav format, depending on the codec that was used in the call. If the codec was G711u (PCMU) with sample rate 8000:
sox -t ul -r 8000 -c 1 call.rtp call.wav
The audio formats supported by sox are listed by sox -h. The ffmpeg might be needed for codecs such as G729 or G722, example for G722 with sample rate 16000:
ffmpeg -f g722 -i call.rtp -acodec pcm_s16le -ar 16000 -ac 1 call.wav
These guidelines are from some brief notes I made during the past when I had similar needs, hope they are good and still valid nowadays, or at least provide the right direction to explore further.

Combine two ffmpeg commands

Is there a way to combine the following two ffmpeg commands into one?
ffmpeg -i OutputAudioEN.mp4 -acodec aac -strict -2 german.mp4
ffmpeg -i german.mp4 -c copy -f segment
-segment_list audio-de.m3u8 -segment_time 10 output%03d.ts
Is this possible to use the output from the first command for the second line, without using two separate commands?
Well, here I'm making my comment as a proper answer. What I'm suggesting here is you can directly segment the video and then encode the audio using acc according to your need. Following command works for me.
ffmpeg -i OutputAudioEN.mp4 -f segment -segment_list audio-de.m3u8 -segment_time 10 -acodec aac -strict -2 output%03d.ts
Like this you can segment the video while audio encoding also happens at the meantime.
Hope this helps you!

Does FFMPEG supports AES encryption

Want to know if the ffmpeg has in-built encryption . I have grabbed the frames from the camera and now I encode the video with this frame using ffmpeg.
But is it possible to encrypt the frames (AES) just like we mention the encode format.
Yes, ffmpeg supports AES.
You can create encrypted HLS segments for example using:
ffmpeg -i <input> -hls_time 10 -hls_key_info_file key_info playlist.m3u8
The same lib is also used for SRTP and possibly other formats.
If you want to encrypt just the I-frames you'll most likely need to write a custom program using the ffmpeg libs.
Yes Support AES Encryption
#!/bin/bash
mkdir -p /opt/FFMPEG/rawContent/
cd /opt/FFMPEG/rawContent/
mkdir -p /opt/FFMPEG/$1/processed/
mkdir -p /opt/FFMPEG/$1/encrypted/
var=`ls | grep -i 'mp4'`
for z in ${var}
do
cd /opt/FFMPEG/$1/encrypted/
fname=`echo ${z} | awk -F "." '{print $1}'`
BASE_URL=" ${fname}.key"
openssl rand 16 > ${fname}.key
echo $BASE_URL > ${fname}.keyinfo
echo ${fname}.key >> ${fname}.keyinfo
echo $(openssl rand -hex 16) >> ${fname}.keyinfo
fname=`echo ${z} | awk -F "." '{print $1}'`
sleep 1
ffmpeg -i /opt/FFMPEG/rawContent/${fname}.mp4 -profile:v baseline -level 4.0 -start_number 0 -hls_time 10 -hls_list_size 0 -hls_key_info_file ${fname}.keyinfo* -f hls ${fname}.m3u8
mv /opt/FFMPEG/rawContent/${fname}.mp4 /opt/FFMPEG/$1/processed/
done
cd -
Run above Shell as
./shellname.sh NameOfTheFolder
(./test.sh TestOne)

Sox: Failed reading file: Sorry don't understand .wav size

I want to convert a 44,100 Hz, 24 Bit Mono wav file to aformat that I can play it in asterisk. How can I do this using sox? When I use "Sox filename.wav -t raw -r 44100 -s -w -c 1 filename.sln" I get error "Sox: Failed reading file: Sorry don't understand .wav size". What is the problem?
SoX can't handle 24-bit samples. You will have to use a different program for those.
Try sndfile-convert.
http://itdp.fh-biergarten.de/transcode-users/2005-12/msg00150.html

MPEG-TS audio synchronization lost on segmentation

I use FFmpeg for encoding my iphone video (on debian) and mediafilesegmenter (on mac OS server). For encoding this is my commande :
ffmpeg -i INPUT -y -acodec libfaac -ar 22000 -ab 40k -vcodec libx264 -b 600k \
-bt 600k -vpre slow -vpre baseline -threads 1 -level 30 -r 10 -s 400x224 \
-map_chapters -1:-1 -f ipod INPUT.mp4
When i read the INPUT.mp4 everything is OK with audio.
But when I use the Apple Segmenter (mediafilesegmenter) i have a descync between audio & video.
Is my command line is wrong ? or it's a Apple segmenter bug. The mediastreamvalidator show me :
WARNING: Media segment contains a video track but does not contain any IDR access unit with a SPS and a PPS
But i don't know if cause the audio desync.
I have the latest mediafilesegmenter download from connect.apple.com.

Resources