Convert to JPG in Job without creating garbage impossible?

Thank you, it works! For anyone stumbling over this thread and having the same problem, here is my solution:

BurstCompile]
private struct EncoderJob : IJob
{
    [ReadOnly] public NativeArray<byte> Input;
    [WriteOnly] public NativeArray<byte> Result;
    [WriteOnly] public NativeArray<int> EncodedDataLength;

    public int Width;
    public int Height;
    public int RowBytes;
    public int Quality;
    public GraphicsFormat GraphicsFormat;

    public unsafe void Execute()
    {
         NativeArray<byte> encodedDataNative = ImageConversion.EncodeNativeArrayToJPG(Input, GraphicsFormat, (uint)Width, (uint)Height, (uint)RowBytes, Quality);
         EncodedDataLength[0] = encodedDataNative.Length;
         void* internalPtr = NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(encodedDataNative);
         void* outputPtr = NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks<byte>(Result);
         UnsafeUtility.MemCpy(outputPtr, internalPtr, encodedDataNative.Length * UnsafeUtility.SizeOf<byte>());
         encodedDataNative.Dispose();
    }
}
private void StartEncoderJob(NativeArray<byte> textureData)
{
    // prepare job
    EncoderJob job = new EncoderJob();
    NativeArray<byte> jpgDataPool = GetPooledJpgDataArray(textureData.Length);
    NativeArray<int> jpgDataLength = GetPooledJpgLengthArray();

    // textureData was created before this method was called and contains a copy of the async result data
    job.Input = textureData;
    job.Result = jpgDataPool;
    job.EncodedDataLength = jpgDataLength;
    job.Width = _currentWidth;
    job.Height = _currentHeight;
    job.RowBytes = 0;
    job.Quality = _encodingQuality;
    job.GraphicsFormat = _renderTexture.graphicsFormat;

    JobHandle handle = job.Schedule();
    PendingJob pendingJob = GetPooledPendingJob();
    pendingJob.Handle = handle;
    pendingJob.Job = job;
    pendingJob.CreationTime = Time.time;
    _pendingJobs.Add(pendingJob);
}

Make sure you have “allow unsafe code” enabled in your player settings AND if you are using assemblies, you will have to tick the “allow unsafe code” checkbox in them as well.

I got the code from this thread. Note, that I do not call the NativeArray.Resize function since I know that Result is definetely bigger than encodedDataNative. I do NOT guarantee safety of this code, but if I ever find a problem with it, I will keep this thread here updated.