No sound from video file using default image component

Hi @joinlook,

David’s example is based on HTML video tags, so there may be an issue with browser support. Some video formats are not supported by all browsers, so transcoding might solve your problem.

Mozilla have a table showing which formats are supported by which browsers:

The most well-supported format seems to be H.264 video, AAC audio, in MPEG-4, as suggested by the table and by this StackOverflow answer.

ffmpeg

We’ve installed ffmpeg and python-ffmpeg in Server Modules.

It’s a library for doing all sorts of operations with video files, including transcoding into different formats.

Here are some links to docs for ffmpeg and python-ffmpeg

files in Server Modules

ffmpeg uses the filesystem, so we’ve implemented ways to create temporary files from Media objects and to create empty temporary files (read more in the reference docs).

Transcoding example

Here’s a function that transcodes an existing video in Data Tables to .mp4:

def transcode_to_mp4():
  """Transcode a video to mp4 with H.264 video and aac audio."""

  # Get the video out of the Data Table
  video = app_tables.videos.search()[0]
  media_obj = video['contents']
  
  with anvil.media.TempFile(media_obj) as input_file, anvil.media.TempFile() as output_file:
    # Transcode the video
    stream = ffmpeg.input(input_file)
    stream = ffmpeg.output(stream, output_file, f='mp4', acodec='aac', vcodec='libx264')
    ffmpeg.run(stream)

    # Create a Media object from the output file, and store it in Data Tables
    converted_video = anvil.media.from_file(
      output_file, mime_type='video/mp4', name='foo.mp4'
    )
    app_tables.videos.add_row(
      contents=converted_video, name='foo.mp4'
    )

I tried this on a .mov file and the size reduced from 4.8MB to 721kB, so you’ll get smaller videos too.

Let me know how you get on!