- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
关于使用 ffmpeg 对视频文件进行视频编码/复用的简单问题。基本上,我的复用器正在运行,我正在尝试让我的数据包输出正确的 PTS/DTS。
这是我编码我的 AVFrame 的代码的一部分,将它混合到输出文件中:
int ret;
int got_packet = 0;
AVPacket pkt = { 0 };
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
/* encode the image */
ret = avcodec_encode_video2(cc, &pkt, frame, &got_packet);
if (ret < 0)
{
fprintf(stderr, "error encoding video frame: %s\n", av_err2str(ret));
exit(EXIT_FAILURE);
}
if (got_packet)
{
av_packet_rescale_ts(&pkt, cc->time_base, st->time_base);
fprintf(stderr, "\npkt.pts = %ld\n", pkt.pts);
fprintf(stderr, "pkt.dts = %ld\n", pkt.dts);
fprintf(stderr, "writing frame\n");
ret = av_interleaved_write_frame(fmt_ctx, &pkt);
av_packet_unref(&pkt);
}
else
{
ret = 0;
}
...
然后我得到以下输出:
pkt.pts = 0
pkt.dts = 0
writing frame
pkt.pts = 1502
pkt.dts = 0
writing frame
pkt.pts = 3003
pkt.dts = 1502
writing frame
pkt.pts = 4505
pkt.dts = 3003
writing frame
...
我的目标是让我的 PST 和 DST 都具有以下模式:1502、3003、4505、6006、7508,...
但似乎第一个 DTS 值重复了一次,因此与其对应的 PTS 值不同步。还值得一提的是,编解码器上下文配置为没有 b 帧,因此此处仅存在 i 帧和 p 帧。
有没有经验丰富的人对此有一些见解?
添加:
我在终端中运行了以下命令来检查我的 DTS 和 PTS 值是否与我的打印语句一致:
sudo ./ffprobe -show_packets -print_format json mux_test.ts | less
我得到了以下信息:
{
"packets": [
{
"codec_type": "video",
"stream_index": 0,
"pts": 0,
"pts_time": "0.000000",
"dts": -1501,
"dts_time": "-0.016678",
"duration": 1501,
"duration_time": "0.016678",
"convergence_duration": "N/A",
"convergence_duration_time": "N/A",
"size": "55409",
"pos": "564",
"flags": "K"
},
{
"codec_type": "video",
"stream_index": 0,
"pts": 1502,
"pts_time": "0.016689",
"dts": 0,
"dts_time": "0.000000",
"duration": 1501,
"duration_time": "0.016678",
"convergence_duration": "N/A",
"convergence_duration_time": "N/A",
"size": "46574",
"pos": "60160",
"flags": "_"
},
{
"codec_type": "video",
"stream_index": 0,
"pts": 3003,
"pts_time": "0.033367",
"dts": 1502,
"dts_time": "0.016689",
"duration": 1501,
"duration_time": "0.016678",
"convergence_duration": "N/A",
"convergence_duration_time": "N/A",
"size": "2544",
"pos": "110356",
"flags": "_"
},
...
它不会重复显示我的第一个 DTS 值,但会在我的 PTS 之后继续显示我的 DTS 一个周期。
最佳答案
调试API后,我终于得出结论。
要使 DTS 值有效,它们必须以单调、一致的速率增加(假设时基和帧速率在混合过程中没有以某种方式改变),因此值本身并不那么重要。
此代码块直接来自 ffmpeg 库。它位于 mpegvideo_enc.c 的 2074-2080 行(为清楚起见重新格式化):
...
pkt->pts = s->current_picture.f->pts;
if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B)
{
if (!s->current_picture.f->coded_picture_number)
{
pkt->dts = pkt->pts - s->dts_delta;
}
else
{
pkt->dts = s->reordered_pts;
}
s->reordered_pts = pkt->pts;
...
如您所见,只有第一帧会进入 if (!s->current_picture.f->coded_picture_number) 语句,coded_picture_number 值为 0 . 后续每一帧都会进入else语句,设置当前DTS等于之前的PTS值。
因此,对于使用 MPEG-2 编码器的混合情况,这种行为似乎是正常的。 DTS 应该落后“1-cycle”。
关于c - DTS 和 PTS 是不同的,尽管没有 B 帧 (ffmpeg),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47477483/
我正在尝试使用 ldash 等选项和 http_opts ,正如 dash muxer 文档所描述的,但 FFmpeg 无法识别它们。我正在使用最新发布的 ffmpeg v4.2.2 版本。我在 ff
假设我们有许多想要与 -vcodec 副本(或等效语法)合并的视频记录。无需重新编码,不会损失质量。并且很少有记录(minor set),有另外的编解码器,参数等等。所以我们可以使用 ffprobe
有没有办法安装 ffmpeg 没有root访问权限?使用 ./configure 无法做到这一点来自 git 克隆 git://source.FFmpeg.org/fFFmpeg.git 最佳答案 是
在应用程序中直接使用 FFmpeg 与使用 Ffmpeg 命令行有什么区别? 最佳答案 没有:FFmpeg 命令行只是一个使用 FFmpeg API 的应用程序。当然,在使用该应用程序时,您仅限于已实
我正在使用以下命令对文件(下面的媒体信息)进行编码: ffmpeg -i AHomeMovie.mkv -map 0 -c copy -c:v libx264 -preset veryslow -cr
我正在制作一张圣诞贺卡,我需要将视频嵌入到右侧(边框内)的卡片中,并在左侧显示一些文本。 为简单起见,假设我有一个带有透明孔的盒子。我想在那个洞里显示视频。 我正在使用 ffmpeg-python很高
我正在使用 laravel ffmpeg 为视频创建缩略图,但是当我运行代码时,它返回给我 Call to undefined method FFMpeg\FFMpeg::fromDisk() 我不知
我为我的 nvidia 下载了 cuda 驱动程序 但它仍然不使用我的 GPU,它仍然使用 cpu。 我怎样才能让它使用GPU。 我也听说过硬件加速,但那不起作用。 它必须是 h.264 最佳答案 你
尝试剪切视频的多个部分时,我遵循此问题的解决方案 Cut multiple parts of a video with ffmpeg .但问题是,如果我剪切多次(比如大约 20 次或更多),视频和音频
所以我最近开始在我打算在商业上分发的应用程序中实现 ffmpeg。而且我很难理解整个许可过程。 我见过的最常回答的问题似乎是关于 x264,它需要 x264.org 的付费许可才能在商业上使用它(对吗
我使用 ffmpeg 更改视频文件的分辨率,转换到另一个位置后,视频持续 0 秒,但最初持续 2 分钟 我的ffmepg代码: ffmpeg -i input.mp4 -filter:v scale=
如上: FFMPEG 不支持在没有第三部分库的情况下加载外部过滤器是否有特定原因? (像弗莱0r) 我必须重新编译整个包来添加一个新的过滤器! 最佳答案 只有开发人员可以肯定地回答,但我会冒安全风险和
我收到了一个编码器,我需要用 FFMPEG 编译,我是新手,所以我不知道如何用 ffmpeg 添加/编译它。编码器是JSV,我的服务器是ubuntu 14.04。 我已经开始阅读这篇 https://
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许在 Stack Overflow 上提出有关通用计算硬件和软件的问题。您可以编辑问题,使其成为
我正在制作一个利用 ffmpeg 重新混合和转码视频文件的程序。我想使用 ffmpeg -codecs和 ffmpeg -formats (或通过 ffmpeg 可用的任何其他命令)来检查我可以在哪些
这个问题在这里已经有了答案: ffmpeg moving text drawtext (1 个回答) 3年前关闭。 我正在使用此命令使用 ffmpeg 将文本从一个地方移动到另一个地方 ffmpeg
为什么 ffmpeg/ffprobe 为流和整个文件提供不同的比特率值? 当我使用 ffprobe 分析 mp3 文件时,它会在第一行和第二行给出不同的比特率。 有谁知道,有什么区别? // File
如何在ffmpeg中使用drawtext在视频上绘制多色文本? 示例:我想突出句子中的专有名词, “XYZ公司股价上涨91%” 高亮 XYZ 白色 黄色 用绿色突出显示 91% 如果您有任何其他方法不
我想让我的不和谐机器人播放音乐,但我不断收到“找不到 FFMPEG”错误。 我的机器人主要是由 ping 制成的,所以我不会上传那部分。音乐代码应该是这个。 const Discord = requi
我需要帮助在 ffmpeg drawtext 过滤器中正确/(完全)显示德语变音符号“äüö”。我现在不能说我的无能是由于缺乏 ffmpeg 专业知识或机器配置,还是两者兼而有之。非常感谢您的意见。
我是一名优秀的程序员,十分优秀!