videoffmpegtokboxvp8matroska

How to convert VP8 track with different frame resolution to h264


I have a .webm file with VP8 track, recorded from WebRTC stream by external service (TokBox Archiving). The stream is adaptive, so each frame in track could have different resolution. Most players (in webkit browsers) use video resolution from track description (which is always 640x480) and scale frames to this resolution. Firefox and VLC player uses real frame resolution, changing video resolution respectively.

I want to achieve 2 goals:

  1. play this video in Internet Explorer 9+ without additional plugin installation.
  2. change frames resolution to one fixed resolution, so the video will look identically in different browsers.

So, my plan is:

Is all correct? How can I achieve this? Can this algorithm be optimized some way?

I tried ffmpeg to extract images, but it does not parse real frame resolution, using resolution from track header. I think some libwebm functions can help me (to parse frame headers and extract images). Maybe someone has some code snippets to do this?

Example .webm (download source, do not play google-converted version): https://drive.google.com/file/d/0BwFZRvYNn9CKcndhMzlVa0psX00/view?usp=sharing

Official description of adaptive stream from TokBox support: https://support.tokbox.com/hc/en-us/community/posts/206241666-Archived-video-resolution-is-supposed-to-be-720x1280-but-reports-as-640x480


Solution

  • If you run

    ffprobe -show_entries frame=width,height -of compact=p=0:nk=1 video.webm
    

    you will get an output that looks like this:

    1254|800
    1058|800
    890|800
    774|800
    672|800
    

    The left column is each frame's actual width and the right column has the height. You can then check the max values in each column, to use for canvas size.

    Then run

    ffmpeg -i video.webm -vf pad=MAXW:MAXH:(MAXW-iw)/2:(MAXH-ih)/2 out.mp4
    

    where MAXW and MAXH should be replaced with the values you discovered.