📜  ffmpeg whatsapp 或电报格式 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:41:10.691000             🧑  作者: Mango

ffmpeg WhatsApp or Telegram Format - Shell-Bash

Introduction

In this tutorial, we will explore how to use FFmpeg to convert audio or video files into a specific format for sharing on WhatsApp or Telegram. FFmpeg is a powerful command-line tool for manipulating multimedia files, and it supports a wide range of formats and codecs.

We will focus on converting files into formats that are commonly supported by WhatsApp and Telegram, such as MP4 for video and MP3 for audio. The conversion process will be done using Shell/Bash scripting, which provides a convenient way to automate the task.

Prerequisites

Before getting started, make sure you have the following prerequisites:

  • FFmpeg installed on your system (installation guide)
  • Basic knowledge of Shell/Bash scripting
Steps
  1. Check FFmpeg Version

    ffmpeg -version
    
  2. Convert Video to MP4 format

    ffmpeg -i input_video.avi -c:v libx264 -preset slow -crf 22 -c:a aac -b:a 128k output_video.mp4
    

    Explanation:

    • -i input_video.avi: Specifies the input video file name.
    • -c:v libx264: Sets the video codec to H.264 (x264) for encoding.
    • -preset slow: Selects a slower encoding preset to improve video quality.
    • -crf 22: Sets Constant Rate Factor (CRF) for video quality. Lower values result in better quality, but larger file sizes.
    • -c:a aac: Sets the audio codec to AAC for encoding.
    • -b:a 128k: Sets the audio bitrate to 128kbps.
    • output_video.mp4: Specifies the output video file name.
  3. Convert Audio to MP3 format

    ffmpeg -i input_audio.wav -c:a libmp3lame -b:a 192k output_audio.mp3
    

    Explanation:

    • -i input_audio.wav: Specifies the input audio file name.
    • -c:a libmp3lame: Sets the audio codec to MP3 (LAME) for encoding.
    • -b:a 192k: Sets the audio bitrate to 192kbps.
    • output_audio.mp3: Specifies the output audio file name.
  4. Result The converted files (output_video.mp4 and output_audio.mp3) can now be shared on WhatsApp or Telegram.

Conclusion

By following the above steps, you can easily convert audio or video files into formats suitable for sharing on WhatsApp or Telegram using FFmpeg and Shell/Bash scripting. FFmpeg provides various options and settings to customize the conversion process according to your requirements. Feel free to explore the FFmpeg documentation for more advanced features and options.