Convert PCM to AAC using PyAV - ffmpeg

I need to convert PCM (G.711U) audio to AAC in realtime. I've been able to do it with ffmpeg, but would like to use PyAV to have direct control and not have to run a separate process. What's the best way to do that?
cat input.raw | ffmpeg -hide_banner -f mulaw -ar 8000 -ac 1 -i - -c:a aac -f adts - > output.mp4
(NOTE: in the actually use case there aren't actual files for input.raw and output.mp4 and those are just streaming data but I did them to be able to show the example)

Related

ffmpeg from .mp3 to .al appears to slow and deepen the audio

I have an mp3 input file that is 22050Hz and 48kb/s. I need to convert it to a .al file in order to stream it to a camera on my network for output.
ffmpeg -i file.mp3 file.al
creates a file that does play but the bitrate of the output is 176kb/s and it clearly slower/deeper sounding. I have tried -b:a 48k and -filter:a without success but I could be doing it wrong.
Documentation states that this is the format I need: PCM ADPCM G.711A G.711.Mu G.726 G.729 MPEG2 AMR AAC
ffmpeg -i input.mp3 -ar 8000 -ac 1 -ab 64 output.al -ar 8000 -ac 1 -ab 64 -f mulaw
This has produced the correct result. Conversion is for playing audio over an Amcrest camera speaker.

ffmpeg how to record and preview at the same time

I want to capture video+audio from directshow device like webcam and stream it to RTMP server. This part no problem. But the problem is that I want to be able to see the preview of it. After a lot of search someone said pipe the input using tee muxer to ffplay. but I couldn't make it work. Here is my code for streaming to rtmp server. how should I change it?
ffmpeg -rtbufsize 8196k -framerate 25 -f dshow -i video="Microsoft® LifeCam Studio(TM)":audio="Desktop Microphone (Microsoft® LifeCam Studio(TM))" -vcodec libx264 -acodec aac -strict -2 -b:v 1024k -b:a 128k -ar 48000 -s 720x576 -f flv "rtmp://ip-address-of-my-server/live/out"
Here is the final code I used and it works.
ffmpeg -rtbufsize 8196k -framerate 25 -f dshow -i video="Microsoft® LifeCam Studio(TM)":audio="Desktop Microphone (Microsoft® LifeCam Studio(TM))" -vcodec libx264 -acodec aac -strict -2 -f tee -map 0:v -map 0:a "[f=flv]rtmp://ip-address-and-path|[f=nut]pipe:" | ffplay pipe:
The core command for those running ffmpeg on a Unix-compatible system (e.g. MacOS, BSD and GNU-Linux) is really quite simple. It's to redirect or to "pipe" one of the outputs of ffmpeg to ffplay. The main problem here is that ffmpeg cannot autodetect the media format (or container) if the output doesn't have a recognizable file extension such as .avi or .mkv.
Therefore you should specify the format with the option -f. You can list the available choices for option -f with the ffmpeg -formats command.
In the following GNU/Linux command example, we record from an input source named /dev/video0 (possibly a webcam). The input source can also be a regular file.
ffmpeg -i /dev/video0 -f matroska - filename.mkv | ffplay -i -
A less ambiguous way of writing this for non-Unix users would be to use the special output specifier pipe.
ffmpeg -i /dev/video0 -f matroska pipe:1 filename.mkv | ffplay -i pipe:0
The above commands should be enough to produce a preview. But to make sure that you get the video and audio quality you want, you also need to specify, among other things, the audio and video codecs.
ffmpeg -i /dev/video -c:v copy -c:a copy -f matroska - filename.mkv | ffplay -i -
If you choose a slow codec like Google's AV1, you'd still get a preview, but one that stutters.

Getting the original video quality while converting in ffmpeg

In my site, having upload video(only mp4 videos) functionality and then to combine. For the combining i used Mp4Box, If we want combine all the mp4 video, those videos have to same dimesions,bitrate,codecs,samplerate,etc, So while uploading the mp4 videos itself we set the constant dimension and other details like
ffmpeg -i test.mp4 -r 25 -s 640x360 -ar 48000 -acodec copy -f mp4 -vcodec libx264 -vpre default -async 1 -strict -2 -qscale 10 test.mp4
After using this command the video quality will loss fro the original video, Kindly suggest any solution?
Add
-qp 0
§ Lossless H.264

Lossless ffmpeg conversion/encoding

I'm looking for the best in quality when converting videos.
I only want to use lossless audio and video encoders and a good container.
How do I enable lossless x264 vcodec for ffmpeg?
I currently use ffmpeg -i "inputvideo" -s 1280x720 -ar 48000 -threads 4 -vcodec libx264 -acodec copy -dsur_mode 2 -ac 6 "outputvideo720p.mkv"
I plan on using flac for the acodec by am unsure because I don't want to use quality if it switches to 16-bit instead of 24-bit
You can use x264 in lossless manner I think. As in here and here use these flags for ffmpeg:
ffmpeg -i input.avi -c:v libx264 -qp 0 output.mkv
In case you couldn't load libx264, remove ffmpeg and install from source with x264 enabled. Here is how to.

FMS FLV to mp3/aac/wav

How can I decode a FLV's audio if it's recorded from a live stream using Flash Media Server and uses NellyMoser codec?
I'm writing a script that process several FLVs, using FFmpeg, so I need a command line solution.
Any ideas?
This should work for you, since NellyMoser is supported by FFmpeg.
1. Using mp3
ffmpeg -i yourinput.flv -vn -acodec libmp3lame output.flv
2. Using AAC (switch aac with libfaac depending on which you have loaded)
ffmpeg -i yourinput.flv -vn -acodec libfaac output.mp4
I'm assuming of course you dont care about video.

Resources