-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to specify output pixel format (#24)
- Loading branch information
Showing
11 changed files
with
90 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,43 @@ | ||
#include "video_converter.h" | ||
|
||
int video_converter_convert(AVFrame *src_frame, uint8_t *out_data[], int out_linesize[]) { | ||
int video_converter_convert(AVFrame *src_frame, AVFrame **dst_frame, enum AVPixelFormat out_format) { | ||
int ret; | ||
|
||
*dst_frame = av_frame_alloc(); | ||
if (!*dst_frame) { | ||
return -1; | ||
} | ||
|
||
(*dst_frame)->width = src_frame->width; | ||
(*dst_frame)->height = src_frame->height; | ||
(*dst_frame)->format = out_format; | ||
(*dst_frame)->pts = src_frame->pts; | ||
|
||
ret = av_frame_get_buffer(*dst_frame, 0); | ||
if (ret < 0) { | ||
return ret; | ||
} | ||
|
||
struct SwsContext *sws_ctx = | ||
sws_getContext(src_frame->width, src_frame->height, src_frame->format, src_frame->width, | ||
src_frame->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL); | ||
|
||
ret = av_image_alloc(out_data, out_linesize, src_frame->width, src_frame->height, | ||
AV_PIX_FMT_RGB24, 1); | ||
src_frame->height, out_format, SWS_BILINEAR, NULL, NULL, NULL); | ||
|
||
if (ret < 0) { | ||
return ret; | ||
} | ||
|
||
|
||
// is this (const uint8_t * const*) cast really correct? | ||
ret = sws_scale(sws_ctx, (const uint8_t *const *)src_frame->data, src_frame->linesize, 0, | ||
src_frame->height, out_data, out_linesize); | ||
src_frame->height, (*dst_frame)->data, (*dst_frame)->linesize); | ||
|
||
if (ret < 0) { | ||
av_freep(&out_data[0]); | ||
av_frame_free(dst_frame); | ||
sws_freeContext(sws_ctx); | ||
return ret; | ||
} | ||
|
||
sws_freeContext(sws_ctx); | ||
|
||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters