Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
FFmpeg is a powerful multimedia framework that can decode, encode, transcode, mux, demux, stream, filter, and play almost anything that humans and machines have created. It's particularly useful on a Raspberry Pi for tasks such as converting video formats, streaming video, and capturing video from a camera.
Before you can start using FFmpeg, you need to install it on your Raspberry Pi. Follow these steps to get started:
Update your system: Open a terminal on your Raspberry Pi and update your package list with the following command:
sudo apt update && sudo apt upgrade -y
Install FFmpeg: Install FFmpeg using the package manager:
sudo apt install ffmpeg -y
Suppose you have a video file in MKV format and you want to convert it to MP4. Use the following command:
ffmpeg -i input_video.mkv -codec copy output_video.mp4
This command specifies the input file input_video.mkv
and the output file output_video.mp4
while copying the codec to avoid re-encoding.
If you have a Raspberry Pi camera module, you can stream video over your local network using FFmpeg. First, ensure you have raspivid
installed, which is the camera capture utility for Raspberry Pi.
Use the following command to stream video:
raspivid -o - -t 0 -n -w 640 -h 480 -fps 25 | ffmpeg -re -ar 44100 -ac 2 -f s16le -acodec pcm_s16le -i /dev/zero -f h264 -i - -vcodec copy -f flv rtmp://your_streaming_server/live/stream_key
This command captures video from the camera and streams it to an RTMP server. Replace your_streaming_server/live/stream_key
with your actual streaming server URL and stream key.
To extract audio from a video file and save it as an MP3, use the following command:
ffmpeg -i input_video.mp4 -q:a 0 -map a output_audio.mp3
This command takes input_video.mp4
and extracts the audio track to output_audio.mp3
.
The Raspberry Pi has limited resources compared to a full-fledged PC, so it's important to optimize FFmpeg usage:
h264_omx
codec for encoding H.264 video to leverage the onboard GPU.