Opened 10 years ago
Closed 10 years ago
#5955 closed defect (needs_more_info)
ffmpeg3.2 watermark is opaque
| Reported by: | wzw200 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Component: | undetermined |
| Version: | unspecified | Keywords: | |
| Cc: | Blocked By: | ||
| Blocking: | Reproduced by developer: | no | |
| Analyzed by developer: | no |
Description
Hello everybody,
I use ffmpeg3.2 to add a watermark, compiled by the X86 platform, the command line out of the video watermark is transparent, I re encoding in watermarking, I program, the video watermarking is opaque, please help me look at the work order
on mac xcode
ffmpeg@detected 2 logical cores
ffmpeg@Setting 'video_size' to value '368x640'
ffmpeg@Setting 'pix_fmt' to value '0'
ffmpeg@Setting 'time_base' to value '1/5'
ffmpeg@Setting 'pixel_aspect' to value '0/1'
ffmpeg@w:368 h:640 pixfmt:yuv420p tb:1/5 fr:0/1 sar:0/1 sws_param:
ffmpeg@Setting 'filename' to value '/var/mobile/Containers/Data/Application/C0B5759652FE/Documents/watermark.png'
ffmpeg@Setting default whitelist 'file,crypto'
ffmpeg@Probing image2 score:50 size:2048
ffmpeg@Probing mp3 score:1 size:2048
ffmpeg@Probing png_pipe score:99 size:2048
ffmpeg@Format png_pipe probed with size=2048 and score=99
ffmpeg@Before avformat_find_stream_info() pos: 0 bytes read:15558 seeks:0 nb_streams:1
ffmpeg@stream 0: start_time: -368934881474191040.000 duration: -368934881474191040.000
ffmpeg@format: start_time: -9223372036854.775 duration: -9223372036854.775 bitrate=0 kb/s
ffmpeg@After avformat_find_stream_info() pos: 15558 bytes read:15558 seeks:0 frames:1
ffmpeg@seek_point:0 format_name:(null) file_name:/var/mobile/Containers/Data/Application/1DD59678-9810-4A8F-B4E7-C0B5759652FE/Documents/watermark.png stream_index:-1
ffmpeg@Setting 'x' to value '0'
ffmpeg@Setting 'y' to value '0'
ffmpeg@w:iw h:ih flags:'bilinear' interl:0
ffmpeg@auto-inserting filter 'auto-inserted scaler 0' between the filter 'Parsed_movie_0' and the filter 'Parsed_overlay_1'
ffmpeg@query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
ffmpeg@w:181 h:98 fmt:rgba sar:1/1 -> w:181 h:98 fmt:yuva420p sar:1/1 flags:0x2
ffmpeg@main w:368 h:640 fmt:yuv420p overlay w:181 h:98 fmt:yuva420p eof_action:repeat
ffmpeg@Selected 1/25 time base
ffmpeg@Sync level 2
ffmpeg@Incoming frame (time:3.74786e+08) from link #0
ffmpeg@w:181 h:98 fmt:rgba sar:0/1 -> w:50 h:30 fmt:yuva420p sar:0/1 flags:0x2
ffmpeg@Incoming frame (time:0) from link #1
ffmpeg@n:1.000000 t:374785922.000000 pos:nan x:100.000000 xi:100 y:100.000000 yi:100
ffmpeg@Incoming frame (time:3.74786e+08) from link #0
ffmpeg@n:1.000000 t:374785961.800000 pos:nan x:100.000000 xi:100 y:100.000000 yi:100
ffmpeg@Incoming frame (time:3.74786e+08) from link #0
ffmpeg@n:2.000000 t:374786001.800000 pos:nan x:100.000000 xi:100 y:100.000000 yi:100
ffmpeg@Incoming frame (time:3.74786e+08) from link #0
ffmpeg@n:3.000000 t:374786042.800000 pos:nan x:100.000000 xi:100 y:100.000000 yi:100
AVFilterGraph *filter_graph ;
AVFilterContext *buffersink_ctx ;
AVFilterContext *buffersrc_ctx ;
AVFilterInOut *outputs ;
AVFilterInOut *inputs ;
const char *filter_format = "movie=%s[wm];[in][wm]overlay=0:0[out]";
int init_filters(RtmpPublisher* rp, AVCodecContext *pCodecCtx)
{
char args[512];
char filters_descr[1024];
int ret;
inputs = NULL;
outputs = NULL;
filter_graph = NULL;
AVFilter *buffersrc = avfilter_get_by_name("buffer");
AVFilter *buffersink = avfilter_get_by_name("buffersink");
outputs = avfilter_inout_alloc();
inputs = avfilter_inout_alloc();
enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE };
AVBufferSinkParams *buffersink_params;
memset(filters_descr, 0, 1024);
snprintf(filters_descr, 1024, filter_format,rp->watermarkUrl);
/* buffer video source: the decoded frames from the decoder will be inserted here. */
snprintf(args, sizeof(args),
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
pCodecCtx->time_base.num, pCodecCtx->time_base.den,
pCodecCtx->sample_aspect_ratio.num, pCodecCtx->sample_aspect_ratio.den);
filter_graph = avfilter_graph_alloc();
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
args, NULL, filter_graph);
if (ret < 0) {
rp->_logCb(rp->publisher_observer, 0, "avfilter_graph_create_filter1 failed");
goto FAILED;
}
//buffer video sink: to terminate the filter chain.
buffersink_params = av_buffersink_params_alloc();
buffersink_params->pixel_fmts = pix_fmts;
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
NULL, buffersink_params, filter_graph);
av_free(buffersink_params);
if (ret < 0) {
rp->_logCb(rp->publisher_observer, 0, "avfilter_graph_create_filter2 failed");
goto FAILED;
}
// Endpoints for the filter graph.
outputs->name = av_strdup("in");
outputs->filter_ctx = buffersrc_ctx;
outputs->pad_idx = 0;
outputs->next = NULL;
inputs->name = av_strdup("out");
inputs->filter_ctx = buffersink_ctx;
inputs->pad_idx = 0;
inputs->next = NULL;
if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
&inputs, &outputs, NULL)) < 0)
{
rp->_logCb(rp->publisher_observer, 0, "avfilter_graph_parse_ptr failed:%s", filters_descr);
goto FAILED;
}
if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
{
rp->_logCb(rp->publisher_observer, 0, "avfilter_graph_config failed");
goto FAILED;
}
rp->watermarkEnable=1;
return 0;
FAILED:
Uninit_filters();
return -1;
}
//////////////////////////////////////////////////////////////////////////////////////
Frame *pic = frame_queue_peek_readable(&rp->videoPictureQueue);
//put dst_frame into queue
int y_size = pic->height * pic->linesize [0];
int u_size = pic->height * pic->linesize [1] / 2;
int v_size = pic->height * pic->linesize [2] / 2;
pPicture->data[0] = pic->data;
pPicture->data[1] = pic->data + y_size;
pPicture->data[2] = pic->data + y_size + v_size;
pPicture->width = pic->width;
pPicture->height = pic->height;
pPicture->format = AV_PIX_FMT_YUV420P;
pPicture->linesize[0] = pic->linesize[0];
pPicture->linesize[1] = pic->linesize[1];
pPicture->linesize[2] = pic->linesize[2];
pPicture->pts = pic->pts;
if (rp->watermarkEnable){
int rt = av_buffersrc_add_frame_flags(buffersrc_ctx, pPicture, AV_BUFFERSRC_FLAG_KEEP_REF);
if (rt < 0) {
av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
fprintf(stderr, "Error encoding audio frame: %d,%s\n", rt,av_err2str(rt));
break;
}
/* pull filtered frames from the filtergraph */
while (1) {
AVFrame *filter_frame = av_frame_alloc();
ret =av_buffersink_get_frame(buffersink_ctx, filter_frame);//,AV_BUFFERSINK_FLAG_PEEK);
if (ret < 0) {
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
ret= 0;
av_frame_free(&filter_frame);
break;
}
filter_frame->pts = pic->pts;
do_encode_video(rp, filter_frame);
av_frame_free(&filter_frame);
}
}
frame_queue_next(&rp->videoPictureQueue);
Attachments (1)
Change History (7)
by , 10 years ago
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Download the latest version of the ffmpeg, compiled in Xcode, running on the iPhone
comment:3 by , 10 years ago
Is the issue only reproducible on a mobile device, not on your development system?
comment:4 by , 10 years ago
The same code, FFMPEG2.8 library, runs on iPhone is transparent,
After that, I will upgrade to FFMPEG3.2 out of the question, and then I will compile the MAC 3.2 on the run command, found out the video is transparent white, I follow the FFMPEG code, is mainly related with alpha,
*d = FAST_DIV255 (*d * (255 - alpha) + *s * alpha);
If main_has_alpha is equal to 0, only the picture of the alpha, there is a black background,
If main_has_alpha is equal to 1, alpha = UNPREMULTIPLY_ALPHA (alpha, alpha_d) is performed;
const int main_has_alpha = s->main_has_alpha;
// if the main channel has an alpha channel, alpha has to be calculated
// to create an un-premultiplied (straight) alpha value
if (main_has_alpha && alpha != 0 && alpha != 255) {
// average alpha for color components, improve quality
uint8_t alpha_d;
if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
alpha_d = (d[0] + d[src->linesize[3]] +
d[1] + d[src->linesize[3]+1]) >> 2;
} else if (hsub || vsub) {
alpha_h = hsub && k+1 < src_wp ?
(d[0] + d[1]) >> 1 : d[0];
alpha_v = vsub && j+1 < src_hp ?
(d[0] + d[src->linesize[3]]) >> 1 : d[0];
alpha_d = (alpha_v + alpha_h) >> 1;
} else
alpha_d = d[0];
alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);
}
*d = FAST_DIV255(*d * (255 - alpha) + *s * alpha);
{{{
}}}
comment:5 by , 10 years ago
If you believe this is a regression, please point us to the change introducing the problem you see.
As an alternative, please provide enough information so I can reproduce the issue.
comment:6 by , 10 years ago
| Resolution: | → needs_more_info |
|---|---|
| Status: | new → closed |
Please reopen this ticket if you can point us to the change introducing the regression.



Please test current FFmpeg git head?
Is the issue reproducible with
ffmpeg, the application?