Reputation: 453
I am trying to resize video file on Android device using FFmpeg. Remark: I cant use FFmpeg as binary - in my case it should be used as shared library (only FFmpeg C API is accessible).
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? Is there any other (easier?) way to resize video file using FFmpeg C API?
Upvotes: 0
Views: 2316
Reputation: 9375
From what I remember, sws_scale()
is the way to do this with recent FFmpeg versions. 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.
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). 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.
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. 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. 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.
Upvotes: 1