[FFmpeg-trac] #5955(undetermined:new): ffmpeg3.2 watermark is opaque

FFmpeg trac at avcodec.org
Tue Nov 15 17:14:28 EET 2016


#5955: ffmpeg3.2 watermark is opaque
-------------------------------------+-------------------------------------
             Reporter:  wzw200       |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:
  undetermined                       |  unspecified
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 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 at detected 2 logical cores
 ffmpeg at Setting 'video_size' to value '368x640'
 ffmpeg at Setting 'pix_fmt' to value '0'
 ffmpeg at Setting 'time_base' to value '1/5'
 ffmpeg at Setting 'pixel_aspect' to value '0/1'
 ffmpeg at w:368 h:640 pixfmt:yuv420p tb:1/5 fr:0/1 sar:0/1 sws_param:
 ffmpeg at Setting 'filename' to value
 '/var/mobile/Containers/Data/Application/C0B5759652FE/Documents/watermark.png'
 ffmpeg at Setting default whitelist 'file,crypto'
 ffmpeg at Probing image2 score:50 size:2048
 ffmpeg at Probing mp3 score:1 size:2048
 ffmpeg at Probing png_pipe score:99 size:2048
 ffmpeg at Format png_pipe probed with size=2048 and score=99
 ffmpeg at Before avformat_find_stream_info() pos: 0 bytes read:15558 seeks:0
 nb_streams:1
 ffmpeg at stream 0: start_time: -368934881474191040.000 duration:
 -368934881474191040.000
 ffmpeg at format: start_time: -9223372036854.775 duration: -9223372036854.775
 bitrate=0 kb/s
 ffmpeg at After avformat_find_stream_info() pos: 15558 bytes read:15558
 seeks:0 frames:1
 ffmpeg at 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 at Setting 'x' to value '0'
 ffmpeg at Setting 'y' to value '0'
 ffmpeg at w:iw h:ih flags:'bilinear' interl:0
 ffmpeg at auto-inserting filter 'auto-inserted scaler 0' between the filter
 'Parsed_movie_0' and the filter 'Parsed_overlay_1'
 ffmpeg at query_formats: 4 queried, 2 merged, 1 already done, 0 delayed
 ffmpeg at w:181 h:98 fmt:rgba sar:1/1 -> w:181 h:98 fmt:yuva420p sar:1/1
 flags:0x2
 ffmpeg at main w:368 h:640 fmt:yuv420p overlay w:181 h:98 fmt:yuva420p
 eof_action:repeat
 ffmpeg at Selected 1/25 time base
 ffmpeg at Sync level 2

 ffmpeg at Incoming frame (time:3.74786e+08) from link #0
 ffmpeg at w:181 h:98 fmt:rgba sar:0/1 -> w:50 h:30 fmt:yuva420p sar:0/1
 flags:0x2
 ffmpeg at Incoming frame (time:0) from link #1
 ffmpeg at n:1.000000 t:374785922.000000 pos:nan x:100.000000 xi:100
 y:100.000000 yi:100
 ffmpeg at Incoming frame (time:3.74786e+08) from link #0
 ffmpeg at n:1.000000 t:374785961.800000 pos:nan x:100.000000 xi:100
 y:100.000000 yi:100
 ffmpeg at Incoming frame (time:3.74786e+08) from link #0
 ffmpeg at n:2.000000 t:374786001.800000 pos:nan x:100.000000 xi:100
 y:100.000000 yi:100
 ffmpeg at Incoming frame (time:3.74786e+08) from link #0
 ffmpeg at 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);

 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/5955>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list