0

What should I change about this command to make the videos reliably seekable in Chrome & Edge? At the moment if I try seeking even after the video has fully loaded, they either stay stubbornly where they are, or go back to the start. On these same videos Firefox allows me to scan through even before the video has fully loaded.

ffmpeg
    -i input.mp4
    -filter:v "scale=912:512"
    -c:a aac -b:a 128k
    -c:v libx264
    -pix_fmt yuv420p
    -preset medium
    -movflags +faststart
    output.mp4

Some of them work fine in Chrome & Edge, so I guess it depends on the exact format of the input video. What I need is a command that will make all output videos play nicely in all the mainstream browsers.

I wonder if it's something about keyframes/GOP size, but I'm a complete novice and don't know where to start with that - I'd like to be guided by someone with experience!

I've tried adding -g <framerate> -g <framerate*2>, -g <framerate/2> and none helped.

The videos are short clips of fast-moving action, if that's relevant to anyone's recommendations. They're supposed to be low-res previews, so filesize is a concern, but seekability is a must.

Thank you!

Edit, here's some outputs from one of the problem INPUT videos:

ffmpeg -i -vf vfrdet -an -f null -

  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.10
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '9976f813d3fc263f9af4322f6f476199.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2024-07-26T15:46:50.000000Z
    encoder         : Blackmagic Design DaVinci Resolve
  Duration: 00:00:18.12, start: 0.000000, bitrate: 11914 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1080x1920, 11588 kb/s, SAR 1:1 DAR 9:16, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      timecode        : 02:18:43:06
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 319 kb/s (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : TimeCodeHandler
      timecode        : 02:18:43:06
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.27.100
  Stream #0:0(und): Video: wrapped_avframe, yuv420p(tv, bt709, progressive), 1080x1920 [SAR 1:1 DAR 9:16], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      timecode        : 02:18:43:06
      encoder         : Lavc59.37.100 wrapped_avframe
frame=  453 fps=0.0 q=-0.0 Lsize=N/A time=00:00:18.12 bitrate=N/A speed=27.3x
video:209kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_vfrdet_0 @ 0x555e62f94e00] VFR:0.000000 (0/452)

ffprobe:

  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '9976f813d3fc263f9af4322f6f476199.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2024-07-26T15:46:50.000000Z
    encoder         : Blackmagic Design DaVinci Resolve
  Duration: 00:00:18.12, start: 0.000000, bitrate: 11914 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1080x1920, 11588 kb/s, SAR 1:1 DAR 9:16, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      timecode        : 02:18:43:06
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 319 kb/s (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
      creation_time   : 2024-07-26T15:46:50.000000Z
      handler_name    : TimeCodeHandler
      timecode        : 02:18:43:06
Unsupported codec with id 0 for input stream 2

So, not VFR. I wonder if it's about that "Data" stream...

1 Answers1

1

This was a classic x/y problem. I assumed the issue was with the video file itself, but in fact it was elsewhere.

Rather than serving <video src="myfile.mp4"> I'm serving <video src="video.php">, because I require access control. It never even occurred to me the issue laid here.

Those of you au fait with such things will have already realised my mistake - on that page, I didn't have a header('Accept-Ranges: bytes');

It was only an issue for some files in Chrome/Edge, and (from what I could see) no files in Firefox. I think now that that just means my Firefox is happy to buffer larger files than Chrome/Edge. None of the files are huge, typically ~2-3MB.

Now I've added that header (and, lazily for now, no code to actually handle partial requests), it is very happy to let me seek ahead/back.

We live and learn eh!