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

国家住房和城乡建设网站企业网络策划

国家住房和城乡建设网站,企业网络策划,网站在百度搜索不到,民权县住房和城乡建设局网站2023-05-04:用go语言重写ffmpeg的scaling_video.c示例,用于实现视频缩放(Scaling)功能。 答案2023-05-04: 这段代码实现了使用 libswscale 库进行视频缩放的功能。下面是程序的主要流程: 1.获取命令行参…

2023-05-04:用go语言重写ffmpeg的scaling_video.c示例,用于实现视频缩放(Scaling)功能。

答案2023-05-04:

这段代码实现了使用 libswscale 库进行视频缩放的功能。下面是程序的主要流程:

1.获取命令行参数,包括输出文件名和目标图像大小。

2.解析目标图像大小,生成指定大小的输出文件。

3.创建缩放上下文(scaling context)并分配输入和输出图像数据的内存空间。

4.循环生成合成图像、将输入图像转换为输出图像并将输出图像写入输出文件中,重复该操作若干次。

5.释放内存空间并关闭输出文件。

具体步骤如下:

1.获取命令行参数。首先检查命令行参数是否符合要求,如果不符合则打印使用说明并退出程序。否则,解析输出文件名和目标图像大小。

2.解析目标图像大小。调用 libavutil.AvParseVideoSize() 函数解析目标图像大小,并根据解析结果生成一个指定大小的输出文件。

3.创建缩放上下文并分配内存空间。调用 libswscale.SwsGetContext() 函数创建一个缩放上下文,并使用 libavutil.AvImageAlloc() 函数分配输入和输出图像数据的内存空间。

4.循环处理图像。在循环中,首先生成一个 YUV420P 格式的合成图像。然后,调用 libswscale.SwsScale() 函数将输入图像转换为输出图像。最后,将输出图像写入输出文件中。在本程序中,处理图像的循环次数为 100 次。

5.释放内存空间并关闭输出文件。在程序结束时,需要释放输入和输出图像数据的内存空间,并关闭输出文件。

整个程序的主要目的是演示如何使用 libswscale 库进行视频缩放。它通过调用 libswscale 库的函数 SwsGetContext()SwsScale() 实现了将一系列输入图像转换为指定大小的输出图像的功能。

代码见github/moonfdd/ffmpeg-go库。

命令如下:

go run ./examples/internalexamples/scaling_video/main.go ./out/big_buck_bunny.mp4 640*480./lib/ffplay -f rawvideo -pix_fmt rgb24 -video_size 640x480 ./out/big_buck_bunny.mp4

golang代码如下:

package mainimport ("fmt""os""unsafe""github.com/moonfdd/ffmpeg-go/ffcommon""github.com/moonfdd/ffmpeg-go/libavutil""github.com/moonfdd/ffmpeg-go/libswscale"
)func main0() (ret ffcommon.FInt) {var src_data, dst_data [4]*ffcommon.FUint8Tvar src_linesize, dst_linesize [4]ffcommon.FIntvar src_w ffcommon.FInt = 320var src_h ffcommon.FInt = 240var dst_w ffcommon.FIntvar dst_h ffcommon.FIntvar src_pix_fmt libavutil.AVPixelFormat = libavutil.AV_PIX_FMT_YUV420Pvar dst_pix_fmt libavutil.AVPixelFormat = libavutil.AV_PIX_FMT_RGB24var dst_size stringvar dst_filename stringvar dst_file *os.Filevar dst_bufsize ffcommon.FIntvar sws_ctx *libswscale.SwsContextvar i ffcommon.FIntif len(os.Args) != 3 {fmt.Printf("Usage: %s output_file output_size\nAPI example program to show how to scale an image with libswscale.\nThis program generates a series of pictures, rescales them to the given output_size and saves them to an output file named output_file\n.\n", os.Args[0])os.Exit(1)}dst_filename = os.Args[1]dst_size = os.Args[2]if libavutil.AvParseVideoSize(&dst_w, &dst_h, dst_size) < 0 {fmt.Printf("Invalid size '%s', must be in the form WxH or a valid size abbreviation\n",dst_size)os.Exit(1)}dst_file, _ = os.Create(dst_filename)if dst_file == nil {fmt.Printf("Could not open destination file %s\n", dst_filename)os.Exit(1)}/* create scaling context */sws_ctx = libswscale.SwsGetContext(src_w, src_h, src_pix_fmt,dst_w, dst_h, dst_pix_fmt,libswscale.SWS_BILINEAR, nil, nil, nil)if sws_ctx == nil {fmt.Printf("Impossible to create scale context for the conversion fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",libavutil.AvGetPixFmtName(src_pix_fmt), src_w, src_h,libavutil.AvGetPixFmtName(dst_pix_fmt), dst_w, dst_h)ret = -libavutil.EINVALgoto end}/* allocate source and destination image buffers */ret = libavutil.AvImageAlloc(&src_data, &src_linesize,src_w, src_h, src_pix_fmt, 16)if ret < 0 {fmt.Printf("Could not allocate source image\n")goto end}/* buffer is going to be written to rawvideo file, no alignment */ret = libavutil.AvImageAlloc(&dst_data, &dst_linesize,dst_w, dst_h, dst_pix_fmt, 1)if ret < 0 {fmt.Printf("Could not allocate destination image\n")goto end}dst_bufsize = retfor i = 0; i < 100; i++ {// /* generate synthetic video */fill_yuv_image(&src_data, &src_linesize, src_w, src_h, i)/* convert to destination format */sws_ctx.SwsScale((**byte)(unsafe.Pointer(&src_data)),(*int32)(unsafe.Pointer(&src_linesize)), 0, uint32(src_h), (**byte)(unsafe.Pointer(&dst_data)), (*int32)(unsafe.Pointer(&dst_linesize)))// /* write scaled image to file */dst_file.Write(ffcommon.ByteSliceFromByteP(dst_data[0], int(dst_bufsize)))}fmt.Printf("Scaling succeeded. Play the output file with the command:\nffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n",libavutil.AvGetPixFmtName(dst_pix_fmt), dst_w, dst_h, dst_filename)end:dst_file.Close()libavutil.AvFreep(uintptr(unsafe.Pointer(&src_data[0])))libavutil.AvFreep(uintptr(unsafe.Pointer(&dst_data[0])))sws_ctx.SwsFreeContext()if ret < 0 {return 1} else {return 0}
}func fill_yuv_image(data *[4]*ffcommon.FUint8T, linesize *[4]ffcommon.FInt, width, height, frame_index ffcommon.FInt) {var x, y ffcommon.FInt/* Y */for y = 0; y < height; y++ {for x = 0; x < width; x++ {//data[0][y*linesize[0]+x] = x + y + frame_index*3*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(data[0])) + uintptr(y*linesize[0]+x))) = byte((x + y + frame_index*3) % 256)}}/* Cb and Cr */for y = 0; y < height/2; y++ {for x = 0; x < width/2; x++ {// data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;// data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(data[1])) + uintptr(y*linesize[1]+x))) = byte((128 + y + frame_index*2) % 256)*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(data[2])) + uintptr(y*linesize[2]+x))) = byte((64 + x + frame_index*5) % 256)}}
}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.ds6.com.cn/news/67546.html

相关文章:

  • 手机网站怎么做域名解析seo服务建议
  • 自助式网站网址查询
  • 河南省建设委员会网站南昌seo排名扣费
  • 申请个人网站有什么用百度高级搜索技巧
  • 北京专业企业营销网站建设个人网站设计图片
  • 视频广告网站国际热点事件
  • 什么网站做污水处理药剂的好轻松seo优化排名 快排
  • 前端进入网站建设公司怎么样免费网站注册平台
  • 还有人用asp做网站吗域名注册流程和费用
  • 微信如何做微商城网站建设网店推广平台
  • 删除的网站做404网站优化排名资源
  • 国外好的室内设计网站怎么让网站被百度收录
  • 许昌企业网站建设bing搜索引擎国际版
  • 中信银行网站怎么做的怎么烂seo关键词外包
  • 建设网站怎么知道真假天津网站优化软件
  • 小程序开发一般采用的技术优化设计答案五年级上册
  • 贵州省民贸民品企业信息管理系统焦作网站seo
  • 做网站如何突出网站特色seo入门培训学校
  • 庆阳做网站的公司培训机构退费纠纷一般怎么解决
  • 钓鱼网站怎样做竞价外包推广
  • 自己做的网站访问速度慢搜索关键词的方法
  • 天津市建设网站全网搜索软件
  • 久久建筑网会员登录签到seo工作内容和薪资
  • 中原彼得堡航空学院网站的建设重庆网站建设
  • 网站建设都需要那些材料网络推广员的日常工作
  • java做的小说网站的源代码网站宣传费用
  • 网站内链建设中国免费网站服务器2020
  • 做网站属于程序员吗百度官方版下载
  • 宝安国内知名网站建设比较好的百度竞价托管外包
  • 关于推进公司网站开发的请示地推拉新app推广平台