【问题标题】:avconv complains "non monotonically increasing dts to muxer in stream" when piping from libx264 on 14.04在 14.04 从 libx264 进行管道传输时,avconv 抱怨“非单调增加 dts 到流中的 muxer”
【发布时间】:2014-05-01 13:07:05
【问题描述】:

我有一段代码获取图像流并将它们写入使用 x264 编码和 avconv 的文件。相关位如下

// Setup encoder
sprintf(cmd, "avconv -i pipe: -vcodec copy %s", filename);
fp = popen(cmd, "w");
x264_param_default_preset(&params, "ultrafast", "stillimage,zerolatency");
params.i_fps_num = fps;
params.i_fps_den = 1;
x264_picture_alloc(&in, X264_CSP_I420, width, height);
params.i_csp = X264_CSP_I420;
in.img.i_csp = X264_CSP_I420;
x.params.b_vfr_input = 0;
in.i_pts = -1;
out.i_pts = -1;
params.i_width = width;
params.i_height = height;
encoder = x264_encoder_open(&params);

in.img.i_plane = 1;
in.img.i_stride[0] = width;
ret = x264_encoder_headers(encoder, &nals, &nheader);
header_size = nals[0].i_payload + nals[1].i_payload + nals[2].i_payload;
fwrite(nals[0].p_payload, header_size, 1, fp);

...
// Loop body
++in.i_pts;
frame_size = x264_encoder_encode(encoder, &nals, &num_nals, &in, &out);
fwrite(nals[0].p_payload, frame_size, 1, fp);

为了清楚起见,我省略了错误检查,但从未返回任何错误。事实上,在我将系统升级到 14.04 之前,这段代码运行良好(并且对于尚未升级的同事继续运行良好)。

现在只运行 Ubuntu 14.04,我从 avconv 得到这个输出

[h264 @ 0x98dec0] Estimating duration from bitrate, this may be inaccurate
Input #0, h264, from 'pipe:'
  Duration: N/A, bitrate: N/A
    Stream #0.0: Video: h264 (Constrained Baseline), yuv420p, 640x480, 25 fps, 25 tbr, 25 tbn, 60 tbc
Output #0, mp4, to '../reel/test.mp4':
  Metadata:
    encoder         : Lavf54.20.3
    Stream #0.0: Video: libx264, yuv420p, 640x480, q=2-31, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
[mp4 @ 0x1347800] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2 >= 2
av_interleaved_write_frame(): Invalid argument

尽管有错误,out.i_dts 确实在整个视频持续时间内单调增加(它始终等于 in.i_pts)。

我的一般假设是新版本的 avconv 对输入流的参数更严格,所以虽然我之前选择的参数可能有效,但现在它们不起作用。

另一个可能相关的好奇是 avconv 检测到流为 25 FPS,即使 x264 配置为输入 FPS 为 30。

编辑:一些进一步的信息,相同的 dts 错误 (2>=2) 发生与初始 pts 无关(输出 dts 与预期匹配)。

【问题讨论】:

  • 在 FFMPEG 给出这个错误后,我在 DDG 中发现了这个问题。问题是无效的字幕文件。其中一个字幕时间戳出现在前一个时间戳之前。我刚刚在文本编辑器中编辑了 VTT 文件并将其删除。无效的字幕恰好位于文件的开头。我相信错误的时间戳是由 x >= x 给出的,其中 x 是毫秒。

标签: c ubuntu x264 avconv ubuntu-14.04


【解决方案1】:

在“我不知道为什么应该修复它,但确实可以”的那一刻,将 -vcodec copy 更改为 -vcodec libx264(即使源编解码器已经是 libx264)修复了 dts 错误。

【讨论】:

  • 是的,这行得通。但可能 ffmpeg 现在不只是转储流,它还重新编码。
  • 使用 ffmpeg,我避免此错误(我只在 mp2 文件中遇到过)的解决方法是通过将以下内容添加到文件的开头(即删除前几毫秒) ffmpeg 命令行,以便文件下载时无需前千分之一秒(但在个别情况下可能需要尝试该值,因为我怀疑所有文件都相同,所以第一步是增加值从 0.015 到更大的数字):-ss 0.015
猜你喜欢
  • 2018-08-14
  • 1970-01-01
  • 2018-07-19
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多