Recherche avancée

Médias (0)

Mot : - Tags -/objet éditorial

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

Autres articles (78)

  • 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 (...)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • 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 (7758)

  • FFmpeg Idet with Timecode/Frame Number ?

    13 avril 2021, par Matt Cohen

    Is it possible to get ffmpeg to tell you which frames it thinks are interlaced/progressive when running the idet filter ?

    


    My use case is that when interlaced frames are detected in a file I need to be able to know which frames ffmpeg thinks are interlaced so I can easily pull them up and check if ffmpeg was correct in its assessment. Sometimes aliasing and thin lines in animation throw it off.

    


  • Anomalie #4710 (Nouveau) : Warning PHP SPIP 3.2.11 / PHP 7.2

    2 avril 2021

    Bonjour,

    J’ai ceci :
    PHP Warning : Use of undefined constant _PROTOCOLES_STD - assumed ’_PROTOCOLES_STD’ (this will throw an Error in a future version of PHP) in /home/www/ecrire/inc/lien.php on line 105
    PHP Warning : Use of undefined constant _SPIP_ECRIRE_SCRIPT - assumed ’_SPIP_ECRIRE_SCRIPT’ (this will throw an Error in a future version of PHP) in /home/www/ecrire/inc/utils.php on line 2044

    En PHP 7.2
    (obtenu avec spip-cli parce que le dossier local manquait)

  • Why does adding audio stream to ffmpeg's libavcodec output container cause a crash ?

    29 mars 2021, par Sniggerfardimungus

    As it stands, my project correctly uses libavcodec to decode a video, where each frame is manipulated (it doesn't matter how) and output to a new video. I've cobbled this together from examples found online, and it works. The result is a perfect .mp4 of the manipulated frames, minus the audio.

    


    My problem is, when I try to add an audio stream to the output container, I get a crash in mux.c that I can't explain. It's in static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt). Where st->internal->priv_pts->val = pkt->dts; is attempted, priv_pts is nullptr.

    


    I don't recall the version number, but this is from a November 4, 2020 ffmpeg build from git.

    


    My MediaContentMgr is much bigger than what I have here. I'm stripping out everything to do with the frame manipulation, so if I'm missing anything, please let me know and I'll edit.

    


    The code that, when added, triggers the nullptr exception, is called out inline

    


    The .h :

    


    #ifndef _API_EXAMPLE_H&#xA;#define _API_EXAMPLE_H&#xA;&#xA;#include <glad></glad>glad.h>&#xA;#include <glfw></glfw>glfw3.h>&#xA;#include "glm/glm.hpp"&#xA;&#xA;extern "C" {&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>avutil.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;}&#xA;&#xA;#include "shader_s.h"&#xA;&#xA;class MediaContainerMgr {&#xA;public:&#xA;    MediaContainerMgr(const std::string&amp; infile, const std::string&amp; vert, const std::string&amp; frag, &#xA;                      const glm::vec3* extents);&#xA;    ~MediaContainerMgr();&#xA;    void render();&#xA;    bool recording() { return m_recording; }&#xA;&#xA;    // Major thanks to "shi-yan" who helped make this possible:&#xA;    // https://github.com/shi-yan/videosamples/blob/master/libavmp4encoding/main.cpp&#xA;    bool init_video_output(const std::string&amp; video_file_name, unsigned int width, unsigned int height);&#xA;    bool output_video_frame(uint8_t* buf);&#xA;    bool finalize_output();&#xA;&#xA;private:&#xA;    AVFormatContext*   m_format_context;&#xA;    AVCodec*           m_video_codec;&#xA;    AVCodec*           m_audio_codec;&#xA;    AVCodecParameters* m_video_codec_parameters;&#xA;    AVCodecParameters* m_audio_codec_parameters;&#xA;    AVCodecContext*    m_codec_context;&#xA;    AVFrame*           m_frame;&#xA;    AVPacket*          m_packet;&#xA;    uint32_t           m_video_stream_index;&#xA;    uint32_t           m_audio_stream_index;&#xA;    &#xA;    void init_rendering(const glm::vec3* extents);&#xA;    int decode_packet();&#xA;&#xA;    // For writing the output video:&#xA;    void free_output_assets();&#xA;    bool                   m_recording;&#xA;    AVOutputFormat*        m_output_format;&#xA;    AVFormatContext*       m_output_format_context;&#xA;    AVCodec*               m_output_video_codec;&#xA;    AVCodecContext*        m_output_video_codec_context;&#xA;    AVFrame*               m_output_video_frame;&#xA;    SwsContext*            m_output_scale_context;&#xA;    AVStream*              m_output_video_stream;&#xA;    &#xA;    AVCodec*               m_output_audio_codec;&#xA;    AVStream*              m_output_audio_stream;&#xA;    AVCodecContext*        m_output_audio_codec_context;&#xA;};&#xA;&#xA;#endif&#xA;

    &#xA;

    And, the hellish .cpp :

    &#xA;

    #include &#xA;#include &#xA;#include &#xA;#include &#xA;#include &#xA;&#xA;#include "media_container_manager.h"&#xA;&#xA;MediaContainerMgr::MediaContainerMgr(const std::string&amp; infile, const std::string&amp; vert, const std::string&amp; frag,&#xA;    const glm::vec3* extents) :&#xA;    m_video_stream_index(-1),&#xA;    m_audio_stream_index(-1),&#xA;    m_recording(false),&#xA;    m_output_format(nullptr),&#xA;    m_output_format_context(nullptr),&#xA;    m_output_video_codec(nullptr),&#xA;    m_output_video_codec_context(nullptr),&#xA;    m_output_video_frame(nullptr),&#xA;    m_output_scale_context(nullptr),&#xA;    m_output_video_stream(nullptr)&#xA;{&#xA;    // AVFormatContext holds header info from the format specified in the container:&#xA;    m_format_context = avformat_alloc_context();&#xA;    if (!m_format_context) {&#xA;        throw "ERROR could not allocate memory for Format Context";&#xA;    }&#xA;    &#xA;    // open the file and read its header. Codecs are not opened here.&#xA;    if (avformat_open_input(&amp;m_format_context, infile.c_str(), NULL, NULL) != 0) {&#xA;        throw "ERROR could not open input file for reading";&#xA;    }&#xA;&#xA;    printf("format %s, duration %lldus, bit_rate %lld\n", m_format_context->iformat->name, m_format_context->duration, m_format_context->bit_rate);&#xA;    //read avPackets (?) from the avFormat (?) to get stream info. This populates format_context->streams.&#xA;    if (avformat_find_stream_info(m_format_context, NULL) &lt; 0) {&#xA;        throw "ERROR could not get stream info";&#xA;    }&#xA;&#xA;    for (unsigned int i = 0; i &lt; m_format_context->nb_streams; i&#x2B;&#x2B;) {&#xA;        AVCodecParameters* local_codec_parameters = NULL;&#xA;        local_codec_parameters = m_format_context->streams[i]->codecpar;&#xA;        printf("AVStream->time base before open coded %d/%d\n", m_format_context->streams[i]->time_base.num, m_format_context->streams[i]->time_base.den);&#xA;        printf("AVStream->r_frame_rate before open coded %d/%d\n", m_format_context->streams[i]->r_frame_rate.num, m_format_context->streams[i]->r_frame_rate.den);&#xA;        printf("AVStream->start_time %" PRId64 "\n", m_format_context->streams[i]->start_time);&#xA;        printf("AVStream->duration %" PRId64 "\n", m_format_context->streams[i]->duration);&#xA;        printf("duration(s): %lf\n", (float)m_format_context->streams[i]->duration / m_format_context->streams[i]->time_base.den * m_format_context->streams[i]->time_base.num);&#xA;        AVCodec* local_codec = NULL;&#xA;        local_codec = avcodec_find_decoder(local_codec_parameters->codec_id);&#xA;        if (local_codec == NULL) {&#xA;            throw "ERROR unsupported codec!";&#xA;        }&#xA;&#xA;        if (local_codec_parameters->codec_type == AVMEDIA_TYPE_VIDEO) {&#xA;            if (m_video_stream_index == -1) {&#xA;                m_video_stream_index = i;&#xA;                m_video_codec = local_codec;&#xA;                m_video_codec_parameters = local_codec_parameters;&#xA;            }&#xA;            m_height = local_codec_parameters->height;&#xA;            m_width = local_codec_parameters->width;&#xA;            printf("Video Codec: resolution %dx%d\n", m_width, m_height);&#xA;        }&#xA;        else if (local_codec_parameters->codec_type == AVMEDIA_TYPE_AUDIO) {&#xA;            if (m_audio_stream_index == -1) {&#xA;                m_audio_stream_index = i;&#xA;                m_audio_codec = local_codec;&#xA;                m_audio_codec_parameters = local_codec_parameters;&#xA;            }&#xA;            printf("Audio Codec: %d channels, sample rate %d\n", local_codec_parameters->channels, local_codec_parameters->sample_rate);&#xA;        }&#xA;&#xA;        printf("\tCodec %s ID %d bit_rate %lld\n", local_codec->name, local_codec->id, local_codec_parameters->bit_rate);&#xA;    }&#xA;&#xA;    m_codec_context = avcodec_alloc_context3(m_video_codec);&#xA;    if (!m_codec_context) {&#xA;        throw "ERROR failed to allocate memory for AVCodecContext";&#xA;    }&#xA;&#xA;    if (avcodec_parameters_to_context(m_codec_context, m_video_codec_parameters) &lt; 0) {&#xA;        throw "ERROR failed to copy codec params to codec context";&#xA;    }&#xA;&#xA;    if (avcodec_open2(m_codec_context, m_video_codec, NULL) &lt; 0) {&#xA;        throw "ERROR avcodec_open2 failed to open codec";&#xA;    }&#xA;&#xA;    m_frame = av_frame_alloc();&#xA;    if (!m_frame) {&#xA;        throw "ERROR failed to allocate AVFrame memory";&#xA;    }&#xA;&#xA;    m_packet = av_packet_alloc();&#xA;    if (!m_packet) {&#xA;        throw "ERROR failed to allocate AVPacket memory";&#xA;    }&#xA;}&#xA;&#xA;MediaContainerMgr::~MediaContainerMgr() {&#xA;    avformat_close_input(&amp;m_format_context);&#xA;    av_packet_free(&amp;m_packet);&#xA;    av_frame_free(&amp;m_frame);&#xA;    avcodec_free_context(&amp;m_codec_context);&#xA;&#xA;&#xA;    glDeleteVertexArrays(1, &amp;m_VAO);&#xA;    glDeleteBuffers(1, &amp;m_VBO);&#xA;}&#xA;&#xA;&#xA;bool MediaContainerMgr::advance_frame() {&#xA;    while (true) {&#xA;        if (av_read_frame(m_format_context, m_packet) &lt; 0) {&#xA;            // Do we actually need to unref the packet if it failed?&#xA;            av_packet_unref(m_packet);&#xA;            continue;&#xA;            //return false;&#xA;        }&#xA;        else {&#xA;            if (m_packet->stream_index == m_video_stream_index) {&#xA;                //printf("AVPacket->pts %" PRId64 "\n", m_packet->pts);&#xA;                int response = decode_packet();&#xA;                av_packet_unref(m_packet);&#xA;                if (response != 0) {&#xA;                    continue;&#xA;                    //return false;&#xA;                }&#xA;                return true;&#xA;            }&#xA;            else {&#xA;                printf("m_packet->stream_index: %d\n", m_packet->stream_index);&#xA;                printf("  m_packet->pts: %lld\n", m_packet->pts);&#xA;                printf("  mpacket->size: %d\n", m_packet->size);&#xA;                if (m_recording) {&#xA;                    int err = 0;&#xA;                    //err = avcodec_send_packet(m_output_video_codec_context, m_packet);&#xA;                    printf("  encoding error: %d\n", err);&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        // We&#x27;re done with the packet (it&#x27;s been unpacked to a frame), so deallocate &amp; reset to defaults:&#xA;/*&#xA;        if (m_frame == NULL)&#xA;            return false;&#xA;&#xA;        if (m_frame->data[0] == NULL || m_frame->data[1] == NULL || m_frame->data[2] == NULL) {&#xA;            printf("WARNING: null frame data");&#xA;            continue;&#xA;        }&#xA;*/&#xA;    }&#xA;}&#xA;&#xA;int MediaContainerMgr::decode_packet() {&#xA;    // Supply raw packet data as input to a decoder&#xA;    // https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga58bc4bf1e0ac59e27362597e467efff3&#xA;    int response = avcodec_send_packet(m_codec_context, m_packet);&#xA;&#xA;    if (response &lt; 0) {&#xA;        char buf[256];&#xA;        av_strerror(response, buf, 256);&#xA;        printf("Error while receiving a frame from the decoder: %s\n", buf);&#xA;        return response;&#xA;    }&#xA;&#xA;    // Return decoded output data (into a frame) from a decoder&#xA;    // https://ffmpeg.org/doxygen/trunk/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c&#xA;    response = avcodec_receive_frame(m_codec_context, m_frame);&#xA;    if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {&#xA;        return response;&#xA;    } else if (response &lt; 0) {&#xA;        char buf[256];&#xA;        av_strerror(response, buf, 256);&#xA;        printf("Error while receiving a frame from the decoder: %s\n", buf);&#xA;        return response;&#xA;    } else {&#xA;        printf(&#xA;            "Frame %d (type=%c, size=%d bytes) pts %lld key_frame %d [DTS %d]\n",&#xA;            m_codec_context->frame_number,&#xA;            av_get_picture_type_char(m_frame->pict_type),&#xA;            m_frame->pkt_size,&#xA;            m_frame->pts,&#xA;            m_frame->key_frame,&#xA;            m_frame->coded_picture_number&#xA;        );&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;&#xA;bool MediaContainerMgr::init_video_output(const std::string&amp; video_file_name, unsigned int width, unsigned int height) {&#xA;    if (m_recording)&#xA;        return true;&#xA;    m_recording = true;&#xA;&#xA;    advance_to(0L); // I&#x27;ve deleted the implmentation. Just seeks to beginning of vid. Works fine.&#xA;&#xA;    if (!(m_output_format = av_guess_format(nullptr, video_file_name.c_str(), nullptr))) {&#xA;        printf("Cannot guess output format.\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    int err = avformat_alloc_output_context2(&amp;m_output_format_context, m_output_format, nullptr, video_file_name.c_str());&#xA;    if (err &lt; 0) {&#xA;        printf("Failed to allocate output context.\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    //TODO(P0): Break out the video and audio inits into their own methods.&#xA;    m_output_video_codec = avcodec_find_encoder(m_output_format->video_codec);&#xA;    if (!m_output_video_codec) {&#xA;        printf("Failed to create video codec.\n");&#xA;        return false;&#xA;    }&#xA;    m_output_video_stream = avformat_new_stream(m_output_format_context, m_output_video_codec);&#xA;    if (!m_output_video_stream) {&#xA;        printf("Failed to find video format.\n");&#xA;        return false;&#xA;    } &#xA;    m_output_video_codec_context = avcodec_alloc_context3(m_output_video_codec);&#xA;    if (!m_output_video_codec_context) {&#xA;        printf("Failed to create video codec context.\n");&#xA;        return(false);&#xA;    }&#xA;    m_output_video_stream->codecpar->codec_id = m_output_format->video_codec;&#xA;    m_output_video_stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    m_output_video_stream->codecpar->width = width;&#xA;    m_output_video_stream->codecpar->height = height;&#xA;    m_output_video_stream->codecpar->format = AV_PIX_FMT_YUV420P;&#xA;    // Use the same bit rate as the input stream.&#xA;    m_output_video_stream->codecpar->bit_rate = m_format_context->streams[m_video_stream_index]->codecpar->bit_rate;&#xA;    m_output_video_stream->avg_frame_rate = m_format_context->streams[m_video_stream_index]->avg_frame_rate;&#xA;    avcodec_parameters_to_context(m_output_video_codec_context, m_output_video_stream->codecpar);&#xA;    m_output_video_codec_context->time_base = m_format_context->streams[m_video_stream_index]->time_base;&#xA;    &#xA;    //TODO(P1): Set these to match the input stream?&#xA;    m_output_video_codec_context->max_b_frames = 2;&#xA;    m_output_video_codec_context->gop_size = 12;&#xA;    m_output_video_codec_context->framerate = m_format_context->streams[m_video_stream_index]->r_frame_rate;&#xA;    //m_output_codec_context->refcounted_frames = 0;&#xA;    if (m_output_video_stream->codecpar->codec_id == AV_CODEC_ID_H264) {&#xA;        av_opt_set(m_output_video_codec_context, "preset", "ultrafast", 0);&#xA;    } else if (m_output_video_stream->codecpar->codec_id == AV_CODEC_ID_H265) {&#xA;        av_opt_set(m_output_video_codec_context, "preset", "ultrafast", 0);&#xA;    } else {&#xA;        av_opt_set_int(m_output_video_codec_context, "lossless", 1, 0);&#xA;    }&#xA;    avcodec_parameters_from_context(m_output_video_stream->codecpar, m_output_video_codec_context);&#xA;&#xA;    m_output_audio_codec = avcodec_find_encoder(m_output_format->audio_codec);&#xA;    if (!m_output_audio_codec) {&#xA;        printf("Failed to create audio codec.\n");&#xA;        return false;&#xA;    }&#xA;

    &#xA;

    I've commented out all of the audio stream init beyond this next line, because this is where&#xA;the trouble begins. Creating this output stream causes the null reference I mentioned. If I&#xA;uncomment everything below here, I still get the null deref. If I comment out this line, the&#xA;deref exception vanishes. (IOW, I commented out more and more code until I found that this&#xA;was the trigger that caused the problem.)

    &#xA;

    I assume that there's something I'm doing wrong in the rest of the commented out code, that,&#xA;when fixed, will fix the nullptr and give me a working audio stream.

    &#xA;

        m_output_audio_stream = avformat_new_stream(m_output_format_context, m_output_audio_codec);&#xA;    if (!m_output_audio_stream) {&#xA;        printf("Failed to find audio format.\n");&#xA;        return false;&#xA;    }&#xA;    /*&#xA;    m_output_audio_codec_context = avcodec_alloc_context3(m_output_audio_codec);&#xA;    if (!m_output_audio_codec_context) {&#xA;        printf("Failed to create audio codec context.\n");&#xA;        return(false);&#xA;    }&#xA;    m_output_audio_stream->codecpar->codec_id = m_output_format->audio_codec;&#xA;    m_output_audio_stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;&#xA;    m_output_audio_stream->codecpar->format = m_format_context->streams[m_audio_stream_index]->codecpar->format;&#xA;    m_output_audio_stream->codecpar->bit_rate = m_format_context->streams[m_audio_stream_index]->codecpar->bit_rate;&#xA;    m_output_audio_stream->avg_frame_rate = m_format_context->streams[m_audio_stream_index]->avg_frame_rate;&#xA;    avcodec_parameters_to_context(m_output_audio_codec_context, m_output_audio_stream->codecpar);&#xA;    m_output_audio_codec_context->time_base = m_format_context->streams[m_audio_stream_index]->time_base;&#xA;    */&#xA;&#xA;    //TODO(P2): Free assets that have been allocated.&#xA;    err = avcodec_open2(m_output_video_codec_context, m_output_video_codec, nullptr);&#xA;    if (err &lt; 0) {&#xA;        printf("Failed to open codec.\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    if (!(m_output_format->flags &amp; AVFMT_NOFILE)) {&#xA;        err = avio_open(&amp;m_output_format_context->pb, video_file_name.c_str(), AVIO_FLAG_WRITE);&#xA;        if (err &lt; 0) {&#xA;            printf("Failed to open output file.");&#xA;            return false;&#xA;        }&#xA;    }&#xA;&#xA;    err = avformat_write_header(m_output_format_context, NULL);&#xA;    if (err &lt; 0) {&#xA;        printf("Failed to write header.\n");&#xA;        return false;&#xA;    }&#xA;&#xA;    av_dump_format(m_output_format_context, 0, video_file_name.c_str(), 1);&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;&#xA;//TODO(P2): make this a member. (Thanks to https://emvlo.wordpress.com/2016/03/10/sws_scale/)&#xA;void PrepareFlipFrameJ420(AVFrame* pFrame) {&#xA;    for (int i = 0; i &lt; 4; i&#x2B;&#x2B;) {&#xA;        if (i)&#xA;            pFrame->data[i] &#x2B;= pFrame->linesize[i] * ((pFrame->height >> 1) - 1);&#xA;        else&#xA;            pFrame->data[i] &#x2B;= pFrame->linesize[i] * (pFrame->height - 1);&#xA;        pFrame->linesize[i] = -pFrame->linesize[i];&#xA;    }&#xA;}&#xA;

    &#xA;

    This is where we take an altered frame and write it to the output container. This works fine&#xA;as long as we haven't set up an audio stream in the output container.

    &#xA;

    bool MediaContainerMgr::output_video_frame(uint8_t* buf) {&#xA;    int err;&#xA;&#xA;    if (!m_output_video_frame) {&#xA;        m_output_video_frame = av_frame_alloc();&#xA;        m_output_video_frame->format = AV_PIX_FMT_YUV420P;&#xA;        m_output_video_frame->width = m_output_video_codec_context->width;&#xA;        m_output_video_frame->height = m_output_video_codec_context->height;&#xA;        err = av_frame_get_buffer(m_output_video_frame, 32);&#xA;        if (err &lt; 0) {&#xA;            printf("Failed to allocate output frame.\n");&#xA;            return false;&#xA;        }&#xA;    }&#xA;&#xA;    if (!m_output_scale_context) {&#xA;        m_output_scale_context = sws_getContext(m_output_video_codec_context->width, m_output_video_codec_context->height, &#xA;                                                AV_PIX_FMT_RGB24,&#xA;                                                m_output_video_codec_context->width, m_output_video_codec_context->height, &#xA;                                                AV_PIX_FMT_YUV420P, SWS_BICUBIC, nullptr, nullptr, nullptr);&#xA;    }&#xA;&#xA;    int inLinesize[1] = { 3 * m_output_video_codec_context->width };&#xA;    sws_scale(m_output_scale_context, (const uint8_t* const*)&amp;buf, inLinesize, 0, m_output_video_codec_context->height,&#xA;              m_output_video_frame->data, m_output_video_frame->linesize);&#xA;    PrepareFlipFrameJ420(m_output_video_frame);&#xA;    //TODO(P0): Switch m_frame to be m_input_video_frame so I don&#x27;t end up using the presentation timestamp from&#xA;    //          an audio frame if I threadify the frame reading.&#xA;    m_output_video_frame->pts = m_frame->pts;&#xA;    printf("Output PTS: %d, time_base: %d/%d\n", m_output_video_frame->pts,&#xA;        m_output_video_codec_context->time_base.num, m_output_video_codec_context->time_base.den);&#xA;    err = avcodec_send_frame(m_output_video_codec_context, m_output_video_frame);&#xA;    if (err &lt; 0) {&#xA;        printf("  ERROR sending new video frame output: ");&#xA;        switch (err) {&#xA;        case AVERROR(EAGAIN):&#xA;            printf("AVERROR(EAGAIN): %d\n", err);&#xA;            break;&#xA;        case AVERROR_EOF:&#xA;            printf("AVERROR_EOF: %d\n", err);&#xA;            break;&#xA;        case AVERROR(EINVAL):&#xA;            printf("AVERROR(EINVAL): %d\n", err);&#xA;            break;&#xA;        case AVERROR(ENOMEM):&#xA;            printf("AVERROR(ENOMEM): %d\n", err);&#xA;            break;&#xA;        }&#xA;&#xA;        return false;&#xA;    }&#xA;&#xA;    AVPacket pkt;&#xA;    av_init_packet(&amp;pkt);&#xA;    pkt.data = nullptr;&#xA;    pkt.size = 0;&#xA;    pkt.flags |= AV_PKT_FLAG_KEY;&#xA;    int ret = 0;&#xA;    if ((ret = avcodec_receive_packet(m_output_video_codec_context, &amp;pkt)) == 0) {&#xA;        static int counter = 0;&#xA;        printf("pkt.key: 0x%08x, pkt.size: %d, counter:\n", pkt.flags &amp; AV_PKT_FLAG_KEY, pkt.size, counter&#x2B;&#x2B;);&#xA;        uint8_t* size = ((uint8_t*)pkt.data);&#xA;        printf("sizes: %d %d %d %d %d %d %d %d %d\n", size[0], size[1], size[2], size[2], size[3], size[4], size[5], size[6], size[7]);&#xA;        av_interleaved_write_frame(m_output_format_context, &amp;pkt);&#xA;    }&#xA;    printf("push: %d\n", ret);&#xA;    av_packet_unref(&amp;pkt);&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;bool MediaContainerMgr::finalize_output() {&#xA;    if (!m_recording)&#xA;        return true;&#xA;&#xA;    AVPacket pkt;&#xA;    av_init_packet(&amp;pkt);&#xA;    pkt.data = nullptr;&#xA;    pkt.size = 0;&#xA;&#xA;    for (;;) {&#xA;        avcodec_send_frame(m_output_video_codec_context, nullptr);&#xA;        if (avcodec_receive_packet(m_output_video_codec_context, &amp;pkt) == 0) {&#xA;            av_interleaved_write_frame(m_output_format_context, &amp;pkt);&#xA;            printf("final push:\n");&#xA;        } else {&#xA;            break;&#xA;        }&#xA;    }&#xA;&#xA;    av_packet_unref(&amp;pkt);&#xA;&#xA;    av_write_trailer(m_output_format_context);&#xA;    if (!(m_output_format->flags &amp; AVFMT_NOFILE)) {&#xA;        int err = avio_close(m_output_format_context->pb);&#xA;        if (err &lt; 0) {&#xA;            printf("Failed to close file. err: %d\n", err);&#xA;            return false;&#xA;        }&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;

    &#xA;

    EDIT&#xA;The call stack on the crash (which I should have included in the original question) :

    &#xA;

    avformat-58.dll!compute_muxer_pkt_fields(AVFormatContext * s, AVStream * st, AVPacket * pkt) Line 630   C&#xA;avformat-58.dll!write_packet_common(AVFormatContext * s, AVStream * st, AVPacket * pkt, int interleaved) Line 1122  C&#xA;avformat-58.dll!write_packets_common(AVFormatContext * s, AVPacket * pkt, int interleaved) Line 1186    C&#xA;avformat-58.dll!av_interleaved_write_frame(AVFormatContext * s, AVPacket * pkt) Line 1241   C&#xA;CamBot.exe!MediaContainerMgr::output_video_frame(unsigned char * buf) Line 553  C&#x2B;&#x2B;&#xA;CamBot.exe!main() Line 240  C&#x2B;&#x2B;&#xA;

    &#xA;

    If I move the call to avformat_write_header so it's immediately before the audio stream initialization, I still get a crash, but in a different place. The crash happens on line 6459 of movenc.c, where we have :

    &#xA;

    /* Non-seekable output is ok if using fragmentation. If ism_lookahead&#xA; * is enabled, we don&#x27;t support non-seekable output at all. */&#xA;if (!(s->pb->seekable &amp; AVIO_SEEKABLE_NORMAL) &amp;&amp;  //  CRASH IS HERE&#xA;    (!(mov->flags &amp; FF_MOV_FLAG_FRAGMENT) || mov->ism_lookahead)) {&#xA;    av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");&#xA;    return AVERROR(EINVAL);&#xA;}&#xA;

    &#xA;

    The exception is a nullptr exception, where s->pb is NULL. The call stack is :

    &#xA;

    avformat-58.dll!mov_init(AVFormatContext * s) Line 6459 C&#xA;avformat-58.dll!init_muxer(AVFormatContext * s, AVDictionary * * options) Line 407  C&#xA;[Inline Frame] avformat-58.dll!avformat_init_output(AVFormatContext *) Line 489 C&#xA;avformat-58.dll!avformat_write_header(AVFormatContext * s, AVDictionary * * options) Line 512   C&#xA;CamBot.exe!MediaContainerMgr::init_video_output(const std::string &amp; video_file_name, unsigned int width, unsigned int height) Line 424  C&#x2B;&#x2B;&#xA;CamBot.exe!main() Line 183  C&#x2B;&#x2B;&#xA;

    &#xA;