Vx Search for “gjZKeyFrame” Follow “Keyframe Keyframe” to get the latest audio and video technical articles in time.

(Basic logic of this article: FFmPEG common command introduction → FFplay common command introduction → FFprobe common command introduction)

Almost every programmer in audio and video development should know or have used FFmpeg. FFmpeg is open source software under the LGPL or GPL license (note the open source license here, which is “contagious” and requires its users to be open source as well). We can use FFmpeg to record, convert and stream audio and video in a variety of formats.

FFmpeg consists of several components, including command line applications and a series of function libraries:

  • Command line application:

  • Ffmpeg: used for audio and video codec, format conversion and audio and video stream content processing.

  • Ffplay: a player based on SDL and FFMPEG libraries.

  • Ffprobe: audio and video analysis tool.

  • Libraries:

  • Libavcodec: codec library.

  • Libavformat: Encapsulates and resolves the audio and video container format and supported protocols.

  • Libavutil: Provides a library of public functions and utilities.

  • Libavfilter: a library of audio and video filters, such as video watermarking and audio changes.

  • Libavdevice: Supports input and output of various device data, such as camera data reading and screen recording.

  • Libswresample, libavresample: provides libraries of audio resampling tools.

  • Libswscale: Provides color conversion, scaling, and pixel format conversion for video images, such as YUV conversion for images.

  • Libpostproc: multimedia post-processor.

If you use a Mac device, you can install FFmpeg on a Mac using Homebrew:

$ brew install ffmpeg
Copy the code

The details of installing Homebrew and using it to install FFMPEG are not covered here.

This article focuses on the use of the FFmpeg command line application, which is an essential tool in audio and video development.

1, FFmpeg command line tool

Ffmpeg is an audio and video codec, format conversion and audio and video streaming content processing tool.

1.1 basic skills

To view the capabilities supported by the current FFMPEG tool, run the following command:

$FFmPEG-help // Supported formats $FFmPEG-decoders // Supported encoders $FFmPEG-encoders // Supported protocols $FFmPEG -protocolsCopy the code

1.2. Transfer to packaging

The following commands can be used to convert encapsulation:

$ffmpeg -i < input file path > -c copy -f < output file path >Copy the code

1) turn to MP4

MP4 is the most commonly used package format for short videos today. For more details on the MP4 format, see MP4 Format.

FFmpeg Package MP4

Example: Convert FLV files to MP4 and move the Moov box to the file header.

$ ffmpeg -i input.flv -c copy -f mp4 -movflags faststart output.mp4
Copy the code

2) turn FLV

FLV is currently the most commonly used encapsulation format for live streaming. For more detailed introduction of FLV format, see FLV Format.

FFmpeg package FLV common parameters:

Example: Encapsulate MP4 files into FLV.

$ ffmpeg -i input.mp4 -c copy -f flv output.flv
Copy the code

The audio encoding and video encoding that can be supported in FLV encapsulation is limited. In the process of encapsulation, if the audio or video does not meet the standard, an error will be reported. In general, we can transcode both audio and video to FLV supported formats while transpackaging.

Example: Package MP4 files into FLV and make sure audio is transcoded to AAC.

$ ffmpeg -i input.mp4 -vcodec copy -acodec aac -f flv output.flv
Copy the code

3) turn HLS

HLS is the most commonly used protocol for live playback and some live broadcast scenarios. Its corresponding media format is M3U8 + TS. For details about HLS, see HLS Protocol, M3U8 Format, and TS Format.

FFmpeg package HLS common parameters:

Example: Encapsulate MP4 files as HLS live.

$ ffmpeg -re -i input.mp4 -c copy -f hls -bsf:v h264_mp4toannexb output.m3u8
Copy the code

Because the default is HLS live, the content of the generated M3U8 file is updated as slices are generated. There is an additional -bSF :v h264_MP4TOAnnexb parameter, which converts the H.264 data in MP4 to the AnnexB standard of H.264, which is commonly used in real-time transmission streams. If the source file is FLV or TS that can be used as the live transmission stream, this parameter is not required.

  • re: Reads data at the local frame rate.
  • bsf: Binary Stream Filter.

4) Audio and video stream extraction

FFmpeg can extract audio and video streams in addition to encapsulation and transcoding.

Example: Extract AAC audio stream from MP4 file.

$ ffmpeg -i input.mp4 -vn -acodec copy output.aac
Copy the code
  • vn: indicates that no video is included.

Example: Extract H.264 video streams from an MP4 file.

$ ffmpeg -i input.mp4 -an -vcodec copy output.h264
Copy the code
  • an: indicates that audio is not included.

Example: Extract H.265 video stream from MP4 file.

$ ffmpeg -i input.mp4 -an -vcodec copy -bsf hevc_mp4toannexb -f hevc output.hevc
Copy the code

1.3, transcoding

FFmpeg generally uses libx264 for soft coding. Here are the encoding parameters related to X264:

1) the Preset

Example: Set preset to ultrafast for conversion.

$ ffmpeg -i input.mp4 -vcodec libx264 -preset ultrafast -b:v 2000k output.mp4
Copy the code
  • b:v: indicates the video output bit rate.

2) Profile

Example: Set profile to high for transcoding.

$ffmpeG-i input. Mp4 -vcodec libx264-profile :v high level 3.1-s 720x1280-an-y-t 10 output_high.tsCopy the code
  • y: overwrites output files.
  • s: indicates the output resolution.

The video encoded by main profile and High Profile can contain B frames. After transcoding, you can see:

$ ffprobe -v quiet -show_frames -select_streams v output_high.ts | grep "pict_type=B" | wc -l
Copy the code

3) the GOP

Example: Set GOP to 50 frames and do not insert keyframes during scene switch.

$ ffmpeg -i input.mp4 -c:v libx264 -g 50 -sc_threshold 0 -t 60 -y output.mp4
Copy the code
  • g: Sets the GOP size in frames.
  • sc_threshold: Sets whether to insert keyframes during scene switching. 0 indicates no insertion and 1 indicates insertion.

4) B frames

Due to the number of parameters to set x264, FFmpeg opens x264OPTS to set internal private parameters of X264.

Example: Set GOP to 50 frames, and no key frame is inserted during scene switch, and no B frame appears.

$ ffmpeg -i input.mp4 -c:v libx264 -x264opts "bframes=0" -g 50 -sc_threshold 0 -t 60 -y output.mp4
Copy the code

Example: Set GOP to 50 frames, no key frames are inserted during scene switching, and three B frames are stored between two P frames.

$ ffmpeg -i input.mp4 -c:v libx264 -x264opts "bframes=3:b-adapt=0" -g 50 -sc_threshold 0 -t 60 -y output.mp4
Copy the code

5) bit rate

VBR and CBR encoding modes can be set during encoding. VBR stands for variable bit rate and CBR stands for constant bit rate.

Example:

$ ffmpeg -i input.mp4 -c:v libx264 -x264opts "bframes=10:b-adapt=0" -b:v 1000k -maxrate 1000k -minrate 1000k -bufsize 50k -nal-hrd cbr -g 50 -sc_threshold 0 -t 60 -y output.ts
Copy the code

The command above is more complex and does these things:

  • -x264opts "bframes=10:b-adapt=0": Sets the number of B-frames to 10 B-frames between two P-frames.
  • -b:v 1000k: set the average video bit rate to 1000kbps.
  • -maxrate 1000k: sets the video maximum bit rate to 1000kbps.
  • -minrate 1000k: sets the minimum video bit rate to 1000kbps.
  • -bufsize 50k: Set the encoding buffer size to 50KB.
  • -nal-hrd cbr: Sets the encoding HRD signal format of H.264 to CBR.
  • -g 50: Set one GOP every 50 frames.
  • -sc_threshold 0: Sets scene switching without inserting key frames.

1.4 streaming media

1) Publish the RTMP stream

RTMP is the most commonly used streaming protocol for live streaming. For more details, see RTMP protocol.

FFmpeg RTMP live stream

Example: Local MP4 video files are converted to FLV and then streamed to the specified RTMP streaming media server.

$ ffmpeg -re -i input.mp4 -c copy -f flv rtmp://localhost:1935/live/room
Copy the code

2) Record the RTMP stream

Example: RTMP media stream saved as FLV video file.

$ ffmpeg -i rtmp://localhost:1935/live/room -c copy output.flv
Copy the code

3) Record the HTTP stream

Among streaming media services, HTTP is the most common, especially voD. Live streaming is also available, including HTTP-FLV, HTTP-TS, and HLS.

FFmpeg operation HTTP uses the following parameters:

Example: Pull and record a FLV live stream.

$ ffmpeg -i http://www.abc.com/live.flv -c copy -f flv output.flv
Copy the code

Example: Pull TS live stream to record as FLV.

$ ffmpeg -i http://www.abc.com/live.ts -c copy -f flv output.flv
Copy the code

Example: Pull an HLS live stream and record it as FLV.

$ ffmpeg -i http://www.abc.com/live.m3u8 -c copy -f flv output.flv
Copy the code

2. Ffplay command line tool

Ffplay is a player based on SDL and FFMPEG library, which can be used to play original YUV/PCM data, encoded H.264/H.265 data, encapsulated MP4/M4A data, or streaming media data.

1) Play the original sound data

$ffplay -f < format name > -ac < channel number > -ar < sample rate > -i < file path >Copy the code

Among them, the -f said PCM format, you can use ffmpeg – formats | grep PCM command to view the current supported formats.

Example:

$ ffplay -f f32le -ac 1 -ar 48000 -i input.pcm
Copy the code

2) Play the original image data

$ffplay -f < file format > -pixel_format > -video_size < video size > -i < file path >Copy the code

-pixel_format indicates the pixel format. You can run the ffplay -pix_fmts command to view the supported formats.

Example:

$ ffplay -f rawvideo -pixel_format yuv420p -video_size 1280x720 -i input.yuv
Copy the code

3) Play coded data

Use ffPlay to play the encoded video or audio file as follows:

$ffplay -i < file path >Copy the code

Example:

$ ffplay -i input.h264
Copy the code

4) Play encapsulated data

Use ffPlay to play the encapsulated video or audio file as follows:

$ffplay -i < file path >Copy the code

Example:

$ ffplay -i input.mp4
Copy the code

However, here are a few other features to keep an eye on:

4.1) Playback control

When playing audio or video, use the following keyboard keys to control playback:

  • w, switch playback mode, such as switching between audio waveform, audio spectrum, video screen.
  • sStep mode, play the next image frame every time you press.
  • rightFast forward 10 s.
  • leftFast back 10 s.
  • up, fast retreat for 1 min.
  • down, fast retreat for 1 min.
  • space, to suspend.
  • escTo exit.

4.2) Loop play

-loop specifies the number of cycles.

$ffplay -loop - I < file path >Copy the code

4.3) Play a certain audio or video

-ast and -vst are used to specify the audio stream number and video stream number respectively.

$ffplay - VST $ffplay - VST $ffplay - VST $ffplay - VSTCopy the code

If there is no audio stream or video stream with the corresponding number, mute or no screen.

4.4) Set audio and video synchronization mode

Run the -sync command to specify the audio and video synchronization mode.

$ffplay -sync -i < file path >Copy the code

There are three synchronization modes, including:

  • audio, based on the audio clock.
  • video, based on the video clock.
  • ext, has the external clock as the benchmark.

3. Ffprobe command line tool

Ffprobe is an executable generated by FFmpeg source code compilation. Ffprobe is a powerful multimedia analysis tool that can obtain audio, video and media container parameters from media files or streams.

1) View the media encapsulation information

Run the -show_format command to view media encapsulation information.

$ffprobe -show_format < file path >Copy the code

The following is an example of the output information and its parameter meanings:

[FORMAT]filename=http://www.example.com/1.flvnb_streams=2nb_programs=0format_name=flvformat_long_name=FLV (Flash Video) start_time = 4088.213000 duration = 0.000000 size = N/Abit_rate = N/Aprobe_score = 100 tag: fileSize = 0 tag: audiochannels = 2 tag: enc oder=xxx[/FORMAT]Copy the code
  • filename: File name.
  • nb_streams: Indicates the number of encapsulated streamsAVFormatContext->nb_streams.
  • nb_programs: the correspondingAVFormatContext->nb_programs.
  • format_name: Indicates the encapsulation formatAVFormatContext->iformat->name.
  • format_long_name: Indicates the full name of the encapsulation formatAVFormatContext->iformat->long_name.
  • start_time: Indicates the start timeAVFormatContext->start_timeBased on theAV_TIME_BASE_Q, in seconds.
  • duration: Indicates the durationAVFormatContext->durationBased on theAV_TIME_BASE_Q, in seconds.
  • size: Size, correspondingavio_size(AVFormatContext->pb), in bytes.
  • bit_rate: bit rate, correspondingAVFormatContext->bit_rate.
  • probe_score: indicates how the format of the input media file matches the actual data format, with higher matching scores (for example, 1.mp4 is really mp4) and lower matching scores (for example, 1.MP4 is actually WAV). The correspondingAVFormatContext->probe_score.
  • TAG:*: TAG is information processed from metadata dump.

2) Check media stream information

Use -show_streams to view media streams.

$ffprobe-show_streams < file path >Copy the code

The following is an example of the output information and its parameter meanings:

[STREAM]index=0codec_name=h264codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10profile=Highcodec_type=videocodec_time_base=1/30codec_tag_string=[0][0][0][0]codec_tag=0x0000width=720height=1280coded _width=720coded_height=1280has_b_frames=1sample_aspect_ratio=N/Adisplay_aspect_ratio=N/Apix_fmt=yuv420plevel=31color_ran ge=unknowncolor_space=unknowncolor_transfer=unknowncolor_primaries=unknownchroma_location=leftfield_order=progressivetim ecode=N/Arefs=1is_avc=truenal_length_size=4id=N/Ar_frame_rate=15/1avg_frame_rate=15/1time_base=1/1000start_pts=1030start _time duration_ts = N/Aduration = = 1.030000 N/Abit_rate = N/Amax_bit_rate = N / 8 nb_frames Abits_per_raw_sample = = N/Anb_read_frames = N / Anb_read_packets=N/ADISPOSITION:default=0DISPOSITION:dub=0DISPOSITION:original=0DISPOSITION:comment=0DISPOSITION:lyrics= 0DISPOSITION:karaoke=0DISPOSITION:forced=0DISPOSITION:hearing_impaired=0DISPOSITION:visual_impaired=0DISPOSITION:clean_e ffects=0DISPOSITION:attached_pic=0DISPOSITION:timed_thumbnails=0[/STREAM][STREAM]index=1codec_name=aaccodec_long_name=AA C (Advanced Audio Coding)profile=LCcodec_type=audiocodec_time_base=1/48000codec_tag_string=[0][0][0][0]codec_tag=0x0000sample_fmt=fltpsamp le_rate=48000channels=2channel_layout=stereobits_per_sample=0id=N/Ar_frame_rate=0/0avg_frame_rate=0/0time_base=1/1000sta Rt_pts = 55 start_time = 0.055000 duration_ts = N/Aduration = N/Abit_rate = N/Amax_bit_rate = N/Abits_per_raw_sample = N/Anb_frames = N/An b_read_frames=N/Anb_read_packets=N/ADISPOSITION:default=0DISPOSITION:dub=0DISPOSITION:original=0DISPOSITION:comment=0DIS POSITION:lyrics=0DISPOSITION:karaoke=0DISPOSITION:forced=0DISPOSITION:hearing_impaired=0DISPOSITION:visual_impaired=0DIS POSITION:clean_effects=0DISPOSITION:attached_pic=0DISPOSITION:timed_thumbnails=0[/STREAM]Copy the code

Video:

  • Index: the index number of the current stream, corresponding to AVStream->index.

  • Codec_name: decoder name, corresponding to AVCodecDescriptor * CD = avCodec_descriptor_get (AVStream-> codecPAR ->codec_id); CD – > name.

  • Codec_long_name: full decoder name, corresponding to CD ->long_name.

  • Profile: Encoding level, obtained by avCOdec_profile_name (AVStream-> coDECPAR ->codec_id, AVStream-> coDECPAR ->profile).

  • Codec_type: stream type, that is, av_get_mediA_type_string (AVStream-> coDECPAR ->codec_type).

  • Codec_time_base: The encoded timestamp calculation base unit, corresponding to AVStream->codec->time_base.

  • Codec_tag_string: encoder label description, corresponding to av_fourcc2str(AVStream-> coDECPAR -> coDEC_tag).

  • Codec_tag: corresponds to AVStream-> coDECPAR -> coDEC_tag.

  • Width: the width of the valid area, corresponding to AVStream-> codecPAR ->width.

  • Height: The height of the valid area, corresponding to AVStream-> codecPAR ->height.

  • Coded_width: Video frame width may be different with the width of the above, because there are some encoders require the number of frames of the width or height is a multiple, so if the input video frame the width or height is not in conformity with the corresponding rules, then you need to do to fill, coded_width here is the width after filling, when decoding need use this parameter to do the corresponding cutting. Corresponding AVStream – > codec – > coded_width.

  • Coded_height: The height of the video frame, which may be different from the above, corresponds to AVStream->codec->coded_height.

  • Has_b_frames: indicates whether B frames are contained.

  • Sample_aspect_ratio: SAR for short, refers to the ratio of horizontal points to vertical points in image collection. FFmpeg provides multiple SARS: AVStream->sample_aspect_ratio, AVStream-> codecPAR ->sample_aspect_ratio, AVFrame->sample_aspect_ratio, The final SAR is obtained by av_guess_sample_aspect_ratio.

  • Display_aspect_ratio: DAR for short, refers to the aspect ratio of the image that is actually displayed, which must be scaled when rendering the video. According to av_reduce calculation, PAR * SAR = DAR, where PAR is Pixel Aspect Ratio, indicating the Aspect Ratio of a single Pixel. In most cases, the Pixel Aspect Ratio is 1:1, that is, a square Pixel. If it is not 1:1, The pixel can be understood as a rectangle pixel.

  • Pix_fmt: Pixel format, corresponding to av_get_pix_FMt_name (AVStream-> codecPAR ->format).

  • Level: encoding parameter, corresponding to AVStream-> codecPAR ->level.

  • Color_range: Additional color space features for AV_COLOR_range_name (AVStream-> CODECPAR -> COLOR_range), AVCOL_RANGE_MPEG for TV, and AVCOL_RANGE_JPEG for PC.

  • Color_space: YUV color space type, corresponding to AV_COLOR_space_name (AVStream-> coDECPAR -> COLOR_space).

  • Color_transfer: color transfer feature, corresponding to AV_COLOR_transfer_name (AVStream-> CODECPAR -> COLOR_trC).

  • Color_primaries: corresponding AV_COLOR_primaries_name (AVStream-> CodecPAR -> COLOR_primaries).

  • Chroma_location: The location of the chroma sample, corresponding to av_chroma_location_name(AVStream-> codecPAR ->chroma_location).

  • Field_order: Interleaved the order of fields in the video, corresponding to AVStream-> codecPAR ->field_order.

  • Timecode: obtained by processing AVStream->codec->timecode_frame_start with av_timecode_make_mpeG_tc_string.

  • Refs: Refer to the number of frames, i.e. AVStream->codec->refs.

  • Is_avc: Indicates whether to enable AVC.

  • Nal_length_size: Indicates the length of the NALU in bytes.

  • Id:

  • R_frame_rate: The base frame rate of the current stream. This value is only a guess and corresponds to AVStream->r_frame_rate.

  • Avg_frame_rate: Average frame rate, corresponding to AVStream->avg_frame_rate.

  • Time_base: The time base of AVStream, that is, AVStream->time_base.

  • Start_pts: PTS timestamp at the start of the stream, based on time_base, i.e. AVStream->start_time.

  • Start_time: The start time after converting start_PTS * time_base, in seconds.

  • Duration_ts: Stream duration, based on time_base, i.e., AVStream->duration.

  • Duration: duration, in seconds, after duration_ts * time_base is converted.

  • Bit_rate: bit_rate, i.e. AVStream-> codecPAR ->bit_rate.

  • Max_bit_rate: the maximum bit rate, i.e. AVStream->codec->rc_max_rate.

  • Bits_per_raw_sample: The number of bits per sample or pixel, i.e. AVStream->codec->bits_per_raw_sample.

  • Nb_frames: The number of frames in a video stream, AVStream->nb_frames.

  • Nb_read_frames: slightly.

  • Nb_read_packets: slightly.

  • TAG:* : corresponds to information in AVStream->metadata.

  • TAG: Rotate: anticlockwise rotation (equivalent to the anticlockwise rotation of a normal video).

  • Side_data: In a video stream, we sometimes see side_data, which corresponds to AVStream->side_data, as shown in the following example:

[SIDE_DATA]// SIDE_DATA data type, Display Matrix represents a 3*3 Matrix, which needs to be applied to the decoded video frame to Display properly: side_data_type=Display Matrixdisplaymatrix=00000000: 0 65536 000000001: -65536 0 000000002: Rotation =-90[/SIDE_DATA]Copy the code

The audio stream:

  • sample_fmt: Sampling format, passav_get_sample_fmt_name(AVStream->codecpar->format)To obtain.
  • sample_rate: Sampling rate, i.eAVStream->codecpar->sample_rate.
  • channels: Number of channels, that isAVStream->codecpar->channels.
  • channel_layout: Channel type, andchannelsTheta corresponds to thetaav_bprint_channel_layoutObtain, for example, mono for mono and STEREO for multichannel.

3) View media packet information

Use -show_streams to view media packet information.

$ffprobe-show_packets < file path >Copy the code

The following is an example of the output information and its parameter meanings:

[PACKET] codec_type = audiostream_index = 0 PTS = 1690083 pts_time = 1690.083000 DTS = 1690083 dts_time = 23 duration_ duration = 1690.083000 Time = 0.023000 convergence_duration = N/Aconvergence_duration_time = N/Asize = 470 pos = 2757652 flags = K_ [/ PACKET] [PACKET] codec_type = videostream_index = 1 PTS = 1690232 pts_time DTS = 1690099 dts_time = = 1690.232000 1690.099000 duration = 33 duration_time conve = 0.033000 rgence_duration=N/Aconvergence_duration_time=N/Asize=11253pos=2758139flags=__[/PACKET]Copy the code
  • codec_type: Frame type. A. audio B. video C. audio D. video
  • stream_index: Index of the stream to which the current frame belongs, corresponding toAVStream->index.
  • pts: Display time stamp of the frame, i.eAVPacket->ptsBased on theAVStream->time_baseTime baseline.
  • pts_time: transformpts * time_baseThe time after that, in seconds.
  • dts: Frame decoding timestamp, that isAVPacket->dtsBased on theAVStream->time_baseTime baseline.
  • dts_time: transformdts * time_baseThe time after that, in seconds.
  • duration: Duration of the current frame, equal to PTS of the next frame minus PTS of the current frame, i.eAVPacket->durationBased on theAVStream->time_baseTime baseline.
  • duration_time: transformduration * time_baseThe time after that, in seconds.
  • convergence_duration: a little.
  • convergence_duration_time: a little.
  • size: Size of the current frame.
  • pos: The position of the current frame, equal to the pos of the previous frame plus the size of the current frame.
  • flags: a little.

4) View the media frame information

Use -show_frames to view media frame information.

$ffprobe -show_frames < file path >Copy the code

The following is an example of the output information and its parameter meanings:

[FRAME] media_type = 1 key_frame videostream_index = = 0 2084699 pkt_pts_time pkt_pts = = 2084.699000 pkt_dts pkt_dts_time = 2084699 = 2084. 699000 best_effort_timestamp = 2084699 best_effort_timestamp_time = 2084.699000 pkt_duration = 33 pkt_duration_time pkt_po = 0.033000 s=3751477pkt_size=2665width=720height=1280pix_fmt=yuv420psample_aspect_ratio=N/Apict_type=Bcoded_picture_number=334displ ay_picture_number=0interlaced_frame=0top_field_first=0repeat_pict=0color_range=unknowncolor_space=unknowncolor_primaries =unknowncolor_transfer=unknownchroma_location=left[/FRAME][FRAME]media_type=audiostream_index=0key_frame=1pkt_pts=208470 7 pkt_pts_time = 2084.707000 pkt_dts = 2084707 pkt_dts_time best_effort_timestamp = 2084707 best_effort_timestamp_time = = 2084.707000 2084.707000 23 pkt_duration_time pkt_duration = = 0.023000 pkt_pos = 3775354 472 sample_fmt pkt_size = = fltpnb_samples = 1024 channels = 2 c hannel_layout=stereo[/FRAME]Copy the code

Video frame:

  • media_type=: Frame type, that isav_get_media_type_string(AVStream->codecpar->codec_type).
  • stream_index: Index of the stream to which the current frame belongs, corresponding toAVStream->index.
  • key_frame: Indicates whether keyframe (IDR) is enabled.
  • pkt_pts: Display time stamp of the frame, i.eAVFrame->ptsBased on theAVStream->time_baseTime baseline.
  • pkt_pts_time: transformpkt_pts * time_baseThe time after that, in seconds.
  • pkt_dts: Frame decoding timestamp, that isAVFrame->dtsBased on theAVStream->time_baseTime baseline.
  • pkt_dts_time: transformpkt_dts * time_baseThe time after that, in seconds.
  • best_effort_timestamp: Frame timestamp, basically the same as PTS. If the current PTS has an unreasonable value, a series of calibrations will be attempted to obtain a more reasonable value, corresponding toAVFrame->best_effort_timestampBased on theAVStream->time_baseTime baseline.
  • best_effort_timestamp_time: transformbest_effort_timestamp * time_baseThe time after that, in seconds.
  • pkt_duration: Frame duration of the corresponding AVPacket, i.eAVFrame->pkt_durationBased on theAVStream->time_baseTime baseline.
  • pkt_duration_time: transformpkt_duration * time_baseThe time after that, in seconds.
  • pkt_pos: Reorder position from the last AVPacket entered into the decoder, i.eAVFrame->pkt_pos.
  • pkt_size: Frame size of the corresponding AVPacket, i.eAVFrame->pkt_size.
  • width: Frame width before rotation, i.eAVFrame->width.
  • height: Frame height before rotation, i.eAVFrame->height.
  • pix_fmt: Pixel format, correspondingav_get_pix_fmt_name(AVFrame->format).
  • sample_aspect_ratio: SAR refers to the ratio of horizontal points to vertical points in image collection. FFmpeg provides multiple SARS:AVStream->sample_aspect_ratio,AVStream->codecpar->sample_aspect_ratio,AVFrame->sample_aspect_ratioThrough theav_guess_sample_aspect_ratioGet the final SAR.
  • pict_type: Image type of the video frame, i.eav_get_picture_type_char(frame->pict_type).
  • coded_picture_number: Number of the frame in the bitstream, i.eAVFrame->coded_picture_number.
  • display_picture_number: Display number of the frame, that isAVFrame->display_picture_number.
  • interlaced_frame: Whether the video frame content is interlaced, that isAVFrame->interlaced_frame.
  • top_field_first: If the video frame content is interlaced, it represents the top field displayed first, that isAVFrame->top_field_first.
  • repeat_pict: When decoded, this signal indicates how much the video frame must be delayed.extra_delay = repeat_pict / (2*fps), i.e.,AVFrame->repeat_pict.
  • color_range: Additional color space features, i.eav_color_range_name(AVFrame->color_range).AVCOL_RANGE_MPEGCorresponding to the TV,AVCOL_RANGE_JPEGCorresponding to the PC.
  • color_space: YUV color space type, i.eav_color_space_name(AVFrame->colorspace).
  • color_primaries: that is,av_color_primaries_name(AVFrame->color_primaries).
  • color_transfer: Color transfer feature, that isav_color_transfer_name(AVFrame->color_trc).
  • chroma_location: Position of chroma sample, i.eav_chroma_location_name(AVFrame->chroma_location).

Audio frame:

  • sample_fmt: Sampling format, passav_get_sample_fmt_name(AVFrame->format)To obtain.
  • sample_rate: Sampling rate, i.eAVFrame->sample_rate.
  • channels: Number of channels, that isAVFrame->channels.
  • channel_layout: Channel type, andchannelsTheta corresponds to thetaav_bprint_channel_layoutObtain, for example, mono for mono and STEREO for multichannel.

In this paper, the reference

Of FFmpeg ffprobe

FFmpeg from Beginner to Master

(Through the introduction above, we understand ffmpeg, ffplay, ffprobe and other common command usage, which is very useful for our daily audio and video development work. We’ll explore other useful audio and video tools later, so stay tuned.)

Recommended reading

Audio Coding: PCM, AAC

Video Coding: H.264

Video Coding: H.265

Video Coding: H.266

MP4 Format

FLV Format

M3U8 Format