Re: [FFmpeg-soc] [PATCH] updated! vf_overlay alpha patch and watermarking using PNG with alpha
On date Tuesday 2009-12-01 00:57:59 +0100, Stefano Sabatini encoded: On date Tuesday 2009-12-01 00:50:50 +0100, Vitor Sessak encoded: [...] I'm fine with committing the patch to soc if tested, even better would be to try to push the filter to the main repo. Does someone want to volunteer for this? A somehow tinied-up version which can be used as a base for SVN inclusion, I believe we should get rid of the blend parameter, also the expression evaluation may stay in a successive commit. Regards. /* * copyright (c) 2007 Bobby Bingham * * 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 libavfilter/vf_overlay.c * overlay one video on top of another */ #include avfilter.h #include libavcodec/eval.h #include libavutil/avstring.h #include libavutil/pixdesc.h static const char *var_names[] = { main_w, /// width of the main video main_h, /// height of the main video over_w, /// width of the overlay video over_h, /// height of the overlay video NULL }; enum var_name { MAIN_W, MAIN_H, OVER_W, OVER_H, VARS_NB }; #define MAIN 0 #define OVER 1 #define PREV 0 #define QUEUED 1 typedef struct { /** pics[MAIN][0..1] are pictures for the main image. * pics[OVER][0..1] are pictures for the overlayed image. * pics[x][PREV ]are previously output images. * pics[x][QUEUED]are queued, yet unused frames for each input. */ AVFilterPicRef *pics[2][2]; int over_x, over_y; /// position of overlayed subpicture char over_x_expr[256], over_y_expr[256]; int bpp;/// bytes per pixel int hsub, vsub; /// chroma subsampling int blend; } OverlayContext; static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) { OverlayContext *over = ctx-priv; av_strlcpy(over-over_x_expr, 0, sizeof(over-over_x_expr)); av_strlcpy(over-over_y_expr, 0, sizeof(over-over_y_expr)); if (args) sscanf(args, %255[^:]:%255[^:]:%d, over-over_x_expr, over-over_y_expr, over-blend); return 0; } static av_cold void uninit(AVFilterContext *ctx) { OverlayContext *over = ctx-priv; int i, j; for (i = 0; i 2; i ++) for (j = 0; j 2; j ++) if (over-pics[i][j]) avfilter_unref_pic(over-pics[i][j]); } static int query_formats(AVFilterContext *ctx) { OverlayContext *over = ctx-priv; if (over-blend) { enum PixelFormat pix_fmts1[] = { PIX_FMT_YUV420P, PIX_FMT_NONE }; enum PixelFormat pix_fmts2[] = { PIX_FMT_YUVA420P, PIX_FMT_NONE }; AVFilterFormats* inoutFormats = avfilter_make_format_list(pix_fmts1); AVFilterFormats* blendFormats = avfilter_make_format_list(pix_fmts2); avfilter_formats_ref(inoutFormats, ctx-inputs [0]-out_formats); avfilter_formats_ref(inoutFormats, ctx-outputs[0]-in_formats); avfilter_formats_ref(blendFormats, ctx-inputs [1]-out_formats); } else { avfilter_default_query_formats(ctx); } return 0; } static int config_input_main(AVFilterLink *link) { OverlayContext *over = link-dst-priv; over-bpp = av_get_bits_per_pixel(av_pix_fmt_descriptors[link-format]) 3; over-hsub = av_pix_fmt_descriptors[link-format].log2_chroma_w; over-vsub = av_pix_fmt_descriptors[link-format].log2_chroma_h; return 0; } #define EVAL_EXPR(val_, expr_) \ val_ = ff_eval2((expr = expr_), var_values, var_names, \ NULL, NULL, NULL, NULL, NULL, error); \ if (error) \ goto fail static int config_input_overlay(AVFilterLink *link) { AVFilterContext *ctx = link-dst; OverlayContext *over = link-dst-priv; const char *error = NULL, *expr; double var_values[VARS_NB]; /* Finish the configuration by evaluating the expressions now when both inputs are configured. */ var_values[MAIN_W] = ctx-inputs[0]-w; var_values[MAIN_H] = ctx-inputs[0]-h; var_values[OVER_W] = ctx-inputs[1]-w; var_values[OVER_H] = ctx-inputs[1]-h; EVAL_EXPR(over-over_x, over-over_x_expr); EVAL_EXPR(over-over_y, over-over_y_expr); return 0; fail: av_log(ctx,
Re: [FFmpeg-soc] [PATCH] updated! vf_overlay alpha patch and watermarking using PNG with alpha
Stefano Sabatini wrote: On date Tuesday 2009-12-01 00:57:59 +0100, Stefano Sabatini encoded: On date Tuesday 2009-12-01 00:50:50 +0100, Vitor Sessak encoded: [...] I'm fine with committing the patch to soc if tested, even better would be to try to push the filter to the main repo. Does someone want to volunteer for this? A somehow tinied-up version which can be used as a base for SVN inclusion, Nice work! I believe we should get rid of the blend parameter, also the expression evaluation may stay in a successive commit. Do you have any idea of how to get rid of it? Are you planning to implement Michael's suggestion of calling swscale to convert one of the inputs to the right pixel format? A few comments... static int query_formats(AVFilterContext *ctx) { OverlayContext *over = ctx-priv; if (over-blend) { enum PixelFormat pix_fmts1[] = { PIX_FMT_YUV420P, PIX_FMT_NONE }; enum PixelFormat pix_fmts2[] = { PIX_FMT_YUVA420P, PIX_FMT_NONE }; these can be const. } else { avfilter_default_query_formats(ctx); Are all lavfi formats supported? static void copy_blended( uint8_t *out, int out_linesize, const uint8_t*in, intin_linesize, const uint8_t *alpha, int alpha_linesize, int w, int h, int hsub, int vsub) { int x, y; for (y = 0; y h; y++) { uint8_t *outp = out + y* out_linesize; const uint8_t *inp= in+ y*in_linesize; const uint8_t *alphap = alpha + (yvsub) * alpha_linesize; for (x = 0; x w; x++) { *outp = (*outp * (0xff - *alphap) + *inp * *alphap) 8; Looks like some rounding could be useful. Also, one thing that bothers me is that this filter copies the whole picture for overlaying a 10x10 picture into a 1024x1024 picture. I think it could simply draw the input #2 over input #1 (like vf_drawbox does with its box). -Vitor ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5513 - aac-sbr/aacsbr.h
Author: alexc Date: Tue Dec 8 23:58:58 2009 New Revision: 5513 Log: Expand the noise_facs matrix. The noise_facs matrix needs room for 2 noise floors from this frame (the maximum value of bs_num_noise) plus the last noise floor from the previous frame. Modified: aac-sbr/aacsbr.h Modified: aac-sbr/aacsbr.h == --- aac-sbr/aacsbr.hTue Dec 8 07:14:49 2009(r5512) +++ aac-sbr/aacsbr.hTue Dec 8 23:58:58 2009(r5513) @@ -144,7 +144,7 @@ typedef struct { uint8_tt_env_num_env_old[2]; uint8_tt_q[2][3]; float env_facs[2][7][48]; -float noise_facs[2][2][5]; +float noise_facs[2][3][5]; float W[2][32][32][2]; float x_low[32][40][2]; float x_high[64][40][2]; ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5514 - aac-sbr/aacsbr.c
Author: alexc Date: Tue Dec 8 23:59:00 2009 New Revision: 5514 Log: Fix the indexing of (env|noise)_facs. Both are indexed from 1. 0 holds the last envelope/noise floor of the previous frame. Modified: aac-sbr/aacsbr.c Modified: aac-sbr/aacsbr.c == --- aac-sbr/aacsbr.cTue Dec 8 23:58:58 2009(r5513) +++ aac-sbr/aacsbr.cTue Dec 8 23:59:00 2009(r5514) @@ -1333,13 +1333,13 @@ static void sbr_mapping(AACContext *ac, for (i = 0; i ilim; i++) for (m = table[i]; m table[i + 1]; m++) -sbr-e_origmapped[l][m - sbr-k[3]] = sbr-env_facs[ch][l][i]; +sbr-e_origmapped[l][m - sbr-k[3]] = sbr-env_facs[ch][l+1][i]; // ch_data-bs_num_noise 1 = 2 noise floors k = (ch_data-bs_num_noise 1) (sbr-t_env[ch][l] = sbr-t_q[ch][1]); for (i = 0; i sbr-n_q; i++) for (m = table[i]; m table[i + 1]; m++) -sbr-q_mapped[l][m - sbr-k[3]] = sbr-noise_facs[ch][k][i]; +sbr-q_mapped[l][m - sbr-k[3]] = sbr-noise_facs[ch][k+1][i]; for (i = 0; i sbr-n[1]; i++) { memset(sbr-s_indexmapped[l + 1][sbr-f_tablehigh[i] - sbr-k[3]], 0, ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5515 - aac-sbr/aacsbr.c
Author: alexc Date: Tue Dec 8 23:59:03 2009 New Revision: 5515 Log: Save the last envelope/noise floor of this frame for the next. Modified: aac-sbr/aacsbr.c Modified: aac-sbr/aacsbr.c == --- aac-sbr/aacsbr.cTue Dec 8 23:59:00 2009(r5514) +++ aac-sbr/aacsbr.cTue Dec 8 23:59:03 2009(r5515) @@ -978,7 +978,10 @@ static void sbr_env_noise_floors(Spectra } } } -//FIXME : assign 0th elements of (env|noise)_facs from last elements + +//assign 0th elements of (env|noise)_facs from last elements +memcpy( sbr-env_facs[ch][0], sbr-env_facs[ch][ch_data-bs_num_env[1]], sizeof( sbr-env_facs[ch][0])); +memcpy(sbr-noise_facs[ch][0], sbr-noise_facs[ch][ch_data-bs_num_noise ], sizeof(sbr-noise_facs[ch][0])); } // Dequantisation and stereo decoding (14496-3 sp04 p203) ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5516 - aac-sbr/aacsbr.c
Author: alexc Date: Tue Dec 8 23:59:06 2009 New Revision: 5516 Log: Simplify noise floor decoding when bs_df_noise = 0. The bs_df_noise[l] = 0 case of noise floor decoding is just a simple horizontal accumulation. This is analogous to r5495 for envelope decoding. Modified: aac-sbr/aacsbr.c Modified: aac-sbr/aacsbr.c == --- aac-sbr/aacsbr.cTue Dec 8 23:59:03 2009(r5515) +++ aac-sbr/aacsbr.cTue Dec 8 23:59:06 2009(r5516) @@ -970,12 +970,9 @@ static void sbr_env_noise_floors(Spectra for (k = 0; k sbr-n_q; k++) sbr-noise_facs[ch][l + 1][k] = sbr-noise_facs[ch][l][k] + delta * ch_data-bs_data_noise[l][k]; else { -for (k = 0; k sbr-n_q; k++) { -sbr-noise_facs[ch][l + 1][k] = ch_data-bs_data_noise[l][0]; -for (i = 1; i = k; i++) -sbr-noise_facs[ch][l + 1][k] += ch_data-bs_data_noise[l][i]; -sbr-noise_facs[ch][l + 1][k] *= delta; -} +sbr-noise_facs[ch][l + 1][0] = delta * ch_data-bs_data_noise[l][0]; +for (k = 1; k sbr-n_q; k++) +sbr-noise_facs[ch][l + 1][k] = sbr-noise_facs[ch][l + 1][k - 1] + delta * ch_data-bs_data_noise[l][i]; } } ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5517 - aac-sbr/aacsbr.h
Author: alexc Date: Tue Dec 8 23:59:09 2009 New Revision: 5517 Log: Resize variables indexed by bs_num_env (L_E). The maximum value of bs_num_env is 5. env_facs needs one additional envelope from the previous frame. Modified: aac-sbr/aacsbr.h Modified: aac-sbr/aacsbr.h == --- aac-sbr/aacsbr.hTue Dec 8 23:59:06 2009(r5516) +++ aac-sbr/aacsbr.hTue Dec 8 23:59:09 2009(r5517) @@ -94,7 +94,7 @@ typedef struct { uint8_tbs_rel_bord[2][3]; uint8_tbs_pointer; uint8_tbs_num_noise; -uint8_tbs_df_env[7]; +uint8_tbs_df_env[5]; uint8_tbs_df_noise[2]; uint8_tbs_invf_mode[2][5]; uint32_t bs_data_env[7][32]; @@ -143,7 +143,7 @@ typedef struct { uint8_tt_env[2][8]; uint8_tt_env_num_env_old[2]; uint8_tt_q[2][3]; -float env_facs[2][7][48]; +float env_facs[2][6][48]; float noise_facs[2][3][5]; float W[2][32][32][2]; float x_low[32][40][2]; ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5518 - aac-sbr/aacsbr.c
Author: alexc Date: Wed Dec 9 02:17:41 2009 New Revision: 5518 Log: Fix calculation of q_mapped. In q_mapped m is derived from f_tablenoise not f_tablehigh/low. Modified: aac-sbr/aacsbr.c Modified: aac-sbr/aacsbr.c == --- aac-sbr/aacsbr.cTue Dec 8 23:59:09 2009(r5517) +++ aac-sbr/aacsbr.cWed Dec 9 02:17:41 2009(r5518) @@ -1338,7 +1338,7 @@ static void sbr_mapping(AACContext *ac, // ch_data-bs_num_noise 1 = 2 noise floors k = (ch_data-bs_num_noise 1) (sbr-t_env[ch][l] = sbr-t_q[ch][1]); for (i = 0; i sbr-n_q; i++) -for (m = table[i]; m table[i + 1]; m++) +for (m = sbr-f_tablenoise[i]; m sbr-f_tablenoise[i + 1]; m++) sbr-q_mapped[l][m - sbr-k[3]] = sbr-noise_facs[ch][k+1][i]; for (i = 0; i sbr-n[1]; i++) { ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
[FFmpeg-soc] [soc]: r5519 - aac-sbr/aacsbr.c
Author: alexc Date: Wed Dec 9 02:17:44 2009 New Revision: 5519 Log: Index bs_num_res from 1. Use bs_num_res[0] to store the last value from the previous frame. Modified: aac-sbr/aacsbr.c Modified: aac-sbr/aacsbr.c == --- aac-sbr/aacsbr.cWed Dec 9 02:17:41 2009(r5518) +++ aac-sbr/aacsbr.cWed Dec 9 02:17:44 2009(r5519) @@ -516,6 +516,7 @@ static int sbr_grid(AACContext *ac, Spec { int i; +ch_data-bs_freq_res[0] = ch_data-bs_freq_res[ch_data-bs_num_env[1]]; ch_data-bs_num_env[0] = ch_data-bs_num_env[1]; ch_data-bs_amp_res = sbr-bs_amp_res_header; @@ -525,9 +526,9 @@ static int sbr_grid(AACContext *ac, Spec if (ch_data-bs_num_env[1] == 1) ch_data-bs_amp_res = 0; -ch_data-bs_freq_res[0] = get_bits1(gb); +ch_data-bs_freq_res[1] = get_bits1(gb); for (i = 1; i ch_data-bs_num_env[1]; i++) -ch_data-bs_freq_res[i] = ch_data-bs_freq_res[0]; +ch_data-bs_freq_res[i + 1] = ch_data-bs_freq_res[1]; break; case FIXVAR: ch_data-bs_var_bord[1] = get_bits(gb, 2); @@ -540,7 +541,7 @@ static int sbr_grid(AACContext *ac, Spec ch_data-bs_pointer = get_bits(gb, ceil_log2[ch_data-bs_num_env[1] + 1]); for (i = 0; i ch_data-bs_num_env[1]; i++) -ch_data-bs_freq_res[ch_data-bs_num_env[1] - 1 - i] = get_bits1(gb); +ch_data-bs_freq_res[ch_data-bs_num_env[1] - i] = get_bits1(gb); break; case VARFIX: ch_data-bs_var_bord[0] = get_bits(gb, 2); @@ -553,7 +554,7 @@ static int sbr_grid(AACContext *ac, Spec ch_data-bs_pointer = get_bits(gb, ceil_log2[ch_data-bs_num_env[1] + 1]); for (i = 0; i ch_data-bs_num_env[1]; i++) -ch_data-bs_freq_res[i] = get_bits1(gb); +ch_data-bs_freq_res[i + 1] = get_bits1(gb); break; case VARVAR: ch_data-bs_var_bord[0] = get_bits(gb, 2); @@ -570,7 +571,7 @@ static int sbr_grid(AACContext *ac, Spec ch_data-bs_pointer = get_bits(gb, ceil_log2[ch_data-bs_num_env[1] + 1]); for (i = 0; i ch_data-bs_num_env[1]; i++) -ch_data-bs_freq_res[i] = get_bits1(gb); +ch_data-bs_freq_res[i + 1] = get_bits1(gb); break; default: break; @@ -656,10 +657,10 @@ static void sbr_envelope(SpectralBandRep for (i = 0; i ch_data-bs_num_env[1]; i++) { if (!ch_data-bs_df_env[i]) { ch_data-bs_data_env[i][0] = get_bits(gb, bits); // bs_env_start_value_balance -for (j = 1; j sbr-n[ch_data-bs_freq_res[i]]; j++) +for (j = 1; j sbr-n[ch_data-bs_freq_res[i + 1]]; j++) ch_data-bs_data_env[i][j] = get_vlc2(gb, f_huff, 9, max_depth) - f_lav; } else { -for (j = 0; j sbr-n[ch_data-bs_freq_res[i]]; j++) +for (j = 0; j sbr-n[ch_data-bs_freq_res[i + 1]]; j++) ch_data-bs_data_env[i][j] = get_vlc2(gb, t_huff, 9, max_depth) - t_lav; } } @@ -990,7 +991,7 @@ static void sbr_dequant(SpectralBandRepl if (id_aac == TYPE_CPE sbr-bs_coupling) { float pan_offset = sbr-data[ch].bs_amp_res ? 12.0f : 24.0f; for (l = 1; l = sbr-data[ch].bs_num_env[1]; l++) { -for (k = 0; k sbr-n[sbr-data[ch].bs_freq_res[l + 1]]; k++) { +for (k = 0; k sbr-n[sbr-data[ch].bs_freq_res[l]]; k++) { float temp1 = powf(2.0f, sbr-env_facs[0][l][k] * alpha + 7.0f); float temp2 = (pan_offset - sbr-env_facs[1][l][k]) * alpha; sbr-env_facs[0][l][k] = temp1 / (1.0f + powf(2.0f, temp2)); @@ -1007,7 +1008,7 @@ static void sbr_dequant(SpectralBandRepl } } else { // SCE or one non-coupled CPE for (l = 1; l = sbr-data[ch].bs_num_env[1]; l++) -for (k = 0; k sbr-n[sbr-data[ch].bs_freq_res[l + 1]]; k++) +for (k = 0; k sbr-n[sbr-data[ch].bs_freq_res[l]]; k++) sbr-env_facs[ch][l][k] = powf(2.0f, alpha * sbr-env_facs[ch][l][k] + 6.0f); for (l = 1; l = sbr-data[ch].bs_num_noise; l++) for (k = 0; k sbr-n_q; k++) ___ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc