【问题标题】:Quicktime cannot play recorded mp4 video fileQuicktime 无法播放录制的 mp4 视频文件
【发布时间】:2014-02-01 08:21:55
【问题描述】:

我有一个与 mp4 相关的问题。我不太擅长视频处理相关的东西。我们遇到了通过 HTTP Live Streaming (HLS) 从实时流中记录的图像文件的问题。 HLS 块只是放在一起并作为 .mp4 文件保存在文件系统中。此文件无法使用 Apple QuickTime 播放。 VLC 可以播放。但前提是能用 QuickTime 播放。

但是,我找到了一个可行的解决方案。当我使用 ffmpeg 命令 -reset_timestamps 时,可以使用 QuickTime 播放视频文件。我还看到了哪些参数发生了变化。这是起始值。

使用命令前:

ffmpeg -i recorded_file.mp4 

ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan  9 2014 09:06:57 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[h264 @ 0x7fcb7b015a00] non-existing SPS 2 referenced in buffering period
[h264 @ 0x7fcb7b015a00] non-existing PPS referenced
[h264 @ 0x7fcb7b015a00] non-existing SPS 2 referenced in buffering period
[h264 @ 0x7fcb7b015a00] non-existing PPS 0 referenced
[h264 @ 0x7fcb7b015a00] decode_slice_header error
[h264 @ 0x7fcb7b015a00] no frame!
[mpegts @ 0x7fcb7b004a00] max_analyze_duration 5000000 reached at 5013333 microseconds
[mpegts @ 0x7fcb7b004a00] Could not find codec parameters for stream 2 (Unknown: none ([21][0][0][0] / 0x0015)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[NULL @ 0x7fcb7b016a00] start time is not set in estimate_timings_from_pts
Input #0, mpegts, from 'recorded_file.mp4':
  Duration: 00:25:00.01, start: 68428.580933, bitrate: 1499 kb/s
  Program 1 
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1024x576 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 124 kb/s
    Stream #0:2[0x102]: Unknown: none ([21][0][0][0] / 0x0015)

命令的使用:

ffmpeg -i recorded_file.mp4 output.mp4 -reset_timestamps 0

使用命令后的文件:

ffmpeg -i output.mp4 

ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan  9 2014 09:06:57 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.63.104
  Duration: 00:25:00.04, start: 0.021333, bitrate: 1358 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1024x576 [SAR 1:1 DAR 16:9], 1224 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s
    Metadata:
      handler_name    : SoundHandler

很多文本输出发生变化,但持续时间、开始和比特率的行很有趣,因为开始值设置为接近零。

Duration: 00:25:00.04, start: 0.021333, bitrate: 1358 kb/s

所以使用这个解决方案就足够了。问题是,我不能在下载文件的解决方案中使用 ffmpeg(它适用于 Android)。所以我尝试在Java中找到一种方法来做到这一点。但是,由于我在视频处理方面没有太多经验,所以我无法弄清楚这个 ffmpeg 命令是做什么的,因此不知道从哪个方向寻找 Java 解决方案。

是否有一个库可以在 Java 中执行相同的操作,或者是否有一种简单的方法可以在 Java 中自己执行(例如调整文件时间戳)?

感谢您的帮助!

编辑:现在显示整个控制台输出,而不仅仅是其中的一部分。

【问题讨论】:

  • 您应该包含 ffmpeg 编码命令的完整控制台输出。

标签: java android video ffmpeg mp4


【解决方案1】:

我的 FFMPEG 转换 MP4 以在 QuickTime 中播放的修复方法是将 -pix_fmt yuv420p 添加到参数中。

发现于https://trac.ffmpeg.org/wiki/Encode/H.264#FAQ:

为愚蠢的玩家编码

您可能需要使用 -pix_fmt yuv420p 才能让您的输出在 QuickTime 和大多数其他播放器中工作。这些播放器仅支持对 H.264 视频进行 4:2:0 色度二次采样的 YUV 平面色彩空间。否则,根据您的来源,ffmpeg 可能会输出为可能与这些播放器不兼容的像素格式。

如果有兴趣,这是我使用的整个 FFMPEG 命令:

ffmpeg -i $1 \
  -acodec libfaac -b:a 96k \
  -vcodec libx264 -b:v 1.5M \
  -pix_fmt yuv420p \
  -threads 0 -s $2 $destination/$filename.mp4

【讨论】:

  • 感谢您的解决方案。我想我已经找到了问题的真正原因(见我上面的回答)。
【解决方案2】:

我自己找到了解决方案。问题不在于时间戳错误,而在于输入文件是没有容器的 MPEG-TS 流。由于它的容器以 .mp4 结尾,因此 Qucktime 无法播放它,因为文件扩展名错误。当我执行 ffmpeg 命令时,它会自动将流包装到 .mp4 容器中。所以之后Quicktime可以播放它,因为文件格式是正确的。将输入文件重命名为 .ts(MPEG-TS 流)文件扩展名后,Quicktime 也可以播放输入文件。

事实上,我的带有 -reset_timestamps 的命令解决了问题,这让我做出了错误的假设,即时间戳就是问题所在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-04
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2018-01-20
    • 1970-01-01
    相关资源
    最近更新 更多