Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
Decode MP4 video with VideoDecoder

I want to make a web app, which extracts each frame of a MP4 file, and saves it as a PNG. Setting the currentTime of a <video> element and drawing it into a canvas does not work, as it often skips some frames.

I am using the VideoDecoder. It has a decode method, which receives an EncodedVideoChunk, that contains an array of bytes - a "chunk of a video".

I parsed this MP4 file to get "moov" - "trak" - 0 - "mdia" - "minf" - "stbl". I slice a piece of the MP4 file from stbl.stco[0], of a length stbl.stsz[0] (80 and 42548 in this case). The bytes are

[0, 0, 0, 2,   9, 16, 0, 0,   166, 42, 37, 136,   128, 67, 255, 235, ...]

I still see an error message:

Failed to execute 'decode' on 'VideoDecoder': A key frame is required after configure() or flush().

What am I doing wrong? How can I find a right piece of data, that should be given to the VideoDecoder?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

All my steps were correct. The problem was, that the VideoDecoder missed the description parameter during configure(). Seems like no MP4 file can be decoded without it.

Use the sequence of 40 bytes at stbl.stsd.extraData.avcC as a value of the description.

about 4 years ago · Santiago Trujillo Report

0

The key frame error refers to the EncodedVideoChunk.type field, which must be "key" at the start of decoding. It's assumed that this information comes from the media container.

This is independent of the format of the bitstream; if the bitstream is Annex B then you should not set a description, and if the stream is AVC (used in MP4), you should set description.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!