stand

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 8 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() {
    cmd := exec.Command("ffmpeg", "-i", "input.mp4", "-c:v", "libx264", "output.mp4")
    // 传入视频文件路径,自动获取总帧数并显示进度条
    err := stand.ExecCommandWithBar(cmd, "input.mp4")
    if err != nil {
        panic(err)
    }
}

如果获取帧数失败,会自动回退到 ExecuteCommandWithRealtimeOutput 直接输出命令结果。

API 参考

ExecuteCommandWithRealtimeOutput

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

func ExecuteCommandWithRealtimeOutput(cmd *exec.Cmd) error

参数:

  • cmd: 要执行的命令

返回值:

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

执行 FFmpeg 命令并显示实时进度条。自动通过视频文件路径获取总帧数。

func ExecCommandWithBar(cmd *exec.Cmd, fpath string) error

参数:

  • cmd: FFmpeg 命令
  • fpath: 视频文件路径,用于自动获取总帧数

返回值:

  • error: 命令执行错误信息

说明:

  • 自动通过 FastMediaInfo 获取视频总帧数
  • 从 FFmpeg 的 stderr 输出中解析帧数信息(格式:frame= XXXX)实时更新进度条
  • 若获取帧数失败,自动回退为实时输出模式
GetVideoFrameCount

获取视频文件的总帧数。

func GetVideoFrameCount(filePath string) (int, error)

参数:

  • filePath: 视频文件路径

返回值:

  • int: 视频总帧数
  • error: 获取帧数时的错误信息

依赖

许可证

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecCommandWithBar added in v0.0.2

func ExecCommandWithBar(c *exec.Cmd, fpath string) (e error)

func ExecuteCommandWithRealtimeOutput

func ExecuteCommandWithRealtimeOutput(cmd *exec.Cmd) error

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

func GetFrameNum added in v0.0.2

func GetFrameNum(s string) (int, error)

func GetVideoFrameCount added in v0.0.3

func GetVideoFrameCount(filePath string) (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