stand

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

Stand

封装可复用的基础命令工具库。

项目简介

Stand 是一个 Go 语言工具库,提供了常用的命令执行封装函数,简化系统命令的调用和输出处理。

功能特性

  • 实时命令输出:执行系统命令并实时显示标准输出和错误输出
  • FFmpeg 进度条支持:为 FFmpeg 命令添加实时进度条显示,基于帧数跟踪处理进度

安装

go get github.com/zhangyiming748/stand

使用方法

1. 执行命令并实时输出
package main

import (
    "os/exec"
    "github.com/zhangyiming748/stand"
)

func main() {
    cmd := exec.Command("ls", "-la")
    err := stand.ExecuteCommandWithRealtimeOutput(cmd)
    if err != nil {
        panic(err)
    }
}
2. 执行 FFmpeg 命令并显示进度条
package main

import (
    "os/exec"
    "github.com/zhangyiming748/stand"
)

func main() {
    // 首先获取视频总帧数(可以使用 ffprobe)
    totalFrames := 3000 // 示例值
    
    cmd := exec.Command("ffmpeg", "-i", "input.mp4", "output.avi")
    err := stand.ExecuteFfmpegCommandWithProgressBar(cmd, totalFrames)
    if err != nil {
        panic(err)
    }
}

API 参考

ExecuteCommandWithRealtimeOutput

执行命令并实时输出命令的输出(包括标准输出和错误输出)。

func ExecuteCommandWithRealtimeOutput(cmd *exec.Cmd) error

参数:

  • cmd: 要执行的命令

返回值:

  • error: 命令执行错误信息
ExecuteFfmpegCommandWithProgressBar

执行 FFmpeg 命令并显示实时进度条。

func ExecuteFfmpegCommandWithProgressBar(cmd *exec.Cmd, totalFrames int) error

参数:

  • cmd: FFmpeg 命令
  • totalFrames: 视频总帧数,用于计算进度百分比

返回值:

  • error: 命令执行错误信息

说明:

  • 该函数会解析 FFmpeg 输出中的帧数信息(格式:frame= XXXX
  • 实时更新进度条显示处理进度
  • 进度条输出到 stderr,避免与其他输出冲突

依赖

许可证

本项目采用 MIT 许可证,详见 LICENSE 文件。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteCommandWithRealtimeOutput

func ExecuteCommandWithRealtimeOutput(cmd *exec.Cmd) error

执行命令并实时输出命令的输出 实时打印命令本身的输出(包括标准输出和错误输出)

func ExecuteFfmpegCommandWithProgressBar

func ExecuteFfmpegCommandWithProgressBar(cmd *exec.Cmd, totalFrames int) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL