ffmpeg 写入无效的 HLS 视频长度

ffmpeg 写入无效的 HLS 视频长度

我正在使用ffmpeg生成hls文件,如下所示:

ffmpeg 
   -i input.mp4 
   -y -preset slow 
   -c:v h264 
   -g 48 -keyint_min 48 
   -sc_threshold 0 
   -profile:v main 
   -crf 25 
   -c:a aac -ar 48000 -b:a 128k 
   -f hls -hls_list_size 0 -hls_time 4 -hls_playlist_type vod 
   -hls_segment_filename temp.%d.ts 
   -master_pl_name temp.v%v.m3u8 
   -shortest 
   tempName2.m3u8

这可行,但是视频在 iOS avplayer 中显示错误结尾(在 VLC 和 Quicktime 中正常运行)。

原始视频在这里:

https://storage.googleapis.com/easyeasy-assets-devel/challenges/nem-kri-nfns/mayo-1/step-1.mp4

处理后的视频在这里:

https://storage.googleapis.com/easyeasy-assets-devel/challenges/nem-kri-nfns/mayo-1/processed/step-1.m3u8

hls 块的最后一个文件是这样的:

https://storage.googleapis.com/easyeasy-assets-devel/challenges/nem-kri-nfns/mayo-1/processed/step-1.1.ts

当使用 ffmpeg 探测时我可以看到这一点:

Input #0, mpegts, from 'tempName.1.ts':
  Duration: 00:00:03.26, start: 7.176000, bitrate: 1901 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1080x1920, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 118 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: wrapped_avframe, yuv420p, 1080x1920, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.91.100 wrapped_avframe
    Stream #0:1(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc58.91.100 pcm_s16le
frame=   80 fps=0.0 q=-0.0 Lsize=N/A time=00:00:03.28 bitrate=N/A speed=28.7x

请注意:

  Duration: 00:00:03.26, start: 7.176000, bitrate: 1901 kb/s

进而:

frame=   80 fps=0.0 q=-0.0 Lsize=N/A time=00:00:03.28 bitrate=N/A speed=28.7x

通过 ffprobe,我看到了完全不同的东西:

Input #0, mpegts, from 'tempName.1.ts':
  Duration: 00:00:03.26, start: 7.176000, bitrate: 1901 kb/s
...
[FORMAT]
...
duration=3.264000

我做错了什么?该-shortest参数似乎没有任何效果。

相关内容