当前位置: 首页 > news >正文

中国住房建设部网站首页快手seo软件下载

中国住房建设部网站首页,快手seo软件下载,网站域名费怎么查询,西安做网站那家公司好2023-04-01:当Go语言遇见FFmpeg视频解码器,使用Go语言改写decode_video.c文件,提升视频解码效率与开发体验。 答案2023-04-01: 步骤如下: 1.导入必要的依赖库,包括 fmt、os、unsafe 和其它 FFmpeg 库相关…

2023-04-01:当Go语言遇见FFmpeg视频解码器,使用Go语言改写decode_video.c文件,提升视频解码效率与开发体验。

答案2023-04-01:

步骤如下:

1.导入必要的依赖库,包括 fmt、os、unsafe 和其它 FFmpeg 库相关的 Go 库。

2.定义一个名为 main0() 的函数,该函数负责视频解码操作。在函数中定义了许多变量,例如文件名、编解码器、解析器、编解码器上下文、文件句柄、AVFrame 等等。

3.通过命令行参数获取输入文件名和输出文件名,并进行一些基本的参数检查。

4.通过调用 AvPacketAlloc() 函数创建一个 AVPacket 对象,用于存储解码后的帧数据。如果创建失败,则退出程序。

5.初始化输入缓冲区 inbuf 并设置结尾填充字节为 0。

6.调用 AvcodecFindDecoder() 函数查找 MPEG-1 视频解码器。如果找不到,则退出程序。

7.调用 AvParserInit() 函数初始化解析器。如果初始化失败,则退出程序。

8.调用 AvCodecAllocContext3() 函数分配一个新的编解码器上下文对象。如果分配失败,则退出程序。

9.调用 AvcodecOpen2() 函数打开编解码器。如果打开失败,则退出程序。

10.打开输入文件,并创建一个 AVFrame 对象。

11.进入循环,读取输入文件并将其分解成视频帧。如果读取失败或读取完毕,则跳出循环。

12.调用 AvParserParse2() 函数将输入缓冲区中的数据解析为视频帧,并存储在 AVPacket 对象中。如果解析失败,则退出程序。

13.如果成功解析到一个视频帧,则调用 decode() 函数对其进行解码并保存到输出文件中。

14.在循环结束后,调用 decode() 函数对剩余的数据进行解码并保存到输出文件中。

15.关闭输入文件句柄、解析器、编解码器上下文和 AVFrame 对象等资源,以避免内存泄漏。

16.定义一个名为 pgm_save() 的函数,该函数用于将视频帧写入 PGM 格式文件。

17.定义一个名为 decode() 的函数,该函数用于对视频帧进行解码并调用 pgm_save() 函数将其写入 PGM 格式文件。

18.定义 main() 函数,该函数将 FFmpeg 库的路径设置为当前目录下的 lib 子目录,并调用 main0() 函数进行视频解码操作。

注意:在 Windows 操作系统中,您可能需要将 FFmpeg 库的可执行文件添加到 PATH 环境变量中,或者使用 SetXXXPath() 函数设置它们的路径,才能够正常运行此代码。

代码见github/moonfdd/ffmpeg-go。

执行命令:

./lib/ffmpeg -i ./resources/big_buck_bunny.mp4 -c:v mpeg1video ./out/big_buck_bunny.mpggo run ./examples/internalexamples/decode_video/main.go ./out/big_buck_bunny.mpg ./out/ppm/big_buck_bunny.yuv./lib/ffplay  ./out/ppm/big_buck_bunny.yuv-113.ppm

golang代码如下:

package mainimport ("fmt""os""unsafe""github.com/moonfdd/ffmpeg-go/ffcommon""github.com/moonfdd/ffmpeg-go/libavcodec""github.com/moonfdd/ffmpeg-go/libavutil"
)func main0() (ret ffcommon.FInt) {var filename, outfilename stringvar codec *libavcodec.AVCodecvar parser *libavcodec.AVCodecParserContextvar c *libavcodec.AVCodecContextvar f *os.Filevar frame *libavutil.AVFramevar inbuf [INBUF_SIZE + libavcodec.AV_INPUT_BUFFER_PADDING_SIZE]ffcommon.FUint8Tvar data *ffcommon.FUint8Tvar data_size ffcommon.FSizeTvar pkt *libavcodec.AVPacketif len(os.Args) <= 2 {fmt.Printf("Usage: %s <input file> <output file>\nAnd check your input file is encoded by mpeg1video please.\n", os.Args[0])os.Exit(0)}filename = os.Args[1]outfilename = os.Args[2]pkt = libavcodec.AvPacketAlloc()if pkt == nil {os.Exit(1)}/* set end of buffer to 0 (this ensures that no overreading happens for damaged MPEG streams) *///memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);/* find the MPEG-1 video decoder */codec = libavcodec.AvcodecFindDecoder(libavcodec.AV_CODEC_ID_MPEG1VIDEO)if codec == nil {fmt.Printf("Codec not found\n")os.Exit(1)}parser = libavcodec.AvParserInit(int32(codec.Id))if parser == nil {fmt.Printf("parser not found\n")os.Exit(1)}c = codec.AvcodecAllocContext3()if c == nil {fmt.Printf("Could not allocate video codec context\n")os.Exit(1)}/* For some codecs, such as msmpeg4 and mpeg4, width and heightMUST be initialized there because this information is notavailable in the bitstream. *//* open it */if c.AvcodecOpen2(codec, nil) < 0 {fmt.Printf("Could not open codec\n")os.Exit(1)}var err errorf, err = os.Open(filename)if err != nil {fmt.Printf("Could not open %s,err = %s\n", filename, err)os.Exit(1)}frame = libavutil.AvFrameAlloc()if frame == nil {fmt.Printf("Could not allocate video frame\n")os.Exit(1)}for {/* read raw data from the input file */var n intn, err = f.Read(inbuf[:INBUF_SIZE])if err != nil {break}data_size = uint64(n)if data_size == 0 {break}/* use the parser to split the data into frames */data = (*byte)(unsafe.Pointer(&inbuf))for data_size > 0 {ret = parser.AvParserParse2(c, &pkt.Data, (*int32)(unsafe.Pointer(&pkt.Size)),data, int32(data_size), libavutil.AV_NOPTS_VALUE, libavutil.AV_NOPTS_VALUE, 0)if ret < 0 {fmt.Printf("Error while parsing\n")os.Exit(1)}data = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(data)) + uintptr(ret)))data_size -= uint64(ret)if pkt.Size != 0 {decode(c, frame, pkt, outfilename)}}}/* flush the decoder */decode(c, frame, nil, outfilename)f.Close()parser.AvParserClose()libavcodec.AvcodecFreeContext(&c)libavutil.AvFrameFree(&frame)libavcodec.AvPacketFree(&pkt)return 0
}const INBUF_SIZE = 4096func pgm_save(buf ffcommon.FBuf, wrap, xsize, ysize ffcommon.FInt, filename string) {var f *os.Filevar i ffcommon.FIntvar err errorf, err = os.Create(filename)if err != nil {return}f.WriteString(fmt.Sprintf("P5\n%d %d\n%d\n", xsize, ysize, 255))bytes := []byte{}for i = 0; i < ysize; i++ {for j := int32(0); j < xsize; j++ {bytes = append(bytes, *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(i*wrap+j))))}}f.Write(bytes)f.Close()
}func decode(dec_ctx *libavcodec.AVCodecContext, frame *libavutil.AVFrame, pkt *libavcodec.AVPacket, filename string) {// var buf [1024]bytevar ret ffcommon.FIntret = dec_ctx.AvcodecSendPacket(pkt)if ret < 0 {fmt.Printf("Error sending a packet for decoding\n")os.Exit(1)}for ret >= 0 {ret = dec_ctx.AvcodecReceiveFrame(frame)if ret == -libavutil.EAGAIN || ret == libavutil.AVERROR_EOF {return} else if ret < 0 {fmt.Printf("Error during decoding %d\n", ret)os.Exit(1)}fmt.Printf("saving frame %3d\n", dec_ctx.FrameNumber)//fflush(stdout)/* the picture is allocated by the decoder. no need tofree it */pgm_save(frame.Data[0], frame.Linesize[0],frame.Width, frame.Height, fmt.Sprintf("%s-%d.ppm", filename, dec_ctx.FrameNumber))}
}func main() {os.Setenv("Path", os.Getenv("Path")+";./lib")ffcommon.SetAvutilPath("./lib/avutil-56.dll")ffcommon.SetAvcodecPath("./lib/avcodec-58.dll")ffcommon.SetAvdevicePath("./lib/avdevice-58.dll")ffcommon.SetAvfilterPath("./lib/avfilter-56.dll")ffcommon.SetAvformatPath("./lib/avformat-58.dll")ffcommon.SetAvpostprocPath("./lib/postproc-55.dll")ffcommon.SetAvswresamplePath("./lib/swresample-3.dll")ffcommon.SetAvswscalePath("./lib/swscale-5.dll")genDir := "./out"_, err := os.Stat(genDir)if err != nil {if os.IsNotExist(err) {os.Mkdir(genDir, 0777) //  Everyone can read write and execute}}main0()
}

在这里插入图片描述

http://www.yidumall.com/news/96843.html

相关文章:

  • 同ip网站做友链成都网站建设技术支持
  • 政务公开系统网站建设长尾关键词举例
  • 动态网页网站seo服务靠谱吗
  • php商业网站制作免费的seo网站下载
  • 织梦统计网站访问量代码沪深300指数怎么买
  • 济南品牌营销型网站建设十大搜索引擎地址
  • angular做门户网站友链交易网
  • 深圳企业网站制作报价网络营销工程师是做什么的
  • 电信网站服务器百度网页高级搜索
  • 专业的营销型网站培训中心品牌推广内容
  • 南联企业网站建设新闻头条今日要闻
  • 做网站为什么要备案照相怎么拿到百度推广的代理
  • 网站制作软件排行榜正规seo大概多少钱
  • 电子商务网站建设的基本要素线上培训
  • 俄罗斯免费网站推广网站优化关键词排名公司
  • 做网站图标的软件宁波网站推广平台效果好
  • 泰兴城乡建设局网站无锡网站制作推广
  • 自己建网站做代理商厦门seo培训
  • 武汉彩票网站开发公司百度服务商平台
  • 广东网站建设价格seo优化的主要任务
  • 可以自己做论坛网站吗网络优化大师下载
  • 哪个网站可以做头像关键词排名批量查询软件
  • 深圳疫情情况最新今天南昌seo方案
  • 海南网站建设中心手机系统优化软件
  • 网站建设平台杭州百度网址大全 简单版
  • flash 可以做网站吗网站推广属于哪些
  • 北京建设工程交易信息网官网快手seo关键词优化
  • 南宁房地产信息网保定seo网站推广
  • 附近编程培训机构seo网络推广是干嘛的
  • 随州网站制作友情链接对网站的作用