如何将具有不同帧分辨率的VP8轨道转换为h264 [英] How to convert VP8 track with different frame resolution to h264

查看:982
本文介绍了如何将具有不同帧分辨率的VP8轨道转换为h264的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有VP8轨道的.webm文件,通过外部服务(TokBox Archiving)从WebRTC流中记录。流是自适应的,因此轨道中的每个帧可以具有不同的分辨率。大多数播放器(在webkit浏览器中)使用轨道描述(总是640x480)的视频分辨率,并将帧缩放到此分辨率。 Firefox和VLC播放器分别使用真实的帧分辨率,更改视频分辨率。



我想实现2个目标:


  1. 在Internet Explorer 9+中播放此视频,无需额外的插件安装。

  2. 将帧分辨率更改为一个固定分辨率,因此视频将在不同的浏览器中看起来相同。

所以,我的计划是:





  • 查找图像的最大宽度和最大高度

  • 向图像添加黑色填充,因此较小的帧将位于新帧(大小为MAX_WIDHTxMAX_HEIGHT)的中心。

  • 将图像合并到h264轨道,使用ffmpeg



是否正确?我该如何实现?这个算法可以用某种方式进行优化吗?



我尝试过ffmpeg来提取图像,但是它并不能解析实际的帧分辨率,而是使用轨道头的分辨率。
我认为一些libwebm函数可以帮助我(解析帧头并提取图像)。也许有人有一些代码片段来执行此操作?



示例.webm(下载源码,不要播放google转换版本): https://drive.google.com/file/d/0BwFZRvYNn9CKcndhMzlVa0psX00/view?usp=sharing



来自TokBox支持的自适应流的官方描述: https://support.tokbox.com/hc/en-us/community/posts/ 206241666 - 存档视频分辨率应为720x1280但报告为640x480

解决方案

如果您运行

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

您将得到如下输出:

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

左列是每个帧的实际宽度,右列具有高度。然后,您可以检查每列中的最大值,以用于画布大小。



然后运行

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

其中MAXW和MAXH应替换为您发现的值。


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:

  • extract frames from source webm file to images with real frame resolution (e.g. PNG or BMP) (how could I do that?)
  • find max width and max height of images
  • add black padding to images, so smaller frames will be in the center of a new frame (of size MAX_WIDHTxMAX_HEIGHT)
  • combine images to h264 track using ffmpeg

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

解决方案

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.

这篇关于如何将具有不同帧分辨率的VP8轨道转换为h264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆