How to improve FFmpeg - advanced version

1. Introduction to FFmpeg

FFmpeg is a free, open-source, cross-platform audio and video processing tool designed to provide high-quality, high-speed multimedia processing. FFmpeg is designed to stream audio and video.

FFmpeg has become one of the most powerful and comprehensive audio and video processing tools recognized in the industry, and has been widely used. Most audio and video related applications and tool libraries directly or indirectly refer to FFmpeg.

The development of FFmpeg began in 2000, initially initiated by French programmer Fabrice Bellard, and later more and more open source contributors participated. Currently FFmpeg is maintained and developed by a team of several developers.

2. ffmpeg author and team

Fabrice Bellard is a famous French computer programmer, known in the industry for founding FFmpeg, QEMU and other projects.

His profile website is bellard.org/.

It lists several projects he created. He has a wide range of interests and has dabbled in many different fields, making him a true master of programming.

3. Basic commands

Here are some basic commands of FFmpeg:

1. Transcoding: Convert an audio and video file from one format to another. For example, to convert an MP4 file to an AVI file use the following command:

ffmpeg -i input.mp4 output.avi

In this command, "-i" means the input file, "input.mp4" is the name of the input file, and "output.avi" is the name of the output file. FFmpeg automatically detects the format of the input file, so you don't need to specify the format of the input file.

2. Trimming: to intercept a part of an audio and video file. For example, to capture the first 10 seconds of an MP4 file, use the following command:

ffmpeg -i input.mp4 -ss 00:00:00 -t 00:00:10 -c copy output.mp4

In this command, "-ss" means the start time, "00:00:00" is the timestamp of the start time, "-t" means the duration, and "00:00:10" is the timestamp of the duration , "-c copy" means to save the cut part as a new file without re-encoding. If you need to re-encode the cut part, you can use the following command:

ffmpeg -i input.mp4 -ss 00:00:00 -t 00:00:10 -c:v libx264 -c:a aac output.mp4

In this command, "-c:v libx264" means to encode video with H.264 encoder, and "-c:a aac" means to encode audio with AAC encoder.

 [Learning address]: Advanced development of FFmpeg/WebRTC/RTMP/NDK/Android audio and video streaming media
[Article Benefits]: Receive more audio and video learning materials packages, Dachang interview questions, technical videos and learning roadmaps for free, including ( C/C++, Linux, FFmpeg webRTC rtmp hls rtsp ffplay srs, etc.) If you need it, you can click 1079654574 to join the group to receive it~

3. Resizing: Adjust the size of audio and video files. For example, to resize an MP4 file to have a width of 640 pixels use the following command:

ffmpeg -i input.mp4 -vf scale=640:-1 output.mp4

In this command, "-vf scale=640:-1" means to use the scale filter to adjust the video, "640" is the target width, and "-1" means to automatically calculate the target height based on the target width.

4. Frame rate conversion: Adjust the frame rate of audio and video files. For example, to adjust the frame rate of an MP4 file to 30 frames, you can use the following command:

ffmpeg -i input.mp4 -r 30 output.mp4

In this command, "-r 30" means to set the frame rate of the output file to 30 frames.

5. Extracting audio: Extracting audio files from a video file. For example, to extract audio from an MP4 file use the following command:

ffmpeg -i input.mp4 -vn -acodec copy output.aac

In this command, "-vn" means don't output the video, and "-acodec copy" means copy the audio stream to a new file without re-encoding.

6. Adding watermark (Adding watermark): Add a picture as a watermark to the video. For example, to add a PNG image as a watermark to an MP4 file use the following command:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output.mp4

In this command, "-i watermark.png" means to input watermark image, "-filter_complex" means to use complex filter, "overlay=10:10" means to place watermark on the upper left corner of the video.

4. Advanced FFmpeg6.0

4.1 FFmpeg filters

  1. FFmpeg filter chain framework

  2. Audio Filter Framework

  3. Video Filter Framework

  4. multi-channel audio mixing amix

  5. Video watermark watermark

  6. Video area cropping and flipping

  7. video add logo

Note: filter is widely used in the field of video editing.

4.2 ffplay player

  1. Master the meaning of ffplay.c

  2. ffplay framework analysis

  3. demultiplexing thread

  4. audio decoding thread

  5. video decoding thread

  6. sound output callback

  7. Screen Rendering Interval

  8. audio resampling

  9. Screen size format conversion

  10. Differences between audio, video, and external clock synchronization

  11. Audio resampling compensation when referencing video

  12. The essence of volume mute and size adjustment

  13. Audio and video packet queue size limit

  14. Audio and video packet queue thread safety

  15. Audio and video frame queue size limit

  16. Audio and video frame queue thread safety

  17. Pause, play implementation mechanism

  18. Screen stuck problem caused by seek playback

  19. seek playback data queue, synchronous clock processing

  20. How to play frame by frame

  21. Key points of the process of player exit

Note: ffplay.c is the source code of the ffplay command, mastering ffplay will help us develop our own player with twice the result with half the effort.

5. Summary

FFmpeg is a powerful audio and video processing tool that can process audio and video files in various formats. It is a set of open source computer programs that can be used to record, convert digital audio and video, and convert them into streams.

Guess you like

Origin blog.csdn.net/irainsa/article/details/130693083