Software and Hardware Environment

  • windows 10 64bit
  • Ffmpeg 3.4.8

Download and Installation

Download the compiled binary file from the official website ffmpeg.org/download.ht… And add its path to the system environment variable

Get audio/video file information

To display information about the media file, run ffmpeg -i test.mp4

(base) PS C:\Users\Administrator\Desktop> ffmpeg.exe -i .\test.mp4 ffmpeg version N-93125-gdbfd042983 Copyright (c) 2000-2019 The FFmpeg Developers Built with GCC 8.2.1 (GCC) 20190212 Configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56.26.100/56.26.100 libavcodec 58.47.100/58. 47.100 libavformat 58.26.101/58.26.101 libavDevice 58.6.101/58.6.101 libavfilter 7.48.100/7.48.100 Libswscale 5.4.100/5.4.100 libswresample 3.4.100/3.4.100 libpostproc 55.4.100/55.4.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\test.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: Encoder: Lavf57.83.100 Duration: 00:01:08.40, start: 0.000000, bitrate: 5947 KB /s Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5945 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default) Metadata: handler_name : VideoHandler At least one output file must be specified (base) PS C:\Users\Administrator\Desktop>Copy the code

You can see information about the media file in the output above, as well as ffMPEG information such as version, configuration details, copyright tags, build parameters, library options, and so on

Converting video formats

Convert mp4 to AVI

ffmpeg -i test.mp4 test.avi
Copy the code

Video capture

From the 10th second of the video, the video with a length of 30 seconds is intercepted, and the encoding method is maintained unchanged

ffmpeg -ss 00:00:10 -t 00:00:30 -i test.mp4 -vcodec copy -acodec copy output.mp4
Copy the code

Video stitching

Use a TXT file to organize the video files that need to be spliced together. The format is

file 'test1.mp4'
file 'test2.mp4'
file 'test3.mp4'
Copy the code

With the text file above, you can concatenate using ffmpeg, the command is

ffmpeg -f concat -i filelist.txt -v:c copy output.mp4
Copy the code

Change the resolution of the video

Change the resolution in the original video to 1280×720, and the audio encoding method remains unchanged

ffmpeg -i test.mp4 -filter:v scale=1280:720 -c:a copy output.mp4
Copy the code

If you want to change the scale of the video, you can do this

ffmpeg -i test.mp4 -vf scale=1280x720,setdar=16:9 output.mp4
Copy the code

Change the way audio and video are encoded

That’s transcoding, you can specify the encoding

ffmpeg -i test.avi -c:v libx264 -c:a aac output.mp4
Copy the code

Extract the audio from the video

Use the -vn parameter to disable video

ffmpeg -i test.mp4 -vn test.mp3
Copy the code

Alternatively, if you want to remove audio, use the -an parameter

ffmpeg -i test.mp4 -an output.mp4
Copy the code

Extract the image

ffmpeg -i test.mp4 -r 1 -f image2 image_%2d.png
Copy the code

-r indicates the frame speed, and -r 1 means to extract an image per second. The extracted images are named image_01. PNG, image_02.png, image_03.png, and so on

M3u8 slice

M3u8 is great for playing over the network and FFMPEG can convert local video files into a combination of M3U8 index plus TS video. In this way, you can simply copy the generated files to a Web service like Nginx and achieve voD

ffmpeg -i test.mp4 -vcodec libx264 -strict -2 -acodec aac -hls_list_size 0 -f hls index.m3u8
Copy the code

Adjust the video playback speed

The following example is a double speed conversion, with setpts=2*PTS if the speed is 1/2 of the original

Ffmpeg-i test.mp4-vf "setpts=0.5*PTS" output.mp4Copy the code

Edit video

You can modify original_network_id, transport_stream_id, and service_id. Streamid stands for audio and video PID. You can modify video PID and audio PID

ffmpeg -i test.mp4 -vcodec libx264 -strict -2 -acodec aac -streamid 1:2595 -
mpegts_original_network_id 0x1122 -mpegts_transport_stream_id 0x3344 -
mpegts_service_id 0x02 -mpegts_pmt_start_pid 0x0A20 -mpegts_start_pid
0x0A21 -metadata service_provider="yakir" -metadata service_name="yakir"
-bsf h264_mp4toannexb -f mpegts output.ts
Copy the code

Ask for help

Finally released the ultimate big trick, super detailed official help information

ffmpeg -h full
Copy the code