Recherche avancée

Médias (0)

Mot : - Tags -/xmlrpc

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (100)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

Sur d’autres sites (14416)

  • FFmpeg/libav : YUV420P to RGB conversion

    17 janvier 2014, par learner

    I am working with Video encoding-decoding based on online tutorials. In the encoding section, the dummy image created is in YUV420P format. I need it to be in RGB or BGR format. Any idea how to do this ??

    #include
    #include
    #include

    #ifdef HAVE_AV_CONFIG_H
    #undef HAVE_AV_CONFIG_H
    #endif

    #include "libavcodec/avcodec.h"
    #include "libavutil/mathematics.h"

    #define INBUF_SIZE 4096
    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096

    /*
    * Video encoding example
    */
    static void video_encode_example(const char *filename)
    {
        AVCodec *codec;
        AVCodecContext *c = NULL;
        int i, out_size, size, x, y, outbuf_size;
        FILE *f;
        AVFrame *picture;
        uint8_t *outbuf, *picture_buf;

        printf("Video encoding\n");

        /* find the mpeg1 video encoder */
        codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
        if (!codec)
        {
            fprintf(stderr, "codec not found\n");
            exit(1);
        }

        c = avcodec_alloc_context();
        picture = avcodec_alloc_frame();

        /* put sample parameters */
        c->bit_rate = 400000;
        /* resolution must be a multiple of two */
        c->width = 352;
        c->height = 288;
        /* frames per second */
        c->time_base= (AVRational){1,25};
        c->gop_size = 10; /* emit one intra frame every ten frames */
        c->max_b_frames=1;
        c->pix_fmt = PIX_FMT_YUV420P;

        /* open it */
        if (avcodec_open(c, codec) < 0)
        {
            fprintf(stderr, "could not open codec\n");
            exit(1);
        }

        f = fopen(filename, "wb");
        if (!f)
        {
            fprintf(stderr, "could not open file! %s\n", filename);
            exit(1);
        }

        /* alloc image and output buffer */
        outbuf_size = 100000;
        outbuf = malloc(outbuf_size);
        size = c->width * c->height;
        picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */

        picture->data[0] = picture_buf;
        picture->data[1] = picture->data[0] + size;
        picture->data[2] = picture->data[1] + size / 4;
        picture->linesize[0] = c->width;
        picture->linesize[1] = c->width / 2;
        picture->linesize[2] = c->width / 2;

        /* encode 1 second of video */
        for(i=0; i<25; i++)
        {
            fflush(stdout);
            /* prepare a dummy image */
            /* Y */
            for(y=0; y < c->height; y++)
            {
                for(x=0; x < c->width; x++)
                {
                    picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
                }
            }

            /* Cb and Cr */
            for(y=0; y < c->height/2; y++)
            {
                for(x=0; x < c->width/2; x++)
                {
                    picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
                    picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
                }
            }

            /* encode the image */
            out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
            printf("encoding frame %3d (size=%5d)\n", i, out_size);
            fwrite(outbuf, 1, out_size, f);
        }

        /* get the delayed frames */
        for(; out_size; i++)
        {
            fflush(stdout);

            out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
            printf("write frame %3d (size=%5d)\n", i, out_size);
            fwrite(outbuf, 1, out_size, f);
        }

        /* add sequence end code to have a real mpeg file */
        outbuf[0] = 0x00;
        outbuf[1] = 0x00;
        outbuf[2] = 0x01;
        outbuf[3] = 0xb7;
        fwrite(outbuf, 1, 4, f);
        fclose(f);
        free(picture_buf);
        free(outbuf);

        avcodec_close(c);
        av_free(c);
        av_free(picture);
        printf("\n");
    }

    /*
     * Video decoding example
     */

    static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,
                         char *filename)
    {
        FILE *f;
        int i;

        f=fopen(filename,"w");
        fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255);
        for(i=0; i* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
        memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);

        printf("Video decoding\n");

        /* find the mpeg1 video decoder */
        codec = avcodec_find_decoder(CODEC_ID_MPEG1VIDEO);
        if (!codec) {
            fprintf(stderr, "codec not found\n");
            exit(1);
        }

        c = avcodec_alloc_context();
        picture = avcodec_alloc_frame();

        if(codec->capabilities&CODEC_CAP_TRUNCATED)
            c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */

        /* For some codecs, such as msmpeg4 and mpeg4, width and height
           MUST be initialized there because this information is not
           available in the bitstream. */

        /* open it */
        if (avcodec_open(c, codec) < 0) {
            fprintf(stderr, "could not open codec\n");
            exit(1);
        }

        /* the codec gives us the frame size, in samples */

        f = fopen(filename, "rb");
        if (!f) {
            fprintf(stderr, "could not open file! %s\n", filename);
            exit(1);
        }

        frame = 0;
        for(;;) {
            avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
            if (avpkt.size == 0)
                break;

            /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
               and this is the only method to use them because you cannot
               know the compressed data size before analysing it.

               BUT some other codecs (msmpeg4, mpeg4) are inherently frame
               based, so you must call them with all the data for one
               frame exactly. You must also initialize 'width' and
               'height' before initializing them. */

            /* NOTE2: some codecs allow the raw parameters (frame size,
               sample rate) to be changed at any frame. We handle this, so
               you should also take care of it */

            /* here, we use a stream based decoder (mpeg1video), so we
               feed decoder and see if it could decode a frame */

            avpkt.data = inbuf;
            while (avpkt.size > 0)
            {
                len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
                if (len < 0)
                {
                    fprintf(stderr, "Error while decoding frame %d\n", frame);
                    exit(1);
                }
                if (got_picture)
                {
                    printf("saving frame %3d\n", frame);
                    fflush(stdout);

                    /* the picture is allocated by the decoder. no need to
                       free it */
                    snprintf(buf, sizeof(buf), outfilename, frame);
                    pgm_save(picture->data[0], picture->linesize[0],
                             c->width, c->height, buf);
                    frame++;
                }
                avpkt.size -= len;
                avpkt.data += len;
            }
        }

        /* some codecs, such as MPEG, transmit the I and P frame with a
           latency of one frame. You must do the following to have a
           chance to get the last frame of the video */

        avpkt.data = NULL;
        avpkt.size = 0;
        len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
        if (got_picture)
        {
            printf("saving last frame %3d\n", frame);
            fflush(stdout);

            /* the picture is allocated by the decoder. no need to
               free it */
            snprintf(buf, sizeof(buf), outfilename, frame);
            pgm_save(picture->data[0], picture->linesize[0],
                     c->width, c->height, buf);
            frame++;
        }

        fclose(f);

        avcodec_close(c);
        av_free(c);
        av_free(picture);
        printf("\n");
    }

    int main(int argc, char **argv)
    {
        const char *filename;

        /* must be called before using avcodec lib */
        avcodec_init();

        /* register all the codecs */
        avcodec_register_all();

        if (argc <= 1)
        {
            video_encode_example("asdf.mpg");
            filename = "asdf.mpg";
        }
        else
        {
            filename = argv[1];
        }

        video_decode_example("%d.pgm", filename);

        return 0;
    }

    I tried with PIX_FMT_RGB24 and changing each channel accordingly. For this, I declared another :

    AVFrame *pictureRGB ; and then : pictureRGB = avcodec_alloc_frame() ;

    for(y=0; y < c->height; y++)
    {
        for(x=0; x < c->width; x++)
        {
             pictureRGB ->data[0][y * pictureRGB ->linesize[0] + x] = x + y + i * 3;
             pictureRGB ->data[1][y * pictureRGB ->linesize[1] + x] = x + y + i * 3;
             pictureRGB ->data[2][y * pictureRGB ->linesize[2] + x] = x + y + i * 3;
        }
    }

    But it gives errors ! I am totally new to this library. Is it possible to directly encode as a RGB dummy image rather than as YUV420P. Anybody out there with sound knowledge in this area ??? Thanks in advance !

  • FFmpeg unexpected behavior using -loop flag

    7 décembre 2020, par all jazz

    Dear hackers of the world !

    


    I've been trying to use the beloved FFmpeg library to create a video from an image loop and audio using the famous Docker FFmpeg image, but it has been driving me crazy not producing the expected results (the results that I get when I run the ffmpeg command with the equivalent version on my Macbook).

    


    Here is the command :

    


    docker run -v $(pwd):$(pwd) -w $(pwd) jrottenberg/ffmpeg:4.3-alpine \
    -y \
    -stats \
    -loop 1 -i files/image.jpg \
    -i files/a.mp3 \
    -c:v libx265 -pix_fmt yuv420p10 \
    -c:a aac \
    -movflags +faststart \
    -shortest \
    -f mp4 test.mp4


    


    It should create a test.mp4 with the provided audio and image that is ready to be uploaded to the unfortunate Youtube.

    


    When I do this, the video seems to be lacking moov atoms (if I try to analyse it). Strangely enough, if I run this two times using the Docker image (overriding the same file), the video file will magically start to work.

    


    I also tried using different ffmpeg os images and versions. It seems that ffmpeg docummentation and code repo could also benefit from some care and love.

    


    What else I could do to get this fixed ?

    


    Here is the output from the console :

    


            -y \
        -stats \
        -loop 1 -i files/image.jpg \
        -i files/a.mp3 \
        -c:v libx265 -pix_fmt yuv420p10 \
        -c:a aac \
        -movflags +faststart \
        -shortest \
        -f mp4 test30.mp4
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 6.4.0 (Alpine 6.4.0)
  configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-fontconfig --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxcb --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-postproc --enable-small --enable-version3 --enable-libbluray --enable-libzmq --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-libopenjpeg --enable-libkvazaar --enable-libaom --extra-libs=-lpthread --enable-libsrt --enable-libaribb24 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, image2, from 'files/image.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 34300 kb/s
    Stream #0:0: Video: mjpeg, gray(bt470bg/unknown/unknown), 500x500 [SAR 240:240 DAR 1:1], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, mp3, from 'files/a.mp3':
  Metadata:
    title           : Visions
    artist          : Hattori Hanzo
    album           : Visions
    encoded_by      : Fission
    encoder         : Lavf58.45.100
    TLEN            : 16039
    track           : 1
  Duration: 00:00:16.04, start: 0.000000, bitrate: 199 kb/s
    Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 191 kb/s
    Stream #1:1: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 500x500 [SAR 300:300 DAR 1:1], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Other
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> hevc (libx265))
  Stream #1:0 -> #0:1 (mp3 (mp3float) -> aac (native))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.1.1+1-04b37fdfd2dc
x265 [info]: build info [Linux][GCC 6.4.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-3 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 3 / wpp(8 rows)
x265 [warning]: Source height < 720p; disabling lookahead-slices
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias: 25 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip signhide tmvp b-intra
x265 [info]: tools: strong-intra-smoothing deblock sao
Output #0, mp4, to 'test30.mp4':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: hevc (libx265) (hev1 / 0x31766568), yuv420p10le(progressive), 500x500 [SAR 1:1 DAR 1:1], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.91.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.91.100 aac
frame=   52 fps=0.0 q=33.0 size=       0kB time=00:00:00.80 bitrate=   0.4kbits/frame=  120 fps=119 q=33.0 size=       0kB time=00:00:03.52 bitrate=   0.1kbits/frame=  190 fps=125 q=33.0 size=       0kB time=00:00:06.33 bitrate=   0.1kbits/frame=  257 fps=127 q=33.0 size=       0kB time=00:00:09.00 bitrate=   0.0kbits/frame=  303 fps=120 q=35.0 size=     256kB time=00:00:10.86 bitrate= 193.0kbits/frame=  373 fps=123 q=36.0 size=     256kB time=00:00:13.65 bitrate= 153.6kbits/[mp4 @ 0x55d481bc6980] Starting second pass: moving the moov atom to the beginning of the file
frame=  432 fps=121 q=36.0 Lsize=     379kB time=00:00:17.16 bitrate= 180.8kbits/s speed= 4.8x
video:107kB audio:255kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 4.667185%
x265 [info]: frame I:      2, Avg QP:23.55  kb/s: 8634.80
x265 [info]: frame P:    147, Avg QP:33.00  kb/s: 13.49
x265 [info]: frame B:    283, Avg QP:35.71  kb/s: 8.06
x265 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x265 [info]: consecutive B-frames: 34.2% 10.1% 20.8% 1.3% 33.6%

encoded 432 frames in 3.56s (121.32 fps), 49.84 kb/s, Avg QP:34.73
[aac @ 0x55d481b23ac0] Qavg: 563.168```


    


  • Issues with FFMPEG swresample and channel mapping

    19 mars 2024, par Joseph Katrinka

    Ive linked FFMPEG libs to a C++ project Im working on in VS2017 and have had mostly no problems with it so far.
Im currently trying to use it to extract audio from a movie file and save it as a wav file.
I managed to do this just fine, and my next step is to make a "split into mono". To make 2 mono wav files, one from the left channel and one from the right channel of a stereo file.
My code works for the orignal usecase, stereo to stereo (one wav file) and also works for when Im just doing the left, but when doing the right it fails.

    


    Exception thrown at 0x00007FF9603F2D20 (swresample-4.dll) in Matchbox.exe : 0xC0000005 : Access violation reading location 0x0000000000000000.

    


    This is the relevent code involved. It is failing inside the processing loop on line :
int ret = swr_convert_frame(swrCtx, resampledFrame, frame);

    


    /// FFMPEG init
    AVFormatContext* formatCtx = nullptr;
    AVCodecContext* codecCtx = nullptr;
    const AVCodec* codec = nullptr;
    SwrContext* swrCtx = nullptr;
    AVPacket* packet = nullptr;
    AVFrame* frame = nullptr;
    AVFrame* resampledFrame = nullptr;
    int audioStreamIndex = -1;

    int sampleRate;

    uint64_t in_channel_layout = AV_CH_LAYOUT_STEREO; /// we only care about stereo in for now
    uint64_t out_channel_layout = doMono ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;

    /// some redundancy in this stream setup/checking
    if (avformat_open_input(&formatCtx, movieFilePath.toRawUTF8(), nullptr, nullptr) < 0)
    {
        DBG("failed to open input file");
        return false;
    }
    if (avformat_find_stream_info(formatCtx, nullptr) < 0)
    {
        DBG("failed to find stream info");
        return false;
    }

    for (unsigned i = 0; i < formatCtx->nb_streams; i++) {
        if (formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
        {
            audioStreamIndex = i;
            break;
        }
    }
    if (audioStreamIndex == -1)
    {
        DBG("audio stream not found");
        return false;
    }

    codec = avcodec_find_decoder(formatCtx->streams[audioStreamIndex]->codecpar->codec_id);
    if (!codec)
    {
        DBG("decoder not found for audio stream");
        return false;
    }

    codecCtx = avcodec_alloc_context3(codec);
    if (avcodec_parameters_to_context(codecCtx, formatCtx->streams[audioStreamIndex]->codecpar) < 0)
    {
        DBG("failed to copy codec params to codec context");
        return false;
    }
    if (avcodec_open2(codecCtx, codec, nullptr) < 0)
    {
        DBG("failed to open codec");
        return false;
    }

    if (codecCtx->channels != 2)
    {
        DBG("unsupported channel layout");
        return false;
    }

    if (!codecCtx->channel_layout)
    {
        codecCtx->channel_layout = av_get_default_channel_layout(codecCtx->channels);
    }

    sampleRate = codecCtx->sample_rate; /// using this later for timecode calculation

    packet = av_packet_alloc();
    frame = av_frame_alloc();
    resampledFrame = av_frame_alloc();

    /// the input frame requires this info
    frame->format = codecCtx->sample_fmt;
    frame->channel_layout = codecCtx->channel_layout;
    frame->sample_rate = codecCtx->sample_rate;

    // does the resampled frame really need this?
    resampledFrame->format = AV_SAMPLE_FMT_S16;
    resampledFrame->channel_layout = out_channel_layout;
    resampledFrame->sample_rate = codecCtx->sample_rate;

    if (!packet || !frame || !resampledFrame)
    {
        DBG("failed to allocate packed or frame");
        return false;
    }

    /// Set up swrCtx for channel mapping if we need it
    swrCtx = swr_alloc();
    av_opt_set_int(swrCtx, "in_channel_layout", codecCtx->channel_layout, 0);
    av_opt_set_int(swrCtx, "out_channel_layout", out_channel_layout, 0);
    av_opt_set_int(swrCtx, "in_sample_rate", codecCtx->sample_rate, 0);
    av_opt_set_int(swrCtx, "out_sample_rate", codecCtx->sample_rate, 0);
    av_opt_set_sample_fmt(swrCtx, "in_sample_fmt", codecCtx->sample_fmt, 0);
    av_opt_set_sample_fmt(swrCtx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);

    /// channel mapping if we are doing mono
    if (doMono)
    {
        DBG("WE ARE DOING MONO");
        int in_channel_map[2];
        if (useLeft)
        {
            DBG("WE ARE DOING LEFT");
            in_channel_map[0] = AV_CH_FRONT_LEFT;
        }
        else
        {
            DBG("WE ARE DOING RIGHT");
            in_channel_map[0] = AV_CH_FRONT_RIGHT;
        }
        in_channel_map[1] = -1;
        swr_set_channel_mapping(swrCtx, in_channel_map);
    }
    

    if (swr_init(swrCtx) < 0)
    {
        DBG("failed to init resampler");
        return false;
    }

    AVFormatContext* outFormatCtx = nullptr;
    avformat_alloc_output_context2(&outFormatCtx, nullptr, nullptr, wavFilePath.toRawUTF8());
    if (!outFormatCtx)
    {
        DBG("failed to allocate output format context");
        return false;
    }

    AVStream* outStream = avformat_new_stream(outFormatCtx, nullptr);
    if (!outStream)
    {
        DBG("failed to create new stream for output");
        return false;
    }

    AVCodecContext* outCodecCtx = avcodec_alloc_context3(avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE));
    if (!outCodecCtx)
    {
        DBG("failed to allocate output codec context");
        return false;
    }

    outCodecCtx->sample_rate = codecCtx->sample_rate;
    outCodecCtx->channel_layout = out_channel_layout;
    outCodecCtx->channels = doMono ? 1 : 2;
    outCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
    outCodecCtx->bit_rate = 192000;
    outCodecCtx->time_base = (AVRational{ 1, outCodecCtx->sample_rate });

    if (avcodec_open2(outCodecCtx, avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE), nullptr) < 0)
    {
        DBG("failed to open output codec");
        return false;
    }

    outStream->time_base = outCodecCtx->time_base;
    if (avcodec_parameters_from_context(outStream->codecpar, outCodecCtx) < 0)
    {
        DBG("failed to copy codec params from context to stream");
        return false;
    }

    if (!(outFormatCtx->oformat->flags & AVFMT_NOFILE))
    {
        if (avio_open(&outFormatCtx->pb, wavFilePath.toRawUTF8(), AVIO_FLAG_WRITE) < 0)
        {
            DBG("failed to open output file");
            return false;
        }
    }

    if (avformat_write_header(outFormatCtx, nullptr) < 0)
    {
        DBG("failed to write header to output file");
        return false;
    }

    int64_t total_samples = 0;

    while (av_read_frame(formatCtx, packet) >= 0)
    {
        if (packet->stream_index == audioStreamIndex)
        {
            if (avcodec_send_packet(codecCtx, packet) < 0)
            {
                DBG("failed secnding packet to decoder");
                av_packet_unref(packet);
                continue;
            }
            while (avcodec_receive_frame(codecCtx, frame) == 0)
            {
                int ret = swr_convert_frame(swrCtx, resampledFrame, frame);
                if (ret < 0)
                {
                    char errBuf[AV_ERROR_MAX_STRING_SIZE];
                    av_strerror(ret, errBuf, sizeof(errBuf));
                    DBG("Error resampling frame: " + std::string(errBuf));
                    continue;
                }

                resampledFrame->pts = av_rescale_q(total_samples, (AVRational{ 1, outCodecCtx->sample_rate }), outCodecCtx->time_base);
                total_samples += resampledFrame->nb_samples;

                AVPacket outPacket;
                av_init_packet(&outPacket);
                if (avcodec_send_frame(outCodecCtx, resampledFrame) < 0)
                {
                    DBG("error sending frame to decoder");
                    continue;
                }
                while (avcodec_receive_packet(outCodecCtx, &outPacket) == 0)
                {
                    outPacket.stream_index = outStream->index;
                    if (av_interleaved_write_frame(outFormatCtx, &outPacket) < 0)
                    {
                        av_packet_unref(&outPacket);
                        DBG("error writing packet to output file");
                        return false;
                    }
                    av_packet_unref(&outPacket);
                }
            }
        }
        av_packet_unref(packet);
    }

    /// trailer and cleanup
    av_write_trailer(outFormatCtx);

    avcodec_close(outCodecCtx);
    avcodec_close(codecCtx);
    avformat_close_input(&formatCtx);
    av_packet_free(&packet);
    av_frame_free(&frame);
    av_frame_free(&resampledFrame);
    swr_free(&swrCtx);
    if (!(outFormatCtx->oformat->flags & AVFMT_NOFILE)) avio_closep(&outFormatCtx->pb);
    avformat_free_context(outFormatCtx);


    


    Ive tried some debugging to see if the the values of either of the frames were unexpected or to see if the SwrContext might be unsual but did not manage anything. The thing I dont understand is the distinction that would cause this to fail for the right but not for when Im just doing the left.