How to get video dimensions for an asset

I’m using resources.Get to grab an mp4 (to place in a <video> tag) and I need the aspect ratio to properly size it on the front-end with CSS/JS. With images this is straightforward — .Width and .Height. But is there any way I can get this same information for videos?

No. I would include the dimensions in the filename, then parse the filename.

└── post
    └── test
        ├── big-buck-bunny-1280x720.mp4
        ├── big-buck-bunny-640x360.mp4

This is ugly but works if the file name ends with -WIDTHxHEIGHT.mp4.

{{ range .Resources.Match "*.mp4" }}
  {{ $dims := split (index (split (index (last 1 (split .Name "-")) 0) ".") 0) "x" }}
  {{ $width := index $dims 0 }}
  {{ $height := index $dims 1 }}
{{ end }}

Got it, thank you. Hopefully the devs consider adding support for this in the future!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.