<div dir="ltr"><div class="gmail_default" style="color:rgb(0,0,153)">Hi All,</div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)">Following is the code snippet that I am reusing from remuxing.c, but when I convert an image from YUV to RGB and again back to YUV, there are some glitches added to the video stream on the frames that went for conversion, rest of the frames are fine.<br></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)">Please let me know what I am missing or how this can be achieved in a different way without any glitches. FFmpeg version is 2.6.2</div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)">    //Allocation for RGB frame</div><div class="gmail_default" style><div class="gmail_default" style><span style="color:rgb(0,0,153)"><br></span></div><div class="gmail_default" style><span style="color:rgb(0,0,153)">    frame_rgb = av_frame_alloc();</span><br></div><div class="gmail_default" style><font color="#000099">    if (!frame_rgb) {</font></div><div class="gmail_default" style><font color="#000099">        goto end;</font></div><div class="gmail_default" style><font color="#000099">    }</font></div></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style><div class="gmail_default" style><font color="#000099">    </font><span style="color:rgb(0,0,153)">num_bytes = avpicture_get_size(PIX_FMT_RGB24, in_vcodec_ctx->width,</span></div><div class="gmail_default" style><font color="#000099">                      in_vcodec_ctx->height);</font></div><div class="gmail_default" style><font color="#000099"><br></font></div><div class="gmail_default" style><font color="#000099">    buffer_rgb = (uint8_t *)av_malloc(num_bytes * sizeof(uint8_t));</font></div><div class="gmail_default" style><font color="#000099"><br></font></div><div class="gmail_default" style><font color="#000099">    </font><span style="color:rgb(0,0,153)">avpicture_fill((AVPicture *)frame_rgb, buffer_rgb, PIX_FMT_RGB24,</span></div><div class="gmail_default" style><font color="#000099">             in_vcodec_ctx->width, in_vcodec_ctx->height);</font></div></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)"><div class="gmail_default">    //Allocation for YUV frame</div><div class="gmail_default"><br></div><div class="gmail_default" style="color:rgb(34,34,34)"><div class="gmail_default"><font color="#000099">    frame_yuv = av_frame_alloc();</font></div><div class="gmail_default"><font color="#000099">    if (!frame_yuv) {</font></div><div class="gmail_default"><font color="#000099">        goto end;</font></div><div class="gmail_default"><font color="#000099">    }</font></div><div class="gmail_default"><font color="#000099"><br></font></div></div></div><div class="gmail_default" style><div class="gmail_default" style><font color="#000099">    num_bytes = avpicture_get_size(in_vcodec_ctx->pix_fmt, in_vcodec_ctx->width,</font></div><div class="gmail_default" style><font color="#000099">                      in_vcodec_ctx->height);</font></div><div class="gmail_default" style><font color="#000099"><br></font></div><div class="gmail_default" style><font color="#000099">    buffer_yuv = (uint8_t *)av_malloc(num_bytes * sizeof(uint8_t));</font></div><div class="gmail_default" style><font color="#000099"><br></font></div><div class="gmail_default" style><span style="color:rgb(0,0,153)">    avpicture_fill((AVPicture *)frame_yuv, buffer_yuv, in_vcodec_ctx->pix_fmt,</span><br></div><div class="gmail_default" style><font color="#000099">             in_vcodec_ctx->width, in_vcodec_ctx->height);</font></div><div class="gmail_default" style><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)">    //Allocation of SWS context</div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div></div><div class="gmail_default" style><font color="#000099"><div class="gmail_default">    sws_rgb_ctx = sws_getContext(in_vcodec_ctx->width, in_vcodec_ctx->height,</div><div class="gmail_default">                             in_vcodec_ctx->pix_fmt,</div><div class="gmail_default">                             in_vcodec_ctx->width, in_vcodec_ctx->height,</div><div class="gmail_default">                             PIX_FMT_RGB24,</div><div class="gmail_default">                             SWS_BICUBIC, NULL, NULL, NULL);</div><div class="gmail_default"><br></div><div class="gmail_default">    sws_yuv_ctx = sws_getContext(in_vcodec_ctx->width, in_vcodec_ctx->height,<br></div><div class="gmail_default">                             PIX_FMT_RGB24,</div><div class="gmail_default">                             in_vcodec_ctx->width, in_vcodec_ctx->height,</div><div class="gmail_default">                             in_vcodec_ctx->pix_fmt,</div><div class="gmail_default">                             SWS_BICUBIC, NULL, NULL, NULL);</div><div><br></div><div><div>    for( ;; ) {</div><div><br></div><div>        ret = av_read_frame(ifmt_ctx, &pkt_in);</div><div>        if (ret < 0)</div><div>            break;</div><div><br></div><div>        in_stream  = ifmt_ctx->streams[pkt_in.stream_index];</div><div>        out_stream = ofmt_ctx->streams[pkt_in.stream_index];</div><div><br></div><div>        /* Process only video stream packets */<br></div><div>        if (pkt_in.stream_index == video_stream_idx) {</div><div><br></div><div>          /* Decode video frame */</div><div>          avcodec_decode_video2(in_vcodec_ctx, frame_yuv, &frame_finished, &pkt_in);</div><div><br></div><div>          /* Process completed video frame and preferred type frame */</div><div>          if (frame_finished && AV_PICTURE_TYPE_I == frame_yuv->pict_type) {</div><div><br></div><div>              /* Convert the image from its native format to RGB */</div><div>              sws_scale</div><div>              (</div><div>                  sws_rgb_ctx,</div><div>                  (uint8_t const * const *)frame_yuv->data,</div><div>                  frame_yuv->linesize,</div><div>                  0,</div><div>                  in_vcodec_ctx->height,</div><div>                  frame_rgb->data,</div><div>                  frame_rgb->linesize</div><div>              );</div><div><br></div><div>              // perform necessary image modification</div><div><br></div><div>              /* Convert the image from RGB to input native format */</div><div>              sws_scale</div><div>              (</div><div>                  sws_yuv_ctx,</div><div>                  (uint8_t const * const *)frame_rgb->data,</div><div>                  frame_rgb->linesize,</div><div>                  0,</div><div>                  in_vcodec_ctx->height,</div><div>                  frame_yuv->data,</div><div>                  frame_yuv->linesize</div><div>              );</div></div><div><br></div><div><div>              av_init_packet(&pkt_yuv);</div><div><br></div><div>              /* packet data will be allocated by the encoder */</div><div>              pkt_yuv.data = NULL;</div><div><br></div><div>              /* encode the image */<br></div><div>              ret = avcodec_encode_video2(out_stream->codec, &pkt_yuv, frame_yuv, &got_frame);</div><div>              if (ret < 0) {</div><div>                  fprintf(stderr, "Error encoding frame\n");</div><div>                  break;</div><div>              }</div><div><br></div><div>              if (got_frame) {</div><div><br></div><div>                  /* copy packet */</div><div>                  pkt_yuv.pts = av_rescale_q_rnd(pkt_in.pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);</div><div>                  pkt_yuv.dts = av_rescale_q_rnd(pkt_in.dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);</div><div>                  pkt_yuv.duration = av_rescale_q(pkt_in.duration, in_stream->time_base, out_stream->time_base);</div><div>                  pkt_yuv.pos = -1;</div><div><br></div><div>                  ret = av_interleaved_write_frame(ofmt_ctx, &pkt_yuv);<br></div><div>                  if (ret < 0) {</div><div>                      fprintf(stderr, "Error muxing packet\n");</div><div>                      break;</div><div>                  }</div></div><div><br></div><div><div>                  av_free_packet(&pkt_yuv);</div><div>                  av_free_packet(&pkt_in);</div><div><br></div><div>                  continue;</div><div>              }</div><div>              else {</div><div>                  fprintf(stdout, "No output for encoded packet\n");</div><div><br></div><div>                  av_free_packet(&pkt_yuv);</div><div>              }</div><div>          }</div><div>        }</div><div><br></div><div>        /* copy packet */</div><div>        pkt_in.pts = av_rescale_q_rnd(pkt_in.pts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);</div><div>        pkt_in.dts = av_rescale_q_rnd(pkt_in.dts, in_stream->time_base, out_stream->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);</div><div>        pkt_in.duration = av_rescale_q(pkt_in.duration, in_stream->time_base, out_stream->time_base);</div><div>        pkt_in.pos = -1;</div><div><br></div><div>        ret = av_interleaved_write_frame(ofmt_ctx, &pkt_in);<br></div><div>        if (ret < 0) {</div><div>            fprintf(stderr, "Error muxing packet\n");</div><div>            break;</div><div>        }</div><div><br></div><div>        av_free_packet(&pkt_in);</div><div>    }</div></div></font></div></div><div class="gmail_default" style="color:rgb(0,0,153)"><br></div><div class="gmail_default" style="color:rgb(0,0,153)">Regards,</div><div class="gmail_default" style="color:rgb(0,0,153)">Sethu</div></div>