如何摆脱ffmpeg pts没有价值错误


12

我想将AVI文件转换为MP4文件。视频流是XVID,而音频流是MP3。

问题是生成的MP4文件无法在Mac上的QuickTime Player中播放。它在VLC上播放。虽然这不是一个交易破坏者,但我想知道如何导致这些问题。

该命令及其输出如下:

$ ffmpeg -i 103.avi -codec copy -f mp4 103.mp4

ffmpeg version N-60163-g78a9f18 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 25 2014 14:03:47 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  configuration: 
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.100 / 55. 49.100
  libavformat    55. 26.100 / 55. 26.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.101 /  4.  1.101
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
Input #0, avi, from '103.avi':
  Metadata:
    encoder         : Lavf55.26.100
  Duration: 00:49:36.43, start: 0.000000, bitrate: 986 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 512x368 [SAR 1:1 DAR 32:23], 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 121 kb/s
Output #0, mp4, to '103.mp4':
  Metadata:
    encoder         : Lavf55.26.100
    Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 512x368 [SAR 1:1 DAR 32:23], q=2-31, 11988 tbn, 23.98 tbc
    Stream #0:1: Audio: mp3 (i[0][0][0] / 0x0069), 48000 Hz, stereo, 121 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x7fe5ca01fa00] pts has no value
    Last message repeated 1555 times
[mp4 @ 0x7fe5ca01fa00] pts has no value9kB time=00:01:17.70 bitrate=1458.0kbits/s    
    Last message repeated 1041 times
[mp4 @ 0x7fe5ca01fa00] pts has no value49kB time=00:02:08.42 bitrate=1661.6kbits/s    
    Last message repeated 1906 times
[mp4 @ 0x7fe5ca01fa00] pts has no value53kB time=00:03:40.39 bitrate=1537.1kbits/s    
    Last message repeated 2136 times
[mp4 @ 0x7fe5ca01fa00] pts has no value93kB time=00:05:35.80 bitrate=1307.4kbits/s    
    Last message repeated 3519 times
[mp4 @ 0x7fe5ca01fa00] pts has no value32kB time=00:08:32.18 bitrate=1150.5kbits/s    
    Last message repeated 2813 times
[mp4 @ 0x7fe5ca01fa00] pts has no value88kB time=00:11:18.01 bitrate=1090.9kbits/s    
    Last message repeated 3057 times
[mp4 @ 0x7fe5ca01fa00] pts has no value39kB time=00:14:00.42 bitrate=1028.7kbits/s    
    Last message repeated 3731 times
[mp4 @ 0x7fe5ca01fa00] pts has no value11kB time=00:16:57.72 bitrate= 991.0kbits/s    
    Last message repeated 2658 times
[mp4 @ 0x7fe5ca01fa00] pts has no value76kB time=00:19:25.70 bitrate= 978.1kbits/s    
    Last message repeated 2167 times
[mp4 @ 0x7fe5ca01fa00] pts has no value70kB time=00:21:17.11 bitrate= 990.8kbits/s    
    Last message repeated 3663 times
[mp4 @ 0x7fe5ca01fa00] pts has no value20kB time=00:24:42.06 bitrate= 938.1kbits/s    
    Last message repeated 2335 times
[mp4 @ 0x7fe5ca01fa00] pts has no value79kB time=00:26:53.90 bitrate= 950.6kbits/s    
    Last message repeated 4153 times
[mp4 @ 0x7fe5ca01fa00] pts has no value06kB time=00:30:59.94 bitrate= 895.4kbits/s    
    Last message repeated 3168 times
[mp4 @ 0x7fe5ca01fa00] pts has no value87kB time=00:33:35.43 bitrate= 888.5kbits/s    
    Last message repeated 1565 times
[mp4 @ 0x7fe5ca01fa00] pts has no value02kB time=00:34:56.47 bitrate= 914.0kbits/s    
    Last message repeated 2792 times
[mp4 @ 0x7fe5ca01fa00] pts has no value10kB time=00:37:34.42 bitrate= 909.6kbits/s    
    Last message repeated 2503 times
[mp4 @ 0x7fe5ca01fa00] pts has no value49kB time=00:39:48.76 bitrate= 916.2kbits/s    
    Last message repeated 1714 times
[mp4 @ 0x7fe5ca01fa00] pts has no value70kB time=00:41:16.64 bitrate= 928.7kbits/s    
    Last message repeated 2060 times
[mp4 @ 0x7fe5ca01fa00] pts has no value79kB time=00:43:04.79 bitrate= 935.2kbits/s    
    Last message repeated 1349 times
[mp4 @ 0x7fe5ca01fa00] pts has no value46kB time=00:44:06.57 bitrate= 951.6kbits/s    
    Last message repeated 2354 times
[mp4 @ 0x7fe5ca01fa00] pts has no value67kB time=00:45:56.33 bitrate= 967.9kbits/s    
    Last message repeated 2668 times
[mp4 @ 0x7fe5ca01fa00] pts has no value50kB time=00:48:14.72 bitrate= 964.9kbits/s    
    Last message repeated 1655 times
frame=71363 fps=5738 q=-1.0 Lsize=  355528kB time=00:49:36.43 bitrate= 978.5kbits/s    
video:309630kB audio:44196kB subtitle:0 global headers:0kB muxing overhead 0.481011%

如果我再次复制mp4,我会得到以下结果:

$ ffmpeg -i 103.mp4 -codec copy -f mp4 103-new.mp4

ffmpeg version N-60163-g78a9f18 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 25 2014 14:03:47 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  configuration: 
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.100 / 55. 49.100
  libavformat    55. 26.100 / 55. 26.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.101 /  4.  1.101
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
[mpeg4 @ 0x7fcddb018000] Video uses a non-standard and wasteful way to store B-frames ('packed B-frames'). Consider using a tool like VirtualDub or avidemux to fix it.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '103.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf55.26.100
  Duration: 00:49:36.44, start: 0.000000, bitrate: 978 kb/s
    Stream #0:0(und): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 512x368 [SAR 1:1 DAR 32:23], 852 kb/s, 23.98 fps, 23.98 tbr, 11988 tbn, 23.98 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, s16p, 121 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, mp4, to '103-new.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf55.26.100
    Stream #0:0(und): Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 512x368 [SAR 1:1 DAR 32:23], q=2-31, 852 kb/s, 23.98 fps, 11988 tbn, 11988 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (i[0][0][0] / 0x0069), 48000 Hz, stereo, 121 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=71363 fps=5505 q=-1.0 Lsize=  355528kB time=00:49:36.43 bitrate= 978.5kbits/s    
video:309567kB audio:44196kB subtitle:0 global headers:0kB muxing overhead 0.498835%

Answers:


22

首先,介绍存在此错误的原因。 AVI不支持可变帧速率视频。因此,在文件开头的某处,记录帧速率。 mp4确实支持可变帧速率,因此需要知道每帧的持续时间。在ffmpeg中,固定帧速率视频的pts生成通常由解码器处理。但通过使用 -codec copy,你绕过了解码器。

解决方案是指定 -fflags +genpts (必须在指定输入文件之前 -i )。


非常感谢背景细节和建议的解决方案。这解释了一下。所以像 ffmpeg -i 103.avi -fflags +genpts -codec copy -f mp4 103.mp4?我实际上在发布之前尝试过,但它没有解决我的问题。你知道怎么用 avidemux 解决第二个日志建议的这个问题?
Umar Farooq Khawaja

5
@UmarFarooqKhawaja -fflags +genpts 需要先去 -i
Andrew Marshall

它工作正常,但是,由此产生的mp4文件在快速播放器中是不可寻的..任何线索..?
Tony Thomas

1
在我看来,这是因为快速播放器是愚蠢的(更准确的描述是它可能缺少一个索引)。
Wyatt8740

6
我知道这是一个相对陈旧的问题/答案。我遇到它正在寻找解决同样问题的方法。不幸, -fflags +genpts 没有解决问题。我得到完全相同的错误。我正在运行OSX并从源代码编译ffmpeg。
Aleks G

1

我发现硬编码帧速率解决了这个问题:

ffmpeg -r 25 -i test.h264 -codec copy testout25.mp4

(我仍然收到警告“在流0中的数据包中未设置时间戳”,但是在Mac上的Quicktime Player中可以查找生成的文件。)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.