简体   繁体   English

使用FFmpeg C API调整视频大小

[英]Resize video using FFmpeg C API

I am trying to resize video file on Android device using FFmpeg. 我正在尝试使用FFmpeg在Android设备上调整视频文件的大小。 Remark: I cant use FFmpeg as binary - in my case it should be used as shared library (only FFmpeg C API is accessible). 备注:我不能将FFmpeg用作二进制文件-在我的情况下,应将其用作共享库(只能访问FFmpeg C API)。

I did not find any documentation regarding video resizing, however it looks like algorithm is following: 我没有找到有关视频大小调整的任何文档,但是看起来算法如下:

10 OPEN video_stream FROM video.mp4
20 READ packet FROM video_stream INTO frame
30 IF frame NOT COMPLETE GOTO 20
40 RESIZE frame
50 WRITE frame TO converted_video.mp4
60 GOTO 20

Should I use sws_scale function in order to resize frame? 我应该使用sws_scale函数来调整框架大小吗? Is there any other (easier?) way to resize video file using FFmpeg C API? 还有其他(更简便的方法)使用FFmpeg C API调整视频文件大小的方法吗?

From what I remember, sws_scale() is the way to do this with recent FFmpeg versions. 我记得, sws_scale()是使用最新的FFmpeg版本执行此操作的方式。 Despite the extra steps like preparing an SwsContext it's not that hard to use, and there are examples such as the tutorial on the site you referenced. 尽管准备了SwsContext这样的额外步骤并不难,但是在您引用的站点上还是有一些示例,例如教程。

Older versions also had an img_convert() function which was a bit simpler to use, and for a while it was still in the library but not in the usual headers -- it still worked if you supplied your own prototype (taken from an older version). 较旧的版本还具有img_convert()函数,该函数使用起来更简单,并且有一段时间仍在库中,但不在通常的头文件中-如果您提供自己的原型(从较旧的版本中获取),它仍然可以工作)。 This may still work, if you're willing to chance it -- though I haven't tried it with the latest versions. 如果您愿意尝试,这可能仍然有效-尽管我还没有尝试使用最新版本。 It's probably safer and better to use sws_scale() , though. 不过,使用sws_scale()可能更安全更好。

It's also possible to handle the scaling outside of the FFmpeg libraries, but it's likely more trouble than it's worth in this case. 也可以在FFmpeg库之外处理扩展,但是在这种情况下,这可能比值得的麻烦更多。 The Doxygen documentation for the libraries describes the AVPicture structure well enough to work with it directly, or transfer the image to/from some other form. 库的Doxygen文档很好地描述了AVPicture结构,可以直接使用它,也可以将图像与其他形式进行传输。 The main difficulty is ensuring you can work with or convert the color/pixel format used -- if you would have to convert it to another format, you should use sws_scale() for at least that much, if not the resizing as well. 主要困难在于确保可以使用或转换所使用的颜色/像素格式-如果必须将其转换为另一种格式,则应至少使用sws_scale()进行调整,如果不能调整大小的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM