Audio and video] 5.ffmpeg Classification and use the command

GT
fact, usually there are some audio and video processing of personal or family needs, then do not be familiar with ffmpeg illustrated by means of software, you can get a basic command

G: ffmpeg command skilled use!
T: Do not rote, read, and found himself under the law, knock again, with more, naturally remember. Even forget, I can look it up _

ffmpeg command line tools provided by
ffprobe: as an information query, view audio and video files
ffplay: is a use of FFmpeg and SDL library media player, ijkplayer ffplay is based on the transformation of secondary development, do some hardware work decoding and compatibility.
ffmpeg: The most important, most central. Contains a variety of functions, learning is mainly to learn this stuff.
ffserver: simple streaming media server, in response to client requests the streaming media data stream and sent to the client.
ffprobe
ffprobe [fileName]: direct output file information, obviously, we can see what it represents

# Long, start, bit rate
the Duration: 00: 01: 39.96, Start: 0.000000, bitrate: 1035 kB / S

# Video stream, the encoding format H264 (encapsulation format AVC1), video frame format YUV420P, resolution of 1000x562, the bit rate , frame rate, default represents the default stream, there may be multiple video streams.
Stream # 0: 0 (und) : Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1000x562 [SAR 1: 1 DAR 500: 281], 935 kb / s, 24 fps, 24 tbr, 12288 tbn, 48 TBC (default)

# audio streams, AAC encoding format (MP4A and encapsulation format), the LC Profile is employed, the sampling rate 44.1kHZ, stereo sound, data representing floating-point format, the bit rate of
stream # 0: 1 (und) : audio: AAC (the LC) (MP4A / 0x6134706D), 44100 Hz, Stereo, fltp, 94 kB / S (default)
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
ffprobe -show_format [fileName]

ffprobe -show_packets [fileName]

ffprobe -show_frames [fileName]

ffprobe -print_format json -show_streams [fileName]

Attribute Meaning
type (a, v, subtitles, etc.) media_type frame
pict_type frame type (IPB)
image color format pic_fmt frame (YUV420P)
Key_frame whether keyframes
ffplay
player: ffplay [fileName]
directly play the file, the player will also print tone video stream information, see the above by ffprobe to coincide
1.seek: click playback window
2. fast forward and rewind: left and right keys 10s, 1min down keys
3. audio and video switching: W is
4.frame-STEP: S

Loop: ffplay [fileName] -loop [times]

Switching audio and video streams: ffplay [fileName] ast / vst [index]

Nude broadcast audio and video data the PCM / the YUV:
ffplay .PCM -f s161e -channels 2 -Ar 44100
ffplay -f rawvideo as well -pixel_format YUV420P / RGB24 -s * 1920 1080 [fileName]

Audio and video synchronization to audio / video / external clock reference
ffplay [fileName] -sync audio / video / ext

ffmpeg: the most delicious fish, is the most prickly.
ffmpeg -help: can test the following types of parameters
# 1.Global options take effect globally, not only for individual files
# 2.Per-file main options: the operation of each file individually into force
-f fmt specified audio and video formats
-c codec name CODEC
-codec CODEC CODEC name
-pre PRESET PRESET name
-map_metadata outfile [, Metadata]: INFILE [, Metadata] SET Metadata Information of outfile from INFILE
when -t duration specified length
-to time_stop STOP Record time in transcode or
-fs limit_size specified file Maximum size of
-ss time_off specify the start time
-sseof time_off the SET at the start time offset relative to EOF
-seek_timestamp enable / disable Regularly Seeking by timestamp with -ss
-timestamp the SET at the Recording time timestamp ( 'now' to the SET at the Current time)
-metadata string = string add metadata
-program title=string:st=number... add program with specified streams
-target type specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")
-apad audio pad
-frames number set the number of frames to output
-filter filter_graph set stream filtergraph
-filter_script filename read stream filtergraph description from a file
-reinit_filter reinit filtergraph on input parameter changes
-discard discard
-disposition disposition

# 3. Video options: 视频参数
-vframes number set the number of video frames to output
-r rate 帧率fps
-s size 分辨率
-aspect aspect 指定视频长宽比(4:3,16:9或1.3333,1.7777)
The Number of Number SET -bits_per_raw_sample bits per RAW Sample
-vn cancel the video output
-vcodec enforce codec codec codec ( 'copy' representatives without re-encoding)
-timecode HH: mm: SS [:;.] FF SET TimeCode value Initial.
-pass The n-SELECT Pass Number (. 1 to. 3)
-vf filter_graph SET Video Filters
-ab bitrate Audio bitrate (Please use -b: A)
-b bitrate Video bitrate (Please use -b: V)
-dn Data disable

# 4. audio Options: audio parameters
-aframes number number of audio Frames The sET to Output
-aq quality audio quality provided (designated coding)
-Ar rate set audio sampling rate (in Hz)
-ac channels provided a number of channels mono 2 stereo
-an audio cancellation output
-acodec codec specified audio coding ( 'copy' refers to audio transcoding is not directly copied)
-VOL volume set record volume (256 = normal)
-af filter_graph set audio filters

# 5. Subtitle options
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
查询类命令
-version show version
-buildconf show build configuration
-formats show available formats
-muxers show available muxers
-demuxers show available demuxers
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
-hwaccels show available HW acceleration methods

命令格式
ffmpeg [global_options] {[input_file_options] -i input_url} {[output_file_options] output_url}

Multiplexing and demultiplexing order
to extract the audio stream
ffmpeg -i input.mp4 -acodec copy -vn out.aac

Extracting video stream
ffmpeg -i input.mp4 -vcodec copy -an out.h264

Format conversion
ffmpeg -i input.mp4 -vcodec copy -acodec copy out.flv

Audio and video merge
ffmpeg -i out.h264 -i out.aac -vcodec copy -acodec copy out.mp4

Data processing bare
# YUV data extraction
ffmpeg -i input.mp4 -an -c: v rawvideo -pixel_format yuv420p out.yuv

# Extracts the PCM data
ffmpeg -i input.mp5 -vn -ar 44100 -ac 2 -f s16le out.pcm

#yuv转h264
ffmpeg -f rawvideo -pix_fmt yuv420p -s 320x240 -r 30 -i out.yuv -c:v libx264 -f rawvideo out.h264

#pcm转wav
ffmpeg -s16le -ar 8000 -ac 2 -acodec pcm_s16le -i input.raw output.wav

Filter
# Add watermark: -vf in the movie logo specified location. scale specified logo size. logo overlay display the location specified
ffmpeg -i 1.mp4 -vf "movie = 2.png , scale = 30: 30 [watermask]; [in] [watermask] overlay = 30: 10 [out]" water.mp4

# Remove the watermark
1. watermark is found
ffplay -i water.mp4 -vf delogo = X = 30: Y = 10: W = 32: H = 31 is: Show. 1 =
2. remove the watermark
ffmpeg -i water.mp4 -vf delogo = x = 30: y = 10: w = 32: h = 31output.mp4

Video # 1 fold reduction: -vf scale Specifies a simple filter scale, iw / 2: -1 iw specified width of the video taken by the integer. -1 represents a height variation along with the width.
ffmpeg -i 1.mp4 -vf scale = iw / 2: -1 scale.mp4

Video cropping
crop format: crop = out_w: out_h: X: Y
out_w: width of the output. In_w width may be used tabular input video.
out_h: height output. You may be used highly in_h tabular input video.
x: X-coordinate
y: Y-coordinate
ffmpeg -i 1.mp4 -vf crop = in_w- 200: -c in_h-200: v libx264 -c: a copy -video_size 1280x720 out.mp4

Speed playback
-filter_complex complex filter, [0: v] represents a (file index number is 0) of a video file as input. setpts = 0.5PTS stamp each frame of video showing pts are multiplied by 0.5, which is less than half the difference. [v] represents an alias output. Similarly the audio is not detailed.
-map complex output can be used, as can be multiplexed stream is output to a specified output file may be output to a plurality of specified files. "[v]" alias filter output as a complex way to the output file stream. Usage map above is complex filters video and audio output to the specified output file.
ffmpeg -i 1.mp4 -filter_complex "[0: v] setpts = 0.5PTS [v]; [0: a] atempo = 2.0 [a]" -map "[v]" -map "[a]" speed. mp4

Symmetric video (horizontal flip)
FFmpeg -i 1.mp4 -filter_complex "[0: V] = PAD IW W = 2 * [A]; [0: V] hflip [B]; [A] [B] = X overlay = w "duicheng.mp4

Video symmetry (vertical flip)
FFmpeg -i 1.mp4 -filter_complex "[0: V] PAD = H = 2 * the IH [A]; [0: V] vflip [B]; [A] [B] = Y overlay = h "duicheng.mp4

画中画
ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex “[1:v]scale=w=176:h=144:force_original_aspect_ratio=decrease[ckout];[0:v][ckout]overlay=x=W-w-10:y=0[out]” -map “[out]” -movflags faststart new.mp4

Volume effect
ffmpeg -i 1.mp4 -af 'volume = 0.5 ' out.mp4

Splicing and cutting audio and video
cropping
ffmpeg -i 1.mp4 -ss 00:00:00 -t 10 out1.mp4

Splicing
text file:
File 'out1.flv'
File 'out2.flv'
File 'out3.flv'
ffmpeg -f -c concat -i text Copy pinjie.mp4

hls slice
-strict -2 use in designating audio AAC.
-f hls turn into m3u8 format.
ffmpeg -i 1.mp4 -c: v libx264 -c : a libfdk_aac -strict -2 -f hls out.m3u8

Video picture system conversion
video to JPEG
-r 1: 1S a
ffmpeg -i 1.mp4 -r 1 -f image2 image- % 3d.jpeg

Pictures turn GIF
ffmpeg -i Image-% 3d.jpeg -r 5 out.gif

Gif video to FIG
ffmpeg -i 1.mp4 -ss 00:00:00 -t 10 out.gif

Image transfer video
ffmpeg -f image2 -i image-% 3d.jpeg images.mp4

Live-related
plug-flow
ffmpeg -re -i out.mp4 -c copy -f flv rtmp: // server / live / streamName

拉流保存
ffmpeg -i rtmp://server/live/streamName -c copy dump.flv

转流
ffmpeg -i rtmp://server/live/originalStream -c:a copy -c:v copy -f flv rtmp://server/live/h264Stream

Limited, abilities, and in the learning stage, to record their own blog about learning, it is inevitable that differences in understanding, correct me welcome message!
Cease to learn endless!
--------------------- 

Guess you like

Origin www.cnblogs.com/hyhy904/p/10983107.html