forked from FFmpeg/FFmpeg
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lavfi: port libmpcodecs remove-logo filter
The code is based on the remove-logo filter in MPlayer/libmpcodecs, by Robert Edele, relicensed to LGPL with consent of the author. Address trac issue FFmpeg#249.
- Loading branch information
Showing
11 changed files
with
832 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* This file is part of FFmpeg. | ||
* | ||
* FFmpeg is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* FFmpeg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FFmpeg; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "libavutil/imgutils.h" | ||
#include "lavfutils.h" | ||
|
||
int ff_load_image(uint8_t *data[4], int linesize[4], | ||
int *w, int *h, enum PixelFormat *pix_fmt, | ||
const char *filename, void *log_ctx) | ||
{ | ||
AVInputFormat *iformat = NULL; | ||
AVFormatContext *format_ctx; | ||
AVCodec *codec; | ||
AVCodecContext *codec_ctx; | ||
AVFrame *frame; | ||
int frame_decoded, ret = 0; | ||
AVPacket pkt; | ||
|
||
av_register_all(); | ||
|
||
iformat = av_find_input_format("image2"); | ||
if ((ret = avformat_open_input(&format_ctx, filename, iformat, NULL)) < 0) { | ||
av_log(log_ctx, AV_LOG_ERROR, | ||
"Failed to open input file '%s'\n", filename); | ||
return ret; | ||
} | ||
|
||
codec_ctx = format_ctx->streams[0]->codec; | ||
codec = avcodec_find_decoder(codec_ctx->codec_id); | ||
if (!codec) { | ||
av_log(log_ctx, AV_LOG_ERROR, "Failed to find codec\n"); | ||
ret = AVERROR(EINVAL); | ||
goto end; | ||
} | ||
|
||
if ((ret = avcodec_open2(codec_ctx, codec, NULL)) < 0) { | ||
av_log(log_ctx, AV_LOG_ERROR, "Failed to open codec\n"); | ||
goto end; | ||
} | ||
|
||
if (!(frame = avcodec_alloc_frame()) ) { | ||
av_log(log_ctx, AV_LOG_ERROR, "Failed to alloc frame\n"); | ||
ret = AVERROR(ENOMEM); | ||
goto end; | ||
} | ||
|
||
ret = av_read_frame(format_ctx, &pkt); | ||
if (ret < 0) { | ||
av_log(log_ctx, AV_LOG_ERROR, "Failed to read frame from file\n"); | ||
goto end; | ||
} | ||
|
||
ret = avcodec_decode_video2(codec_ctx, frame, &frame_decoded, &pkt); | ||
if (ret < 0 || !frame_decoded) { | ||
av_log(log_ctx, AV_LOG_ERROR, "Failed to decode image from file\n"); | ||
goto end; | ||
} | ||
ret = 0; | ||
|
||
*w = frame->width; | ||
*h = frame->height; | ||
*pix_fmt = frame->format; | ||
|
||
if ((ret = av_image_alloc(data, linesize, *w, *h, *pix_fmt, 16)) < 0) | ||
goto end; | ||
ret = 0; | ||
|
||
av_image_copy(data, linesize, frame->data, frame->linesize, *pix_fmt, *w, *h); | ||
|
||
end: | ||
if (codec_ctx) | ||
avcodec_close(codec_ctx); | ||
if (format_ctx) | ||
avformat_close_input(&format_ctx); | ||
av_freep(&frame); | ||
|
||
if (ret < 0) | ||
av_log(log_ctx, AV_LOG_ERROR, "Error loading image file '%s'\n", filename); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of FFmpeg. | ||
* | ||
* FFmpeg is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* FFmpeg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FFmpeg; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
/** | ||
* @file | ||
* Miscellaneous utilities which make use of the libavformat library | ||
*/ | ||
|
||
#ifndef AVFILTER_LAVFUTILS_H | ||
#define AVFILTER_LAVFUTILS_H | ||
|
||
#include "libavformat/avformat.h" | ||
|
||
/** | ||
* Load image from filename and put the resulting image in data. | ||
* | ||
* @param w pointer to the width of the loaded image | ||
* @param h pointer to the height of the loaded image | ||
* @param pix_fmt pointer to the pixel format of the loaded image | ||
* @param filename the name of the image file to load | ||
* @param log_ctx log context | ||
* @return 0 in case of success, a negative error code otherwise. | ||
*/ | ||
int ff_load_image(uint8_t *data[4], int linesize[4], | ||
int *w, int *h, enum PixelFormat *pix_fmt, | ||
const char *filename, void *log_ctx); | ||
|
||
#endif /* AVFILTER_LAVFUTILS_H */ |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This file is part of FFmpeg. | ||
* | ||
* FFmpeg is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* FFmpeg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FFmpeg; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "libavutil/imgutils.h" | ||
#include "lswsutils.h" | ||
|
||
int ff_scale_image(uint8_t *dst_data[4], int dst_linesize[4], | ||
int dst_w, int dst_h, enum PixelFormat dst_pix_fmt, | ||
uint8_t * const src_data[4], int src_linesize[4], | ||
int src_w, int src_h, enum PixelFormat src_pix_fmt, | ||
void *log_ctx) | ||
{ | ||
int ret; | ||
struct SwsContext *sws_ctx = sws_getContext(src_w, src_h, src_pix_fmt, | ||
dst_w, dst_h, dst_pix_fmt, | ||
SWS_BILINEAR, NULL, NULL, NULL); | ||
if (!sws_ctx) { | ||
av_log(log_ctx, AV_LOG_ERROR, | ||
"Impossible to create scale context for the conversion " | ||
"fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | ||
av_get_pix_fmt_name(src_pix_fmt), src_w, src_h, | ||
av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h); | ||
ret = AVERROR(EINVAL); | ||
goto end; | ||
} | ||
|
||
if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 16)) < 0) | ||
goto end; | ||
ret = 0; | ||
sws_scale(sws_ctx, src_data, src_linesize, 0, src_h, dst_data, dst_linesize); | ||
|
||
end: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of FFmpeg. | ||
* | ||
* FFmpeg is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* FFmpeg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with FFmpeg; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
/** | ||
* @file | ||
* Miscellaneous utilities which make use of the libswscale library | ||
*/ | ||
|
||
#ifndef AVFILTER_LSWSUTILS_H | ||
#define AVFILTER_LSWSUTILS_H | ||
|
||
#include "libswscale/swscale.h" | ||
|
||
/** | ||
* Scale image using libswscale. | ||
*/ | ||
int ff_scale_image(uint8_t *dst_data[4], int dst_linesize[4], | ||
int dst_w, int dst_h, enum PixelFormat dst_pix_fmt, | ||
uint8_t *const src_data[4], int src_linesize[4], | ||
int src_w, int src_h, enum PixelFormat src_pix_fmt, | ||
void *log_ctx); | ||
|
||
#endif /* AVFILTER_LSWSUTILS_H */ |
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
Oops, something went wrong.