Location>code7788 >text

Programmer's development tool: Your Commands website goes live!

Popularity:241 ℃/2024-10-14 12:14:01

Programmer's development tool: Your Commands website goes live!

Link up first:

contexts

A variety of command-line tools are inseparable from our daily work in the IT industry, but for the use of command-line tools have a pain point: the document on each command-line parameters written clearly, but how to combine them with the use of confused. So in order to solve this problem everyone should have a notepad, record their common complete command line, every time you use it to turn out directly with it. But the local notepad is very inconvenient, all kinds of cloud notepad is also very bad to use. So there is an idea, why not put these command lines on the network, convenient for themselves and at the same time can also be convenient for others.

The author first collects the complete command lines he commonly uses in his daily work, including FFmpeg/Docker/Git/Tcpdump and so on. This site is open source, other bulls are very welcome to share their common command lines, the gift of the rose, the hand to leave a fragrance.

A selection is listed below:

FFmpeg

1、Re-push RTMP protocol stream

Pure transputation, no codecs.

1.1. Retweeting flv files

ffmpeg -re -stream_loop -1 -i  -c copy -f flv rtmp://localhost:1935/live/destination
parameter interpretation
  • -re
    parameter is used to simulate real-time reading of the input stream, the input data will be processed at the same speed as the actual playback speed.

  • -stream_loop is an option to specify the number of loops for the input stream.
    -1 as the value of the -stream_loop parameter indicates an infinite loop, i.e., the input stream will keep playing over and over again until it is stopped manually or the program ends.

  • -c is short for -codec, which is used to specify an encoder or decoder. copy means to copy the audio/video data directly from the source stream without recoding or decoding. It can also be written as -c:v copy -c:a copy

1.2. Retweet RTMP live streams

ffmpeg -i rtmp://localhost:1935/live/source -c copy -f flv rtmp://localhost:1935/live/destination

:::note
If the input stream itself is a real-time stream, you can not add the -re parameter, when the input stream has a GOP cache, it will be processed by the express and rolled out, configuring the appropriate playback strategy can reduce the latency than adding the -re parameter.

:::

2、Record RTMP protocol stream

It is possible to record live streams as flv files:

ffmpeg -i  'rtmp://localhost:1935/live/test'  -c:v copy -c:a copy -f flv 

3、Re-push RTSP protocol stream

3.1. TCP-based transmission

ffmpeg -re -stream_loop -1  -i test.mp4 -c:v copy -c:a copy  -rtsp_transport tcp -f rtsp "rtsp://127.0.0.1:5544/live/test?token=123"
parameter interpretation
  • -rtsp_transport tcp Indicates the transmission of audio and video data based on TCP, i.e., Interleaved mode.

3.2 UDP-based transmission

 ffmpeg -re -stream_loop -1  -i test.mp4 -c:v copy  -c:a copy -f rtsp "rtsp://127.0.0.1:5544/live/test?token=123"

4、Picture related

4.1, PNG to YUV

 ffmpeg -i  -s 1024x680 -pix_fmt yuvj420p 
parameter interpretation
  • -s 1024x680: This option specifies that the size of the output video is 1024x680 pixels. The -s is followed by the desired width and height.

  • -pix_fmt yuvj420p: This option specifies that the output pixel format is yuvj420p.

4.2. Open YUV

ffplay -f rawvideo -pixel_format yuv420p -video_size 1024x680 

4.3, YUV to PNG

ffmpeg -y -s 1024x680 -i  

5. Transcoding related

ffmpeg transcoding is mainly involved:

Transforms the encoding method:

  • H264 to H265: Reduces bit rate, reduces network bandwidth while clarity remains unchanged.
  • H265 to H264: Solve the problem that low-end devices can't solve H265.

Transforms the resolution:

  • Downscaling resolution: downscaling bit rate.
  • Upgrade resolution: the official ffmpeg to increase the resolution and bitrate does not have a good super-scoring effect, you need to use a third-party SDK integrated into ffmpeg, such as NVIDIA's MAXINE.

Reduced code rate:

  • Constant Bit Rate to Dynamic Bit Rate: Dynamically adjust the bit rate according to the complexity of the screen, saving network bandwidth and improving user experience.

5.1, RTMP live streaming into 720P H264

 ffmpeg -rw_timeout 5000000 -i 'rtmp://localhost:1935/live/source' -acodec libfdk_aac -b:a 64k -ac 2 -ar 44100 -profile:a aac_he  -vcodec libx264 -b:v 2000k -level 3.1 -vprofile high -vsync 2 -strict -2 -preset medium -bf 3 -force_key_frames source  -f flv -loglevel level+info -vf "scale='720:-2'"     'rtmp://localhost:1935/live/dest'
parameter interpretation
  • -rw_timeout 5000000 Set the read/write timeout in microseconds, 5000000 is 5 seconds. If the read/write operation is not completed within this time, FFmpeg will stop the operation and report a timeout error.

  • -acodec executes the audio encoder fdk_aac, an open source encoding library that supports LC, HE-AAC, and HE-AAC-V2 profile levels.

  • -b:a Specifies the audio bit rate

  • -ac Specify the number of audio channels2

  • -ar Specifies an audio sample rate of 44100.

  • -profile:a Specify the audio profile level as aac_he

  • -vcodec Execute video encoder as x264

  • -b:v Specifies a video bit rate of 1700Kbits/s.

  • -level is used to constrain bitrate, frame rate, and resolution

H264 Level

  • The -vprofile is used to define a collection of coding tools and features to meet different usage scenarios and performance requirements.

H264 Profile

  • -vsync 2 frames are passed or discarded along with their timestamps to prevent 2 frames from having the same timestamp.

  • -preset medium Specify the encoding speed and compression ratio, the faster the encoding speed, the lower the compression ratio.FFmpeg doc

  • -bf 3 Specifies that the number of B frames is three, usually three B frames encoded between two P frames.

  • -force_key_frames source Keyframe encoding follows the source stream, if the current frame is a keyframe in the source stream, the keyframe is encoded and output, if the current frame in the source stream must be discarded, the keyframe is output for the next frame.

  • -flv Specifies that the encapsulation format is flv.

  • -loglevel level+info Adds a log level prefix, specifying the log level as info.

  • -vf "scale='720:-2'" video filter parameter, scale is the filter used to scale the video, '720:-2' specifies the width and height of the output video: 720 means that the width of the output video will be set to 720 pixels, and -2 means that the height will be automatically computed to keep the aspect ratio of the original video.

5.2, RTMP live streaming code into 720P H265

 ffmpeg -rw_timeout 5000000 -i "rtmp://localhost:1935/live/source" -vcodec libx265 -b:v 2000k -acodec libfdk_aac -b:a 64k -ac 2 -ar 44100 -profile:a aac_he -preset veryfast -bf 3 -force_key_frames source -f flv -loglevel level+info -vf scale='720:-2' “rtmp://localhost:1935/live/dest”

Docker

1. Basic commands

1.1, pull docker image

docker pull /library/centos:7.9.2009

1.2 Run docker

docker run -it  /library/centos:7.9.2009 /bin/bash 
parameter interpretation
  • -it assigns a pseudo-terminal and keeps standard input open, suitable for interactive operation.
  • /bin/bash The command to run after the container is started, in this case opening a Bash terminal.

1.3. View all docker instances

docker ps -a
parameter interpretation
  • -a lists all containers, including stopped ones; without -a, only running ones are shown

1.4. Getting inside docker

docker  exec -it <container ID or name> /bin/bash

1.5. View all mirrors

docker images

1.6 Cleaning up docker images

1.6.1 Delete unused mirrors
docker image prune
1.6.2 Forced deletion of unused mirrors
docker image prune -a

This removes all mirrors that are not being used by the container, including suspended mirrors.

1.6.3 Deleting specific mirrors
docker rmi <image_id_or_name>
1.6.4 Exporting containers to a file
docker export <container_id>  -o  
1.6.5 Export image to file
docker save -o  <repository_name>:<tag> or <image_id>
1.6.5 Load from file into docker image
cat  | docker import - <repository_name>:<tag>

Where <repository_name> is the name of the mirror repository you want to upload to and <tag> is the tag of the mirror.

2. Higher-order commands

2.1 Pulling and running the image

docker run --cap-add=SYS_PTRACE -d -it --net=bridge --name centos7 --privileged=true -w /youcmds/workspace -e "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/" -e "LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib:/lib64:/lib" -p 1935-2935:1935-2935 -v /Users/yourcmds/workspace:/youcmds/workspace /library/centos:7.9.2009 /bin/bash 
parameter interpretation
  • The --cap-add parameter can be used to add different permissions to Docker containers, including:

    NET_ADMIN: Allows the container to have network management capabilities. This means that containers can perform network configuration, such as changing the configuration of interfaces, adding or removing routes, etc. It gives the container greater network control and is suitable for application scenarios where network settings need to be managed.

    SYS_ADMIN: Adds system administrator privileges to allow processes within the container to perform system-level administrative operations, such as mounting a file system, setting the time, and modifying the host name.

    SYS_PTRACE: Adds system trace privileges to allow processes within the container to use the ptrace system call for debugging and monitoring other processes.

    SYS_CHROOT: Adds toggle root permissions, allowing processes within the container to use the chroot system call to create a new root filesystem environment in the specified directory.

    SYS_MODULE: Add module load/unload privileges to allow processes within the container to load and unload kernel modules.

    SYS_RAWIO: Adds raw I/O permissions to allow processes within the container to perform raw read and write operations to the device, bypassing the file system abstraction provided by the operating system.

    SYS_TIME: adds time management privileges to allow processes within the container to modify the system time.

  • --net sets the network mode of docker, commonly used network modes include:

    bridge: In default mode, Docker creates a virtual bridge through which containers connect to the host's network. It is suitable for most common scenarios.

    host (host mode): containers directly use the host's network stack, suitable for applications that require high network performance, but will lose network isolation between containers.

    none (no network mode): does not connect to any network, suitable for scenarios that require complete isolation.

    container: enables a new container to share the network stack with another existing container. This means they share the same IP address and port.

    overlay (overlay network mode): Used in clustered environments (e.g. Docker Swarm or Kubernetes) across multiple Docker hosts to allow containers to communicate across hosts.

  • -d: Run the container in background mode.

  • --name centos7: Specify a name for the container (centos7).

  • -w /youcmds/workspace: Set the container's working directory.

  • -e Setting environment variables.

  • -p 1935-2935:1935-2935: maps ports 1935-2935 of the host to the same port range of the container.

  • -v /Users/yourcmds/workspace:/youcmds/workspace: Mounts the host directory to a specified path within the container to enable file sharing.

  • /library/centos:7.9.2009: pulls the mirror address.

GIT

1. Basic commands

1.1 Query remote warehouses

Used to display all remote repositories and their corresponding URLs for the current repository:

git remote -v

1.2 Update submission account information

git config --global "your name"
git config --global "your email @"

If you only want to update the current project

git config "your name"
git config "your email @"

1.3 Modify the remote warehouse address

git remote set-url origin <new-url>