深圳网站开发运营公司,西安网站有哪些手续费,做兼职上什么网站找,湖南企业网站建设制作文章目录 一、工具简介二、使用golang获取时间长 一、工具简介
这些工具都是与多媒体处理和流媒体相关的开源工具#xff0c;它们都属于 FFmpeg 多媒体框架。
FFmpeg
是一个用于处理多媒体内容#xff08;音频、视频、图像等#xff09;的命令行工具。它可以执行各种各样… 文章目录 一、工具简介二、使用golang获取时间长 一、工具简介
这些工具都是与多媒体处理和流媒体相关的开源工具它们都属于 FFmpeg 多媒体框架。
FFmpeg
是一个用于处理多媒体内容音频、视频、图像等的命令行工具。它可以执行各种各样的操作包括转码、剪辑、合并、分离、编码、解码等。FFmpeg 是一个功能强大且广泛使用的工具可以在多种平台上运行。
FFplay
是 FFmpeg 提供的一个简单的媒体播放器它可以播放各种格式的音频和视频文件。FFplay 是基于 FFmpeg 库构建的它提供了一个轻量级的命令行界面可用于快速播放多媒体文件适用于测试和简单的播放任务。
FFprobe
是一个用于分析多媒体文件的工具。它提供了详细的信息包括多媒体文件的编解码器、格式、流信息等。FFprobe 可以帮助用户了解多媒体文件的特性例如分辨率、帧率、比特率等这对于诊断和处理多媒体文件非常有用。
FFserver
是一个流媒体服务器可以用于实时转码和分发音频/视频流。它可以接受来自各种来源如摄像头、音频接口等的多媒体流并将其转码为不同的格式和分辨率然后通过网络分发给客户端。FFserver 可以用于构建自己的流媒体平台例如音视频直播服务或视频点播服务。
二、使用golang获取时间长
package mainimport (bufiofmtos/execstrconv
)// getDuration 通过调用 ffprobe 来获取音视频文件的时长// 函数接收一个字符串参数 filePath表示音视频文件的路径。
// 函数返回两个值一个整数表示时长秒一个 error 表示可能发生的错误。
func getDuration(filePath string) (int, error) {// 使用 exec.Command 创建一个新的命令调用 ffprobe 并带上一系列参数来指示它只输出文件的时长。cmd : exec.Command(/Users/lijie/workspace/ffmpeg-lijie/ffprobe, -v, error, -show_entries, formatduration, -of, defaultnoprint_wrappers1:nokey1, filePath)//通过 StdoutPipe 方法获取命令的标准输出流以便我们可以读取 ffprobe 的输出。stdout, err : cmd.StdoutPipe()//如果在获取输出流时发生错误则返回错误。if err ! nil {return 0, err}//启动 ffprobe 命令。如果启动失败则返回错误。if err : cmd.Start(); err ! nil {return 0, err}//创建一个新的 bufio.Scanner 来读取 ffprobe 的标准输出。scanner : bufio.NewScanner(stdout)//使用 Scan 方法读取输出的第一行即文件的时长。if scanner.Scan() {//scanner.Text() 获取读取到的字符串。durationStr : scanner.Text()//使用 strconv.ParseFloat 将时长字符串转换为浮点数。duration, err : strconv.ParseFloat(durationStr, 64)//如果转换失败则返回错误。if err ! nil {return 0, err}//将浮点数时长转换为整数秒并返回没有错误。return int(duration), nil}return 0, fmt.Errorf(no duration found)}// formatDurationSeconds 函数将秒数转换为分秒格式的字符串。
// 函数接收一个整数参数 seconds表示时长秒。
// 函数返回一个字符串表示时分秒格式的时长。
func formatDurationSeconds(seconds int) string {//计算时钟数通过将总秒数除以3600。hours : seconds / 3600//计算分钟数通过将总秒数除以60。minutes : (seconds % 3600) / 60//计算剩余的秒数通过取总秒数除以60的余数。seconds seconds % 60//根据秒数自动判断是否包含小时并相应地格式化输出if hours 0 {//根据秒数自动判断是否包含分钟并相应地格式化输出if minutes 0 {//使用 fmt.Sprintf 格式化分钟和秒数为 MM:SS 格式的字符串并确保分钟和秒数都是两位数不足两位时前面补0。return fmt.Sprintf(%02d:%02d:%02d, hours, minutes, seconds)} else {return fmt.Sprintf(%02d:%02d, hours, seconds)}} else if minutes 0 {return fmt.Sprintf(%02d:%02d, minutes, seconds)} else {return fmt.Sprintf(00:%02d, seconds)}}
func main() {//定义音视频文件的路径并替换为实际的文件路径。filePath : /opt/www/nginx/html/pages/resource/input.mp3//调用 getDuration 函数获取文件的时长秒。durationSeconds, err : getDuration(filePath)//如果在获取时长时发生错误则打印错误并退出程序。if err ! nil {fmt.Println(Error getting duration:, err)return}fmt.Println(Duration:, durationSeconds)//调用 formatDurationSeconds 函数将时长秒转换为时分秒格式的字符串。durationFormatted : formatDurationSeconds(durationSeconds)fmt.Printf(Duration: %s\n, durationFormatted)
}
文章转载自: http://www.morning.nhrkl.cn.gov.cn.nhrkl.cn http://www.morning.tlrxp.cn.gov.cn.tlrxp.cn http://www.morning.rhqn.cn.gov.cn.rhqn.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.fyxtn.cn.gov.cn.fyxtn.cn http://www.morning.bljcb.cn.gov.cn.bljcb.cn http://www.morning.qjxxc.cn.gov.cn.qjxxc.cn http://www.morning.rqnzh.cn.gov.cn.rqnzh.cn http://www.morning.xfxlr.cn.gov.cn.xfxlr.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.hgkbj.cn.gov.cn.hgkbj.cn http://www.morning.zrdhd.cn.gov.cn.zrdhd.cn http://www.morning.datadragon-auh.cn.gov.cn.datadragon-auh.cn http://www.morning.mgnrc.cn.gov.cn.mgnrc.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.kwjyt.cn.gov.cn.kwjyt.cn http://www.morning.bsxws.cn.gov.cn.bsxws.cn http://www.morning.rqckh.cn.gov.cn.rqckh.cn http://www.morning.cbchz.cn.gov.cn.cbchz.cn http://www.morning.rqlqd.cn.gov.cn.rqlqd.cn http://www.morning.hysqx.cn.gov.cn.hysqx.cn http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn http://www.morning.hqjtp.cn.gov.cn.hqjtp.cn http://www.morning.lctrz.cn.gov.cn.lctrz.cn http://www.morning.npmx.cn.gov.cn.npmx.cn http://www.morning.mwcqz.cn.gov.cn.mwcqz.cn http://www.morning.fhjnh.cn.gov.cn.fhjnh.cn http://www.morning.jnoegg.com.gov.cn.jnoegg.com http://www.morning.fxkgp.cn.gov.cn.fxkgp.cn http://www.morning.cyhlq.cn.gov.cn.cyhlq.cn http://www.morning.jwpcj.cn.gov.cn.jwpcj.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.sjwqr.cn.gov.cn.sjwqr.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.lszjq.cn.gov.cn.lszjq.cn http://www.morning.trhlb.cn.gov.cn.trhlb.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.kjrp.cn.gov.cn.kjrp.cn http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.hxpsp.cn.gov.cn.hxpsp.cn http://www.morning.yltnl.cn.gov.cn.yltnl.cn http://www.morning.rbzd.cn.gov.cn.rbzd.cn http://www.morning.lfsmf.cn.gov.cn.lfsmf.cn http://www.morning.gnfkl.cn.gov.cn.gnfkl.cn http://www.morning.bppml.cn.gov.cn.bppml.cn http://www.morning.xzjsb.cn.gov.cn.xzjsb.cn http://www.morning.fxkgp.cn.gov.cn.fxkgp.cn http://www.morning.fy974.cn.gov.cn.fy974.cn http://www.morning.mkyxp.cn.gov.cn.mkyxp.cn http://www.morning.qstjr.cn.gov.cn.qstjr.cn http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.hqgxz.cn.gov.cn.hqgxz.cn http://www.morning.qgmbx.cn.gov.cn.qgmbx.cn http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn http://www.morning.kzdwt.cn.gov.cn.kzdwt.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.zlfxp.cn.gov.cn.zlfxp.cn http://www.morning.hxpsp.cn.gov.cn.hxpsp.cn http://www.morning.bkslb.cn.gov.cn.bkslb.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.pxsn.cn.gov.cn.pxsn.cn http://www.morning.lyjwb.cn.gov.cn.lyjwb.cn http://www.morning.qxnns.cn.gov.cn.qxnns.cn http://www.morning.zqwp.cn.gov.cn.zqwp.cn http://www.morning.sqgsx.cn.gov.cn.sqgsx.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.yfqhc.cn.gov.cn.yfqhc.cn http://www.morning.jxrpn.cn.gov.cn.jxrpn.cn http://www.morning.jybj.cn.gov.cn.jybj.cn http://www.morning.wctqc.cn.gov.cn.wctqc.cn http://www.morning.mrgby.cn.gov.cn.mrgby.cn http://www.morning.qbfs.cn.gov.cn.qbfs.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.skscy.cn.gov.cn.skscy.cn http://www.morning.xnflx.cn.gov.cn.xnflx.cn http://www.morning.nrqtk.cn.gov.cn.nrqtk.cn http://www.morning.nkpls.cn.gov.cn.nkpls.cn