Recherche avancée

Médias (91)

Autres articles (43)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Mise à disposition des fichiers

    14 avril 2011, par

    Par défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
    Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
    Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

Sur d’autres sites (4533)

  • Memory Leak in c++/cli application

    10 décembre 2013, par Ankush

    I am passing bitmap from my c# app to c++/cli dll that add it to video.
    The problem is program slowly leaking memory. I tried _CrtDumpMemoryLeaks() shows me leak of bitmap & another 40 byte leak but i am disposing bitmap.
    Can anyone see memory leak, Here is code..

    Flow :

    1) Capture screenshot by takescreenshot()

    2) pass it to c++/cli function

    3) dispose bitmap

    lines from my c# app

    Bitmap snap = takescreeshot();
    vencoder.AddBitmap(snap);
    snap.Dispose();
    vencoder.printleak();

    private static Bitmap takescreeshot()
       {
           System.Drawing.Bitmap bitmap = null;
           System.Drawing.Graphics graphics = null;

           bitmap = new Bitmap
           (
               System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
               System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height,
               System.Drawing.Imaging.PixelFormat.Format24bppRgb
           );

           graphics = System.Drawing.Graphics.FromImage(bitmap);

           graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size);

           //Write TimeSpamp
           Rectangle rect = new Rectangle(1166, 738, 200, 20);
           String datetime= System.String.Format("{0:dd:MM:yy  hh:mm:ss}",DateTime.Now);
           System.Drawing.Font sysfont = new System.Drawing.Font("Times New Roman", 14, FontStyle.Bold);
           graphics.DrawString(datetime, sysfont, Brushes.Red,rect);
           //

           Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
           Bitmap grayImage = filter.Apply(bitmap);

           //Dispose
           bitmap.Dispose();
           graphics.Dispose();

           return grayImage;
       }

    now in c++/cli dll

    bool VideoEncoder::AddBitmap(Bitmap^ bitmap)
       {
           BitmapData^ bitmapData = bitmap->LockBits( System::Drawing::Rectangle( 0, 0,bitmap->Width, bitmap->Height ),ImageLockMode::ReadOnly,PixelFormat::Format8bppIndexed);
           uint8_t* ptr = reinterpret_cast( static_cast( bitmapData->Scan0 ) );
           uint8_t* srcData[4] = { ptr, NULL, NULL, NULL };
           int srcLinesize[4] = { bitmapData->Stride, 0, 0, 0 };

           pCurrentPicture = CreateFFmpegPicture(pVideoStream->codec->pix_fmt, pVideoStream->codec->width, pVideoStream->codec->height);

           sws_scale(pImgConvertCtx, srcData, srcLinesize, 0, bitmap->Height, pCurrentPicture->data, pCurrentPicture->linesize );

           bitmap->UnlockBits( bitmapData );

           write_video_frame();

           bitmapData=nullptr;
           ptr=NULL;

           return true;
       }

    AVFrame * VideoEncoder::CreateFFmpegPicture(int pix_fmt, int nWidth, int nHeight)
       {

         AVFrame *picture     = NULL;
         uint8_t *picture_buf = NULL;
         int size;

         picture = avcodec_alloc_frame();
         if ( !picture)
         {
           printf("Cannot create frame\n");
           return NULL;
         }

         size = avpicture_get_size((AVPixelFormat)pix_fmt, nWidth, nHeight);

         picture_buf = (uint8_t *) av_malloc(size);

         if (!picture_buf)
         {
           av_free(picture);
           printf("Cannot allocate buffer\n");
           return NULL;
         }

         avpicture_fill((AVPicture *)picture, picture_buf,
           (AVPixelFormat)pix_fmt, nWidth, nHeight);

         return picture;
       }

       void VideoEncoder::write_video_frame()
       {
           AVCodecContext* codecContext = pVideoStream->codec;

           int out_size, ret = 0;

           if ( pFormatContext->oformat->flags & AVFMT_RAWPICTURE )
           {
               printf( "raw picture must be written" );
           }
           else
           {
               out_size = avcodec_encode_video( codecContext, pVideoEncodeBuffer,nSizeVideoEncodeBuffer, pCurrentPicture );

               if ( out_size > 0 )
               {
                   AVPacket packet;
                   av_init_packet( &packet );

                   if ( codecContext->coded_frame->pts != AV_NOPTS_VALUE )
                   {
                       packet.pts = av_rescale_q( packet.pts, codecContext->time_base, pVideoStream->time_base );
                   }

                   if ( codecContext->coded_frame->pkt_dts != AV_NOPTS_VALUE )
                   {
                       packet.dts = av_rescale_q( packet.dts, codecContext->time_base, pVideoStream->time_base );
                   }

                   if ( codecContext->coded_frame->key_frame )
                   {
                       packet.flags |= AV_PKT_FLAG_KEY;
                   }

                   packet.stream_index = pVideoStream->index;
                   packet.data = pVideoEncodeBuffer;
                   packet.size = out_size;

                   ret = av_interleaved_write_frame( pFormatContext, &packet );

                   av_free_packet(&packet);
                   av_freep(pCurrentPicture);
               }
               else
               {
                   // image was buffered
               }
           }

           if ( ret != 0 )
           {
               throw gcnew Exception( "Error while writing video frame." );
           }
       }


       void VideoEncoder::printleak()
       {
           printf("No of leaks: %d",_CrtDumpMemoryLeaks());
           printf("\n");
       }
  • Why is my DSharpPlus Slash Command not playing my desired sound using FFMPEG in C# ?

    19 mai 2023, par IngeniousThoughts

    I'm having a problem with my ffmpeg setup the commands work fine but my play command doesn't play my desired sound.

    


    //The command.
        [SlashCommand("play", "plays a sound in a voice channel.")]
        public async Task HowlCommand(InteractionContext ctx, [Choice("ChoiceName", "C:\\My\\Program\\Directory\\Name\\MySound.mp3")]
                                                             [Option("Sound", "Please select a Sound")] string filepath)
        {
            //Creates a slash command used response.
            //Also removes the error message.
            await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder()
                                                                                                                    .WithContent("Playing sound in voice channel. Please wait just a moment!"));
 
            //Checks if the user is not a bot to send the message.
            if (ctx.Member.IsBot)
            {
                return;
            }
            else
            {
                if(filepath != "C:\\My\\Program\\Directory\\Name\\MySound.mp3")
                {
                    var embedmessage = new DiscordMessageBuilder()
                        .AddEmbed(new DiscordEmbedBuilder()
 
                        .WithAuthor("BotName", null, ctx.Client.CurrentApplication.Icon)
                        .WithTitle("Please select the following sound to play:")
                        .WithImageUrl(ctx.Client.CurrentApplication.Icon)
                        .WithFooter("VoiceChannel Error.", "ImageURL.png")
                        .WithTimestamp(DateTime.Now)
                        .Build()
 
                        );
 
                    //Makes the command wait 5 seconds before sending the rest of the command data.
                    await Task.Delay(TimeSpan.FromSeconds(5));
 
                    //Sends the embed in a message.
                    await ctx.Channel.SendMessageAsync(embedmessage);
                }
                else
                {
                    //Makes the command wait 5 seconds before sending the rest of the command data.
                    await Task.Delay(TimeSpan.FromSeconds(5));
 
 
                    var vnext = ctx.Client.GetVoiceNext();
                    var vnc = vnext.GetConnection(ctx.Guild);
                    
                    //if null throws exception.
                    if (vnc == null)
                        throw new System.InvalidOperationException("Not connected in this guild.");
 
 
                    //Gets the mp3 file to use.
                    var ffmpeg = Process.Start(new ProcessStartInfo
                    {
                        FileName = "ffmpeg",
                        Arguments = $@"-i ""{filepath}"" -ac 2 -f s16le -ar 48000 pipe:1",
                        RedirectStandardOutput = true,
                        UseShellExecute = false
                    });
                    Stream pcm = ffmpeg.StandardOutput.BaseStream;
 
                    VoiceTransmitSink transmit = vnc.GetTransmitSink();
                    await pcm.CopyToAsync(transmit);
                    vnc.GetTransmitSink().VolumeModifier = 5;
 
                    //Makes the command wait 10 seconds before sending the rest of the command data.
                    await Task.Delay(TimeSpan.FromSeconds(10));
 
                    //Disconnects the bot from the voice channel.
                    vnc.Disconnect();
                }
            }
        }


    


    //The command.
        [SlashCommand("join", "Joins a voice channel.")]
        public async Task JoinChannel(InteractionContext ctx, [Choice("MyVoiceChannel", "VoiceChannelName")]
                                                             [Option("VoiceChannel", "Please choose a Voice Channel.")] DiscordChannel channel)
        {
            //Creates a slash command used response.
            //Also removes the error message.
            await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder()
                                                                                                                    .WithContent("Joining voice channel. Please wait just a moment!"));
 
            //Checks if the user is not a bot to send the message.
            if (ctx.Member.IsBot)
            {
                return;
            }
            else
            {
                if (channel.Name != "MyVoiceChannelName")
                {
                    var embedmessage = new DiscordMessageBuilder()
                        .AddEmbed(new DiscordEmbedBuilder()
 
                        .WithAuthor("BotName", null, ctx.Client.CurrentApplication.Icon)
                        .WithTitle("Please Create The Following Voice Channel:")
                        .WithImageUrl(ctx.Client.CurrentApplication.Icon)
                        .AddField("VoiceChannel:", "**BotName**" + Environment.NewLine + "Is Case Sensitive: **Yes**")
                        .WithFooter("VoiceChannel Error.", "ImageURL.png")
                        .WithTimestamp(DateTime.Now)
                        .Build()
 
                        );
 
                    //Makes the command wait 5 seconds before sending the rest of the command data.
                    await Task.Delay(TimeSpan.FromSeconds(5));
 
                    //Sends the embed in a message.
                    await ctx.Channel.SendMessageAsync(embedmessage);
                }
                else
                {
                    //Makes the command wait 5 seconds before sending the rest of the command data.
                    await Task.Delay(TimeSpan.FromSeconds(5));
 
 
                    channel = ctx.Member.VoiceState?.Channel;
                    await channel.ConnectAsync();
 
                }
            }
        }
 
    }
}


    


    public sealed class Program&#xA;    {&#xA;        public static DiscordClient Client { get; private set; }&#xA;        public static InteractivityExtension Interactivity { get; private set; }&#xA;        public static CommandsNextExtension Commands { get; private set; }&#xA;        public static VoiceNextExtension VoiceNext { get; private set; }&#xA; &#xA; &#xA;        static async Task Main(string[] args)&#xA;        {&#xA; &#xA;            //Main Window configs specifying the title name and color.&#xA;            Console.BackgroundColor = ConsoleColor.Black;&#xA;            Console.ForegroundColor = ConsoleColor.Magenta;&#xA;            Console.Title = "BotName";&#xA; &#xA;            //1. Get the details of your config.json file by deserialising it&#xA;            var configJsonFile = new JSONReader();&#xA;            await configJsonFile.ReadJSON();&#xA; &#xA;            //2. Setting up the Bot Configuration&#xA;            var discordConfig = new DiscordConfiguration()&#xA;            {&#xA;                Intents = DiscordIntents.All,&#xA;                Token = configJsonFile.token,&#xA;                TokenType = TokenType.Bot,&#xA;                AutoReconnect = true&#xA;            };&#xA; &#xA;            //3. Apply this config to our DiscordClient&#xA;            Client = new DiscordClient(discordConfig);&#xA; &#xA;            //4. Set the default timeout for Commands that use interactivity&#xA;            Client.UseInteractivity(new InteractivityConfiguration()&#xA;            {&#xA;                Timeout = TimeSpan.FromMinutes(2)&#xA;            });&#xA; &#xA;            //5. Set up the Task Handler Ready event&#xA;            Client.Ready &#x2B;= OnClientReady;&#xA; &#xA;            //6. Set up the Commands Configuration&#xA;            var commandsConfig = new CommandsNextConfiguration()&#xA;            {&#xA;                StringPrefixes = new string[] { configJsonFile.prefix },&#xA;                EnableMentionPrefix = true,&#xA;                EnableDms = true,&#xA;                EnableDefaultHelp = false,&#xA;            };&#xA; &#xA;            Commands = Client.UseCommandsNext(commandsConfig);&#xA; &#xA;            //7. Register your commands&#xA;            var slashCommandsConfig = Client.UseSlashCommands();&#xA;            slashCommandsConfig.RegisterCommands<mysoundscommand>(MyGuildID);&#xA; &#xA;            //8. Allows usage of voice channels.&#xA;            var VoiceNext = Client.UseVoiceNext();&#xA; &#xA;            //9. Connect to get the Bot online&#xA;            await Client.ConnectAsync();&#xA;            await Task.Delay(-1);&#xA;        }&#xA; &#xA;        private static Task OnClientReady(DiscordClient sender, ReadyEventArgs e)&#xA;        {&#xA;            return Task.CompletedTask;&#xA;        }&#xA;    }&#xA;</mysoundscommand>

    &#xA;

    SourceCode Link :

    &#xA;

    text

    &#xA;

    playing the playsound slash command but wasn't expecting it to not play the mp3 file.

    &#xA;

    everything else worked fine except when it transmits the sound it doesn't play it.

    &#xA;

  • libav + AV_PIX_FMT_YUV420P + nvjpeg gives green images

    18 mai 2023, par george_d

    I need to grab frames from remote source and save them as JPEG, and I want to utilize GPU for that purpose.

    &#xA;

    To achieve that, I made my own grabber based on this libav example, which decodes frames using hardware. After that I pass them to nvjpeg.

    &#xA;

    I also set software frame to be in format of planar yuv 4:2:0 (and not nv12, which is not planar), which is mandatory for nvjpeg's nvjpegEncodeYUV function.

    &#xA;

    But as I pass the frame to nvjpegEncodeYUV(), the resulting frame comes in green (example).

    &#xA;

    So, here is the libav code :

    &#xA;

    static void&#xA;encode_to_jpeg(const uint8_t* raw_data,&#xA;               const int size,&#xA;               const int width,&#xA;               const int height,&#xA;               char* output_filename)&#xA;{&#xA;  JpegCoder jpegCoder = JpegCoder();&#xA;  JpegCoderImage* jpegImage =&#xA;    new JpegCoderImage(width, height, 3, JPEGCODER_CSS_420);&#xA;  jpegImage->fill(raw_data);&#xA;  JpegCoderBytes* dataContainer = jpegCoder.encode(jpegImage, 70);&#xA;&#xA;  maybe_create_dir_for_output_filename(output_filename);&#xA;  write_bin_data_to_file(&#xA;    output_filename, (char*)dataContainer->data, dataContainer->size);&#xA;&#xA;  delete dataContainer;&#xA;  delete jpegImage;&#xA;}&#xA;&#xA;static int&#xA;process_packet(AVCodecContext* avctx,&#xA;               AVPacket* packet)&#xA;{&#xA;  AVFrame* frame = NULL;&#xA;  AVFrame* sw_frame = NULL;&#xA;  AVFrame* tmp_frame = NULL;&#xA;  uint8_t* buffer = NULL;&#xA;  char* frame_filename = NULL;&#xA;  int size;&#xA;  int ret = 0;&#xA;&#xA;  ret = avcodec_send_packet(avctx, packet);&#xA;  if (ret &lt; 0) {&#xA;    av_log(NULL, AV_LOG_ERROR, "Error during decoding\n");&#xA;    return ret;&#xA;  }&#xA;&#xA;  while (true) {&#xA;    if (!(frame = av_frame_alloc()) || !(sw_frame = av_frame_alloc())) {&#xA;      av_log(NULL, AV_LOG_ERROR, "Can not alloc frame\n");&#xA;      ret = AVERROR(ENOMEM);&#xA;      goto fail;&#xA;    }&#xA;&#xA;    sw_frame->format = AV_PIX_FMT_YUV420P; // here i force the frames to be in yuv 4:2:0 planar format&#xA;&#xA;    ret = avcodec_receive_frame(avctx, frame);&#xA;    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;      av_frame_free(&amp;frame);&#xA;      av_frame_free(&amp;sw_frame);&#xA;      av_freep(&amp;buffer);&#xA;      return 0;&#xA;    } else if (ret &lt; 0) {&#xA;      av_log(NULL, AV_LOG_ERROR, "Error while decoding\n");&#xA;      goto fail;&#xA;    }&#xA;&#xA;    if (frame->format == hw_pix_fmt) {&#xA;      // pass the data from GPU to CPU&#xA;      if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) &lt; 0) {&#xA;        av_log(&#xA;          NULL, AV_LOG_ERROR, "Error transferring the data to system memory\n");&#xA;        goto fail;&#xA;      }&#xA;      tmp_frame = sw_frame;&#xA;    } else {&#xA;      tmp_frame = frame;&#xA;    }&#xA;&#xA;    size = av_image_get_buffer_size(&#xA;      (AVPixelFormat)tmp_frame->format, tmp_frame->width, tmp_frame->height, 1);&#xA;&#xA;    buffer = (uint8_t*)av_malloc(size);&#xA;    if (!buffer) {&#xA;      av_log(NULL, AV_LOG_ERROR, "Can not alloc buffer\n");&#xA;      ret = AVERROR(ENOMEM);&#xA;      goto fail;&#xA;    }&#xA;    ret = av_image_copy_to_buffer(buffer,&#xA;                                  size,&#xA;                                  (const uint8_t* const*)tmp_frame->data,&#xA;                                  (const int*)tmp_frame->linesize,&#xA;                                  (AVPixelFormat)tmp_frame->format,&#xA;                                  tmp_frame->width,&#xA;                                  tmp_frame->height,&#xA;                                  1);&#xA;    if (ret &lt; 0) {&#xA;      av_log(NULL, AV_LOG_ERROR, "Can not copy image to buffer\n");&#xA;      goto fail;&#xA;    }&#xA;    frame_filename = get_frame_filename((uintmax_t)avctx->frame_number);&#xA;    encode_to_jpeg(&#xA;      buffer, size, tmp_frame->width, tmp_frame->height, frame_filename);&#xA;    free(frame_filename);&#xA;&#xA;  fail:&#xA;    // av_frame_free(&amp;filtered_frame);&#xA;    av_frame_free(&amp;frame);&#xA;    av_frame_free(&amp;sw_frame);&#xA;    av_freep(&amp;buffer);&#xA;    if (ret &lt; 0) {&#xA;      return ret;&#xA;    }&#xA;  }&#xA;}&#xA;&#xA;

    &#xA;

    Basically, I adopted nvjpeg part from the nvjpeg Python wrapper, so here i will post only the differing parts.

    &#xA;

    #define JPEGCODER_GLOBAL_CONTEXT                                               \&#xA;  ((NvJpegGlobalContext*)(JpegCoder::_global_context))&#xA;#define ChromaSubsampling_Covert_JpegCoderToNvJpeg(subsampling)                \&#xA;  ((nvjpegChromaSubsampling_t)(subsampling))&#xA;#define ChromaSubsampling_Covert_NvJpegToJpegCoder(subsampling)                \&#xA;  ((JpegCoderChromaSubsampling)(subsampling))&#xA;&#xA;size_t&#xA;getBufferSize(size_t width, size_t height)&#xA;{&#xA;  return (size_t)(width * height);&#xA;}&#xA;&#xA;JpegCoderImage::JpegCoderImage(size_t width,&#xA;                               size_t height,&#xA;                               short nChannel,&#xA;                               JpegCoderChromaSubsampling subsampling)&#xA;{&#xA;  unsigned char* pBuffer = nullptr;&#xA;  cudaError_t eCopy =&#xA;    cudaMalloc((void**)&amp;pBuffer, width * height * NVJPEG_MAX_COMPONENT);&#xA;  if (cudaSuccess != eCopy) {&#xA;    throw JpegCoderError(eCopy, cudaGetErrorString(eCopy));&#xA;  }&#xA;&#xA;  this->height = height;&#xA;  this->width = width;&#xA;  this->nChannel = nChannel;&#xA;  this->subsampling = subsampling;&#xA;&#xA;  nvjpegImage_t* img = (nvjpegImage_t*)malloc(sizeof(nvjpegImage_t));&#xA;  // More verbose, but readable&#xA;  img->channel[0] = pBuffer;&#xA;  img->channel[1] = pBuffer &#x2B; (width * height);&#xA;  img->channel[2] = pBuffer &#x2B; (width * height) &#x2B; ((width / 2) * height);&#xA;  img->channel[3] = NULL;&#xA;&#xA;  img->pitch[0] = (unsigned int)width;&#xA;  img->pitch[1] = (unsigned int)width / 2;&#xA;  img->pitch[2] = (unsigned int)width / 2;&#xA;  img->pitch[3] = 0;&#xA;&#xA;  this->img = img;&#xA;}&#xA;&#xA;void&#xA;JpegCoderImage::fill(const unsigned char* data)&#xA;{&#xA;  cudaError_t eCopy = cudaMemcpy(((nvjpegImage_t*)(this->img))->channel[0],&#xA;                                 data,&#xA;                                 getBufferSize(width, height),&#xA;                                 cudaMemcpyHostToDevice);&#xA;  if (cudaSuccess != eCopy) {&#xA;    throw JpegCoderError(eCopy, cudaGetErrorString(eCopy));&#xA;  }&#xA;  this->subsampling = JPEGCODER_CSS_420;&#xA;}&#xA;&#xA;&#xA;JpegCoderBytes*&#xA;JpegCoder::encode(JpegCoderImage* img, int quality)&#xA;{&#xA;  nvjpegHandle_t nv_handle = JPEGCODER_GLOBAL_CONTEXT->nv_handle;&#xA;  nvjpegEncoderState_t nv_enc_state = JPEGCODER_GLOBAL_CONTEXT->nv_enc_state;&#xA;  nvjpegEncoderParams_t nv_enc_params;&#xA;&#xA;  nvjpegEncoderParamsCreate(nv_handle, &amp;nv_enc_params, NULL);&#xA;&#xA;  nvjpegEncoderParamsSetQuality(nv_enc_params, quality, NULL);&#xA;  nvjpegEncoderParamsSetOptimizedHuffman(nv_enc_params, 1, NULL);&#xA;  nvjpegEncoderParamsSetSamplingFactors(&#xA;    nv_enc_params,&#xA;    ChromaSubsampling_Covert_JpegCoderToNvJpeg(img->subsampling),&#xA;    NULL);&#xA;  int nReturnCode = nvjpegEncodeYUV(nv_handle,&#xA;                                    nv_enc_state,&#xA;                                    nv_enc_params,&#xA;                                    (nvjpegImage_t*)(img->img),&#xA;                                    ChromaSubsampling_Covert_JpegCoderToNvJpeg(img->subsampling),&#xA;                                    (int)img->width,&#xA;                                    (int)img->height,&#xA;                                    NULL);&#xA;  if (NVJPEG_STATUS_SUCCESS != nReturnCode) {&#xA;    throw JpegCoderError(nReturnCode, "NvJpeg Encoder Error");&#xA;  }&#xA;&#xA;  size_t length;&#xA;  nvjpegEncodeRetrieveBitstream(nv_handle, nv_enc_state, NULL, &amp;length, NULL);&#xA;&#xA;  JpegCoderBytes* jpegData = new JpegCoderBytes(length);&#xA;  nvjpegEncodeRetrieveBitstream(&#xA;    nv_handle, nv_enc_state, jpegData->data, &amp;(jpegData->size), NULL);&#xA;&#xA;  nvjpegEncoderParamsDestroy(nv_enc_params);&#xA;  return jpegData;&#xA;}&#xA;

    &#xA;

    I tried removing implicit pixel format conversion and implementing nv12 to yuv420p conversion by myself, but it gave the same result.

    &#xA;

    I also tried using AV_PIX_FMT_BGR24 and nvJpegEncode, which did not work either - pictures become completely messed up.

    &#xA;

    The only thing worked for me before was using swscale + AV_PIX_FMT_BGR24 + nvjpegEncodeImage - but swscale gives large CPU overhead, which is not something I want to have.

    &#xA;

    How can I make this thing work properly ?

    &#xA;