**aspect-build/rules_js: 高性能Bazel规则指南**

aspect-build/rules_js: 高性能Bazel规则指南

rules_jsHigh-performance Bazel rules for running Node.js tools and building JavaScript projects项目地址:https://gitcode.com/gh_mirrors/ru/rules_js

1. 项目目录结构及介绍

aspect-build/rules_js项目中,我们发现其组织结构精心设计以支持JavaScript项目的构建与管理。以下是关键的目录及组件概述:

  • docs: 包含项目的官方文档,对于理解规则和如何使用至关重要。

  • examples: 提供一系列基础到复杂的示例,帮助用户快速上手,其中包含了基本使用案例以及端到端(E2E)测试场景,如利用js_image_layer容器化JavaScript二进制文件或js_run_devserver用于运行一个监视模式下的开发服务器。

  • WORKSPACE: 这是Bazel工作的起点,定义了外部依赖和其他工作区的设置。对于本项目,它至关重要,因为它设定了如何接入此规则集和其他潜在的npm依赖。

  • js: 存放核心JavaScript规则定义,如js_binaryjs_library,这些都是构建和运行JavaScript代码的关键部分。

  • BUILD, BUILD.bazel: 在各个子目录中,这些文件定义了具体目标的构建规则。

  • LICENSE: 许可证文件,说明了项目的使用条件。

  • README.md: 项目的简介和快速入门指南,对于新用户来说是非常重要的第一手资料。

2. 项目的启动文件介绍

虽然“启动文件”可能更多地指向应用逻辑的入口点,在传统意义上这不直接关联于rules_js项目本身。不过,从开发和构建的角度,重要的是理解和配置BUILDBUILD.bazel文件,以及如何通过定义js_binaryjs_library来创建可执行程序或库。例如,一个简单的启动流程可能会涉及创建一个如下的js_binary目标在你的项目中:

load('@com_vistarmedia_rules_js//js:defs.bzl', 'js_binary')

js_binary(
    name = "app",
    srcs = ["main.js"],
)

运行这个目标前,你需要确保Bazel环境已正确设置,并且rules_js已被添加至你的WORKSPACE文件中的依赖列表。

3. 项目的配置文件介绍

3.1 WORKSPACE 文件

此文件是配置项目与外部世界的桥梁,特别是如何引入rules_js和其他必要的npm包。一个典型的配置包括通过http_archivebazelrio_deps函数来添加rules_js作为依赖:

http_archive(
    name = "aspect_rules_js",
    urls = [
        "https://mirror.bazel.build/github.com/aspect-build/rules_js/releases/download/vX.Y.Z/rules_js-vX.Y.Z.tar.gz", # X.Y.Z为版本号
        "https://github.com/aspect-build/rules_js/releases/download/vX.Y.Z/rules_js-vX.Y.Z.tar.gz",
    ],
    sha256 = "SHA_HASH_HERE", # 替换成实际的SHA哈希值
)

3.2 BUILDBUILD.bazel 文件

这些文件内定义了项目的构建规则。对于JavaScript项目,关注js_libraryjs_binary的定义。它们描述了源文件、依赖关系等,指导Bazel如何编译和链接代码。

其他配置文件(非直接相关)

  • package.json: 如果你的项目同时使用npm,它定义了项目的元数据和依赖关系,但这不是rules_js直接操作的文件,而是间接影响Bazel构建过程,特别是在结合npm_install规则时。

  • .bzlmod 目录(如果存在): 表明Bazel模块的支持,简化大型项目或生态系统的依赖管理。

综上所述,理解并熟练运用rules_js的目录结构、启动逻辑及其配置文件,是有效利用该规则集进行JavaScript项目构建的关键。

rules_jsHigh-performance Bazel rules for running Node.js tools and building JavaScript projects项目地址:https://gitcode.com/gh_mirrors/ru/rules_js

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是将给定的FFmpeg命令使用最新的API转换为C语言代码的示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavutil/opt.h> int main(int argc, char *argv[]) { AVFormatContext *fmt_ctx = NULL; AVCodecContext *video_dec_ctx = NULL, *video_enc_ctx = NULL; AVCodec *video_dec = NULL, *video_enc = NULL; AVStream *video_stream = NULL; AVOutputFormat *output_fmt = NULL; AVFormatContext *output_fmt_ctx = NULL; AVPacket pkt; int ret, i; // Initialize the AVFormatContext if ((ret = avformat_open_input(&fmt_ctx, "/home/tsdl/Downloads/FPV_2021-0-1_12-37-23.h264", NULL, NULL)) < 0) { fprintf(stderr, "Could not open input file\n"); exit(1); } if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) { fprintf(stderr, "Could not find stream information\n"); exit(1); } // Find the video stream for (i = 0; i < fmt_ctx->nb_streams; i++) { if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { video_stream = fmt_ctx->streams[i]; break; } } if (!video_stream) { fprintf(stderr, "Could not find video stream\n"); exit(1); } // Initialize the video decoder video_dec = avcodec_find_decoder(video_stream->codecpar->codec_id); if (!video_dec) { fprintf(stderr, "Could not find video decoder\n"); exit(1); } video_dec_ctx = avcodec_alloc_context3(video_dec); if (!video_dec_ctx) { fprintf(stderr, "Could not allocate video decoder context\n"); exit(1); } if ((ret = avcodec_parameters_to_context(video_dec_ctx, video_stream->codecpar)) < 0) { fprintf(stderr, "Could not initialize video decoder context\n"); exit(1); } if ((ret = avcodec_open2(video_dec_ctx, video_dec, NULL)) < 0) { fprintf(stderr, "Could not open video decoder\n"); exit(1); } // Initialize the video encoder video_enc = avcodec_find_encoder_by_name("libx264"); if (!video_enc) { fprintf(stderr, "Could not find video encoder\n"); exit(1); } video_enc_ctx = avcodec_alloc_context3(video_enc); if (!video_enc_ctx) { fprintf(stderr, "Could not allocate video encoder context\n"); exit(1); } // Set video encoder options av_opt_set(video_enc_ctx->priv_data, "profile", "baseline", 0); av_opt_set(video_enc_ctx->priv_data, "tune", "zerolatency", 0); video_enc_ctx->width = video_dec_ctx->width; video_enc_ctx->height = video_dec_ctx->height; video_enc_ctx->sample_aspect_ratio = video_dec_ctx->sample_aspect_ratio; video_enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P; video_enc_ctx->time_base = av_inv_q(video_stream->avg_frame_rate); video_enc_ctx->gop_size = 50; video_enc_ctx->framerate = video_stream->avg_frame_rate; if ((ret = avcodec_open2(video_enc_ctx, video_enc, NULL)) < 0) { fprintf(stderr, "Could not open video encoder\n"); exit(1); } // Initialize the output format context if ((ret = avformat_alloc_output_context2(&output_fmt_ctx, NULL, "rtc", "http://192.168.114.34:1985/rtc/v1/whip/?app=live&stream=livestream")) < 0) { fprintf(stderr, "Could not allocate output format context\n"); exit(1); } output_fmt = output_fmt_ctx->oformat; // Add the video stream to the output format context video_stream = avformat_new_stream(output_fmt_ctx, NULL); if (!video_stream) { fprintf(stderr, "Could not create video stream\n"); exit(1); } video_stream->codecpar->codec_id = video_enc->id; video_stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; video_stream->codecpar->width = video_enc_ctx->width; video_stream->codecpar->height = video_enc_ctx->height; video_stream->codecpar->format = video_enc_ctx->pix_fmt; video_stream->codecpar->codec_tag = 0; avcodec_parameters_to_context(video_stream->codec, video_stream->codecpar); // Write the output format header if ((ret = avformat_write_header(output_fmt_ctx, NULL)) < 0) { fprintf(stderr, "Could not write output format header\n"); exit(1); } // Read frames from input, encode and write to output while (1) { if ((ret = av_read_frame(fmt_ctx, &pkt)) < 0) { break; } if (pkt.stream_index == video_stream->index) { av_packet_rescale_ts(&pkt, video_stream->time_base, video_enc_ctx->time_base); pkt.flags |= AV_PKT_FLAG_KEY; if ((ret = avcodec_send_packet(video_enc_ctx, &pkt)) < 0) { fprintf(stderr, "Could not send packet to video encoder\n"); exit(1); } while (ret >= 0) { ret = avcodec_receive_packet(video_enc_ctx, &pkt); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { break; } else if (ret < 0) { fprintf(stderr, "Error encoding video frame\n"); exit(1); } av_packet_rescale_ts(&pkt, video_enc_ctx->time_base, video_stream->time_base); pkt.stream_index = video_stream->index; if ((ret = av_interleaved_write_frame(output_fmt_ctx, &pkt)) < 0) { fprintf(stderr, "Error writing video frame\n"); exit(1); } av_packet_unref(&pkt); } } av_packet_unref(&pkt); } // Write the output format trailer av_write_trailer(output_fmt_ctx); // Cleanup avformat_close_input(&fmt_ctx); avcodec_free_context(&video_dec_ctx); avcodec_free_context(&video_enc_ctx); avformat_free_context(output_fmt_ctx); return 0; } ``` 注意:以上示例代码仅供参考,具体实现可能需要根据您的需求进行修改。同时,您需要添加FFmpeg库的链接,并将FFmpeg头文件和库文件添加到编译路径中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

段琳惟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值