我想添加空音频流。在 ffmpeg 命令行工具我可以做:
-re -f lavfi -i anullsrc
但我不知道如何在代码中做到这一点。基于此:https://ffmpeg.org/doxygen/trunk/filter_audio_8c-example.html#a12我认为我可以创建一个假帧,将其馈送到过滤器图,读取输出,使用一些编码器 (?),也许我会让它工作。但这似乎是一个相当丑陋的解决方法。
编辑:
本质上我只是想创建Packet
实例与音频来自 anullsrc 过滤器 / 输入。

您可能能够在我们的输出上下文中使用 Filter,尽管我没有尝试过。这里看起来是一个使用 Filterhttps://blog.birost.com/a?ID=01500-3825be8d-e578-4030-9e2e-a4f7160d1410的基本实现的人的例子。具体来说,下面的代码 (我意识到它与视频有关,但你应该能够修改为音频,并且可能能够摆脱很多这样的代码)。
static int init_filters(const char *filters_descr)
{
char args[512];
int ret;
Filter *buffersrc = avfilter_get_by_name("buffer");
Filter *buffersink = avfilter_get_by_name("ffbuffersink");
FilterInOut *outputs = avfilter_inout_alloc();
FilterInOut *inputs = avfilter_inout_alloc();
enum PixelFormat pix_fmts[] = { _PIX_FMT_YUV420P, _PIX_FMT_NONE };
BufferSinkParams *buffersink_params;
filter_graph = avfilter_graph_alloc();
/* buffer video source: the decoded frames from the decoder will be inserted here. */
snprintf(args, sizeof(args),
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
pCodecCtx->time_base.num, pCodecCtx->time_base.den,
pCodecCtx->sample_aspect_ratio.num, pCodecCtx->sample_aspect_ratio.den);
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
args, NULL, filter_graph);
if (ret < 0) {
printf("Cannot create buffer source\n");
return ret;
}
/* buffer video sink: to terminate the filter chain. */
buffersink_params = av_buffersink_params_alloc();
buffersink_params->pixel_fmts = pix_fmts;
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
NULL, buffersink_params, filter_graph);
av_free(buffersink_params);
if (ret < 0) {
printf("Cannot create buffer sink\n");
return ret;
}
/* Endpoints for the filter graph. */
outputs->name = av_strdup("in");
outputs->filter_ctx = buffersrc_ctx;
outputs->pad_idx = 0;
outputs->next = NULL;
inputs->name = av_strdup("out");
inputs->filter_ctx = buffersink_ctx;
inputs->pad_idx = 0;
inputs->next = NULL;
Filter 已注册以下筛选器:
REGISTER_FILTER(ANULLSRC, anullsrc, asrc);
REGISTER_FILTER(ANULLSINK, anullsink, asink);
您可能能够以与示例代码使用相同的方式使用。我会认为一个空的 Packet 可以工作。它可能这种方法不起作用 (没有直接处理这个),但是如果你还没有,你可以尝试一下。如果你这样做,我很乐意听到结果。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(13条)