Recherche avancée

Médias (1)

Mot : - Tags -/censure

Autres articles (42)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (5862)

  • FFmpeg CRF control using x264 vs libvpx-vp9

    19 octobre 2016, par igon

    I have some experience using ffmpeg with x264 and I wanted to do a comparison with libvpx-vp9. I tested a simple single pass encoding of a raw video, varying the crf settings and presets both with x264 and libvpx-vp9. I am new to libvpx and I followed this and this carefully but I might have still specified wrong combination of parameters since the results I get do not make much sense to me.

    For x264 I did :

    ffmpeg -i test_video.y4m -c:v libx264 -threads 1 -crf <crf> -preset <preset> -y output.mkv
    </preset></crf>

    and obtained the following results :

    codec  , settings                        , time        , PSNR      ,bitrate
    libx264,['-crf', '20', '-preset', 'fast'],13.1897280216, 42.938337 ,15728
    libx264,['-crf', '20', '-preset', 'medium'],16.80494689, 42.879753 ,15287
    libx264,['-crf', '20', '-preset', 'slow'],25.1142120361, 42.919206 ,15400
    libx264,['-crf', '30', '-preset', 'fast'],8.79047083855, 37.975141 ,4106
    libx264,['-crf', '30', '-preset', 'medium'],9.936599016, 37.713778 ,3749
    libx264,['-crf', '30', '-preset', 'slow'],13.0959510803, 37.569511 ,3555

    This makes sense to me, given a crf value you get a value of PSNR and changing the preset can decrease the bitrate but increase the time to encode.

    For libvpx-vp9 I did :

    ffmpeg -i test_video.y4m -c:v libvpx-vp9 -threads 1 -crf <crf> -cpu-used <effort> -y output.mkv
    </effort></crf>

    First of all I thought from tutorials online that the -cpu-used option is equivalent to -preset in x264. Is that correct ? If so what is the difference with -quality ? Furthermore since the range goes from -8 to 8 I assumed that negative values where the fast options while positive values the slowest. Results I get are very confusing though :

    codec     , settings                      , time        , PSNR     ,bitrate
    libvpx-vp9,['-crf', '20', '-cpu-used', '-2'],19.6644911766,32.54317,571
    libvpx-vp9,['-crf', '20', '-cpu-used', '0'],176.670887947,32.69899,564
    libvpx-vp9,['-crf', '20', '-cpu-used', '2'],20.0206270218,32.54317,571
    libvpx-vp9,['-crf', '30', '-cpu-used', '-2'],19.7931578159,32.54317,571
    libvpx-vp9,['-crf', '30', '-cpu-used', '0'],176.587754965,32.69899,564
    libvpx-vp9,['-crf', '30', '-cpu-used', '2'],19.8394429684,32.54317,571

    Bitrate is very low and PSNR seems unaffected by the crf setting (and very low compared to x264). The -cpu-used setting has very minimal impact and also seems that -2 and 2 are the same option.. What am I missing ? I expected libvpx to take more time to encode (which is definitely true) but at the same time higher quality transcodes. What parameters should I use to
    have a fair comparison with x264 ?

    Edit : Thanks to @mulvya and this doc I figured that to work in crf mode with libvpx I have to add -b:v 0. I re-ran my tests and I get :

       codec     , settings                                 , time        , PSNR     ,bitrate
    libvpx-vp9,['-crf', '20', '-b:v', '0', '-cpu-used', '-2'],57.6835780144,45.111158,17908
    libvpx-vp9,['-crf', '20', '-b:v', '0', '-cpu-used', '0'] ,401.360313892,45.285367,17431
    libvpx-vp9,['-crf', '20', '-b:v', '0', '-cpu-used', '2'] ,57.4941239357,45.111158,17908
    libvpx-vp9,['-crf', '30', '-b:v', '0', '-cpu-used', '-2'],49.175855875,42.588178,11085
    libvpx-vp9,['-crf', '30', '-b:v', '0', '-cpu-used', '0'] ,347.158324957,42.782194,10935
    libvpx-vp9,['-crf', '30', '-b:v', '0', '-cpu-used', '2'] ,49.1892938614,42.588178,11085

    PSNR and bitrate went up significantly by adding -b:v 0

  • FFMPEG : Get the Scene Change Detection value for all frame

    19 novembre 2016, par celacanto

    I’m trying to measure how much a movies is "fast" (more action in the screen and quick scene chances). I don’t want just a single value for the movie, but values along the movie to see how the action varies during it. After normalize the frame rate of the movies (10 fps), my idea is to compare each frame with the previous. I’m not only interest if the scene has changed, but also, if there was no cut, how much movement there is. Not only people/object movement but also, camera movement. In summary the paced (I think that the term) of the scenes.

    My idea was to use the scene function from ffmpeg as a metric. But looking at the document and examples online I’m thinking I can only use the value of the Scene Change Detection as a threshold to return frames informations, but I can’t get ffmpeg to return the value. Is that right ? There is any way I can make it return the value ?

  • Sending raw h264 video and aac audio frames to an RTMP server using ffmpeg

    7 décembre 2022, par codeimpaler

    I am receiving raw h264 and aac audio frames from an even driven source. I am trying to send these frames to an rtmp server. &#xA;I started working from the ffmpeg example muxing.c which successfully sends a custom stream to the rtmp server. I figure I just need to replace their frame data with my own.I found this suggestion online. I have tried How to pack raw h264 stream to flv container and send over rtmp using ffmpeg (not command) &#xA;and&#xA;How to publish selfmade stream with ffmpeg and c++ to rtmp server ?&#xA;and a few other suggestions but none have worked for me. &#xA;I have tried to directly memcpy my byte buffer but my code keeps failing&#xA;at ret = avcodec_encode_video2(c, &pkt, frame, &got_packet).&#xA;Specifically, I get an invalid access error.&#xA;For a little more context, anytime I receive a frame (which is event driven), void RTMPWriter::WriteVideoFrame(...) is called. Assume the constructor has already been called before the first frame is received. &#xA;I am not that familiar with ffmpeg and there could be several things wrong with the code. Any input will be really appreciated.

    &#xA;&#xA;

        #define STREAM_FRAME_RATE 25 /* 25 images/s */&#xA;    #define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */&#xA;    #define SCALE_FLAGS SWS_BICUBIC&#xA;    RTMPWriter::RTMPWriter()&#xA;      : seenKeyFrame(false),&#xA;        video_st({ 0 }), &#xA;        audio_st({ 0 }),&#xA;        have_video(0), &#xA;        have_audio(0)&#xA;    {&#xA;&#xA;        const char *filename;&#xA;        AVCodec *audio_codec = NULL, *video_codec = NULL;&#xA;        int ret;&#xA;&#xA;        int encode_video = 0, encode_audio = 0;&#xA;        AVDictionary *opt = NULL;&#xA;        int i;&#xA;&#xA;        /* Initialize libavcodec, and register all codecs and formats. */&#xA;        av_register_all();&#xA;&#xA;        avformat_network_init();&#xA;&#xA;       String^ StreamURL = "StreamURL";&#xA;       String^ out_uri = safe_cast(ApplicationData::Current->LocalSettings->Values->Lookup(StreamURL));&#xA;       std::wstring out_uriW(out_uri->Begin());&#xA;       std::string out_uriA(out_uriW.begin(), out_uriW.end());&#xA;       filename = out_uriA.c_str();  &#xA;&#xA;       /* allocate the output media context */&#xA;       avformat_alloc_output_context2(&amp;oc, NULL, "flv", filename);&#xA;       if (!oc)&#xA;       {&#xA;           OutputDebugString(L"Could not deduce output format from file extension: using MPEG.\n");&#xA;           avformat_alloc_output_context2(&amp;oc, NULL, "mpeg", filename);&#xA;       }&#xA;       if (!oc)&#xA;       {&#xA;           OutputDebugString(L"Could not allocate  using MPEG.\n");&#xA;       }&#xA;&#xA;&#xA;       fmt = oc->oformat;&#xA;&#xA;       /* Add the audio and video streams using the default format codecs&#xA;       * and initialize the codecs. */&#xA;       if (fmt->video_codec != AV_CODEC_ID_NONE) {&#xA;           add_stream(&amp;video_st, oc, &amp;video_codec, fmt->video_codec);&#xA;           have_video = 1;&#xA;           encode_video = 1;&#xA;       }&#xA;       if (fmt->audio_codec != AV_CODEC_ID_NONE) {&#xA;           add_stream(&amp;audio_st, oc, &amp;audio_codec, fmt->audio_codec);&#xA;           have_audio = 1;&#xA;           encode_audio = 1;&#xA;       }&#xA;&#xA;       /* Now that all the parameters are set, we can open the audio and&#xA;        * video codecs and allocate the necessary encode buffers. */&#xA;       if (have_video)&#xA;       {&#xA;           open_video(oc, video_codec, &amp;video_st, opt);&#xA;       }&#xA;&#xA;       if (have_audio)&#xA;       {&#xA;           open_audio(oc, audio_codec, &amp;audio_st, opt);&#xA;       }&#xA;&#xA;       av_dump_format(oc, 0, filename, 1);&#xA;&#xA;       /* open the output file, if needed */&#xA;       if (!(fmt->flags &amp; AVFMT_NOFILE))&#xA;       {&#xA;           ret = avio_open(&amp;oc->pb, filename, AVIO_FLAG_WRITE);&#xA;           if (ret &lt; 0)&#xA;           {&#xA;               OutputDebugString(L"Could not open ");&#xA;               OutputDebugString(out_uri->Data());&#xA;           }&#xA;       }&#xA;&#xA;       /* Write the stream header, if any. */&#xA;       ret = avformat_write_header(oc, &amp;opt);&#xA;       if (ret &lt; 0)&#xA;       {&#xA;           OutputDebugString(L"Error occurred when writing stream header \n");&#xA;       }&#xA;&#xA;    }&#xA;&#xA;    void RTMPWriter::WriteVideoFrame(&#xA;        boolean isKeyFrame,&#xA;        boolean hasDiscontinuity,&#xA;        UINT64 frameId,&#xA;        UINT32 videoBufferLength,&#xA;        BYTE *videoBytes)&#xA;    {&#xA;&#xA;        int ret;&#xA;        AVCodecContext *c;&#xA;        AVFrame* frame;&#xA;        int got_packet = 0;&#xA;        AVPacket pkt = { 0 };&#xA;&#xA;        c = video_st.enc;&#xA;&#xA;        frame = get_video_frame(videoBufferLength, videoBytes);&#xA;&#xA;        /* encode the image */&#xA;        ret = avcodec_encode_video2(c, &amp;pkt, frame, &amp;got_packet);&#xA;        if (ret &lt; 0) {&#xA;             OutputDebugString(L"Error encoding video frame: \n")&#xA;        }&#xA;&#xA;        if (got_packet) &#xA;        {&#xA;            ret = write_frame(oc, &amp;c->time_base, video_st.st, &amp;pkt);&#xA;        }&#xA;        else {&#xA;            ret = 0;&#xA;        }&#xA;&#xA;        if (ret &lt; 0) {&#xA;             OutputDebugString(L"Error while writing video frame: %s\n");&#xA;        }&#xA;    }&#xA;&#xA;    AVFrame * RTMPWriter::get_video_frame(&#xA;       UINT32 videoBufferLength,&#xA;       BYTE *videoBytes)&#xA;    {&#xA;        AVCodecContext *c = video_st.enc;&#xA;&#xA;        if (c->pix_fmt != AV_PIX_FMT_YUV420P) {&#xA;            /* as we only generate a YUV420P picture, we must convert it&#xA;            * to the codec pixel format if needed */&#xA;            if (!video_st.sws_ctx) {&#xA;                video_st.sws_ctx = sws_getContext(c->width, c->height,&#xA;                    AV_PIX_FMT_YUV420P,&#xA;                    c->width, c->height,&#xA;                    c->pix_fmt,&#xA;                    SCALE_FLAGS, NULL, NULL, NULL);&#xA;                if (!video_st.sws_ctx) {&#xA;                    fprintf(stderr,&#xA;                        "Could not initialize the conversion context\n");&#xA;                        exit(1);&#xA;                }&#xA;            }&#xA;            fill_yuv_image(video_st.tmp_frame, video_st.next_pts, c->width, c->height, videoBufferLength, videoBytes);&#xA;            sws_scale(video_st.sws_ctx,&#xA;            (const uint8_t * const *)video_st.tmp_frame->data, video_st.tmp_frame->linesize,&#xA;            0, c->height, video_st.frame->data, video_st.frame->linesize);&#xA;        }&#xA;        else {&#xA;            fill_yuv_image(video_st.frame, video_st.next_pts, c->width, c->height, videoBufferLength, videoBytes);&#xA;        }&#xA;&#xA;        video_st.frame->pts = video_st.next_pts&#x2B;&#x2B;;&#xA;&#xA;        return video_st.frame;&#xA;    }&#xA;&#xA;    /* Prepare a dummy image. */&#xA;    void  RTMPWriter::fill_yuv_image(&#xA;         AVFrame *pict, &#xA;         int frame_index,&#xA;         int width, &#xA;         int height, &#xA;         UINT32 videoBufferLength,&#xA;         BYTE *videoBytes)&#xA;    {&#xA;        //int x, y, i, ret;&#xA;&#xA;        /* when we pass a frame to the encoder, it may keep a reference to it&#xA;        * internally;&#xA;        * make sure we do not overwrite it here&#xA;        */&#xA;        ret = av_frame_make_writable(pict);&#xA;        if (ret &lt; 0) &#xA;        {&#xA;             OutputDebugString(L"Unable to make piture writable");&#xA;        }&#xA;&#xA;        memcpy(pict->data, videoBytes, videoBufferLength);&#xA;&#xA;        //i = frame_index;&#xA;&#xA;        ///* Y */&#xA;        //for (y = 0; y &lt; height; y&#x2B;&#x2B;)&#xA;        //  for (x = 0; x &lt; width; x&#x2B;&#x2B;)&#xA;        //      pict->data[0][y * pict->linesize[0] &#x2B; x] = x &#x2B; y &#x2B; i * 3;&#xA;&#xA;        ///* Cb and Cr */&#xA;        //for (y = 0; y &lt; height / 2; y&#x2B;&#x2B;) {&#xA;        //  for (x = 0; x &lt; width / 2; x&#x2B;&#x2B;) {&#xA;        //      pict->data[1][y * pict->linesize[1] &#x2B; x] = 128 &#x2B; y &#x2B; i * 2;&#xA;        //      pict->data[2][y * pict->linesize[2] &#x2B; x] = 64 &#x2B; x &#x2B; i * 5;&#xA;        //  }&#xA;        //}&#xA;    }&#xA;&#xA;    void RTMPWriter::WriteAudioFrame()&#xA;    {&#xA;&#xA;    }&#xA;&#xA;    /* Add an output stream. */&#xA;    void  RTMPWriter::add_stream(&#xA;        OutputStream *ost, &#xA;        AVFormatContext *oc,&#xA;        AVCodec **codec,&#xA;        enum AVCodecID codec_id)&#xA;   {&#xA;    AVCodecContext *c;&#xA;    int i;&#xA;&#xA;    /* find the encoder */&#xA;    *codec = avcodec_find_encoder(codec_id);&#xA;    if (!(*codec)) {&#xA;        OutputDebugString(L"Could not find encoder for &#x27;%s&#x27;\n");&#xA;        //avcodec_get_name(codec_id));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    ost->st = avformat_new_stream(oc, NULL);&#xA;    if (!ost->st) {&#xA;        OutputDebugString(L"Could not allocate stream\n");&#xA;        exit(1);&#xA;    }&#xA;    ost->st->id = oc->nb_streams - 1;&#xA;    c = avcodec_alloc_context3(*codec);&#xA;    if (!c) {&#xA;        OutputDebugString(L"Could not alloc an encoding context\n");&#xA;        exit(1);&#xA;    }&#xA;    ost->enc = c;&#xA;&#xA;    switch ((*codec)->type) {&#xA;    case AVMEDIA_TYPE_AUDIO:&#xA;        c->sample_fmt = (*codec)->sample_fmts ?&#xA;            (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;&#xA;        c->bit_rate = 64000;&#xA;        c->sample_rate = 44100;&#xA;        if ((*codec)->supported_samplerates) {&#xA;            c->sample_rate = (*codec)->supported_samplerates[0];&#xA;            for (i = 0; (*codec)->supported_samplerates[i]; i&#x2B;&#x2B;) {&#xA;                if ((*codec)->supported_samplerates[i] == 44100)&#xA;                    c->sample_rate = 44100;&#xA;            }&#xA;        }&#xA;        c->channels = av_get_channel_layout_nb_channels(c->channel_layout);&#xA;        c->channel_layout = AV_CH_LAYOUT_STEREO;&#xA;        if ((*codec)->channel_layouts) {&#xA;            c->channel_layout = (*codec)->channel_layouts[0];&#xA;            for (i = 0; (*codec)->channel_layouts[i]; i&#x2B;&#x2B;) {&#xA;                if ((*codec)->channel_layouts[i] == AV_CH_LAYOUT_STEREO)&#xA;                    c->channel_layout = AV_CH_LAYOUT_STEREO;&#xA;            }&#xA;        }&#xA;        c->channels = av_get_channel_layout_nb_channels(c->channel_layout);&#xA;        ost->st->time_base = /*(AVRational)*/{ 1, c->sample_rate };&#xA;        break;&#xA;&#xA;    case AVMEDIA_TYPE_VIDEO:&#xA;        c->codec_id = codec_id;&#xA;&#xA;        c->bit_rate = 400000;&#xA;        /* Resolution must be a multiple of two. */&#xA;        c->width = 352;&#xA;        c->height = 288;&#xA;        /* timebase: This is the fundamental unit of time (in seconds) in terms&#xA;        * of which frame timestamps are represented. For fixed-fps content,&#xA;        * timebase should be 1/framerate and timestamp increments should be&#xA;        * identical to 1. */&#xA;        ost->st->time_base = /*(AVRational)*/{ 1, STREAM_FRAME_RATE };&#xA;        c->time_base = ost->st->time_base;&#xA;&#xA;        c->gop_size = 12; /* emit one intra frame every twelve frames at most */&#xA;        c->pix_fmt = STREAM_PIX_FMT;&#xA;            if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {&#xA;                /* just for testing, we also add B-frames */&#xA;                c->max_b_frames = 2;&#xA;            }&#xA;            if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {&#xA;                /* Needed to avoid using macroblocks in which some coeffs overflow.&#xA;                * This does not happen with normal video, it just happens here as&#xA;                * the motion of the chroma plane does not match the luma plane. */&#xA;                c->mb_decision = 2;&#xA;            }&#xA;            break;&#xA;&#xA;        default:&#xA;            break;&#xA;        }&#xA;&#xA;         /* Some formats want stream headers to be separate. */&#xA;        if (oc->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;            c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;&#xA;AVFrame * RTMPWriter::alloc_audio_frame(&#xA;    enum AVSampleFormat sample_fmt,&#xA;    uint64_t channel_layout,&#xA;    int sample_rate, int nb_samples)&#xA;{&#xA;    AVFrame *frame = av_frame_alloc();&#xA;    int ret;&#xA;&#xA;    if (!frame) {&#xA;        OutputDebugString(L"Error allocating an audio frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    frame->format = sample_fmt;&#xA;    frame->channel_layout = channel_layout;&#xA;    frame->sample_rate = sample_rate;&#xA;    frame->nb_samples = nb_samples;&#xA;&#xA;    if (nb_samples) {&#xA;        ret = av_frame_get_buffer(frame, 0);&#xA;        if (ret &lt; 0) {&#xA;            OutputDebugString(L"Error allocating an audio buffer\n");&#xA;            exit(1);&#xA;        }&#xA;    }&#xA;&#xA;        return frame;&#xA;    }&#xA;&#xA;&#xA;&#xA;&#xA;void  RTMPWriter::open_audio(&#xA;    AVFormatContext *oc, &#xA;    AVCodec *codec, &#xA;    OutputStream *ost, &#xA;    AVDictionary *opt_arg)&#xA;{&#xA;    AVCodecContext *c;&#xA;    int nb_samples;&#xA;    int ret;&#xA;    AVDictionary *opt = NULL;&#xA;&#xA;    c = ost->enc;&#xA;&#xA;    /* open it */&#xA;    av_dict_copy(&amp;opt, opt_arg, 0);&#xA;    ret = avcodec_open2(c, codec, &amp;opt);&#xA;    av_dict_free(&amp;opt);&#xA;    if (ret &lt; 0) {&#xA;        OutputDebugString(L"Could not open audio codec: %s\n");// , av_err2str(ret));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* init signal generator */&#xA;    ost->t = 0;&#xA;    ost->tincr = 2 * M_PI * 110.0 / c->sample_rate;&#xA;    /* increment frequency by 110 Hz per second */&#xA;    ost->tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;&#xA;&#xA;    if (c->codec->capabilities &amp; AV_CODEC_CAP_VARIABLE_FRAME_SIZE)&#xA;        nb_samples = 10000;&#xA;    else&#xA;        nb_samples = c->frame_size;&#xA;&#xA;    ost->frame = alloc_audio_frame(c->sample_fmt, c->channel_layout,&#xA;        c->sample_rate, nb_samples);&#xA;    ost->tmp_frame = alloc_audio_frame(AV_SAMPLE_FMT_S16, c->channel_layout,&#xA;        c->sample_rate, nb_samples);&#xA;&#xA;    /* copy the stream parameters to the muxer */&#xA;    ret = avcodec_parameters_from_context(ost->st->codecpar, c);&#xA;    if (ret &lt; 0) {&#xA;        OutputDebugString(L"Could not copy the stream parameters\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* create resampler context */&#xA;    ost->swr_ctx = swr_alloc();&#xA;    if (!ost->swr_ctx) {&#xA;        OutputDebugString(L"Could not allocate resampler context\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* set options */&#xA;    av_opt_set_int(ost->swr_ctx, "in_channel_count", c->channels, 0);&#xA;    av_opt_set_int(ost->swr_ctx, "in_sample_rate", c->sample_rate, 0);&#xA;    av_opt_set_sample_fmt(ost->swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);&#xA;    av_opt_set_int(ost->swr_ctx, "out_channel_count", c->channels, 0);&#xA;    av_opt_set_int(ost->swr_ctx, "out_sample_rate", c->sample_rate, 0);&#xA;    av_opt_set_sample_fmt(ost->swr_ctx, "out_sample_fmt", c->sample_fmt, 0);&#xA;&#xA;    /* initialize the resampling context */&#xA;    if ((ret = swr_init(ost->swr_ctx)) &lt; 0) {&#xA;        OutputDebugString(L"Failed to initialize the resampling context\n");&#xA;        exit(1);&#xA;    }&#xA;}&#xA;&#xA;int RTMPWriter::write_frame(&#xA;    AVFormatContext *fmt_ctx, &#xA;    const AVRational *time_base, &#xA;    AVStream *st, &#xA;    AVPacket *pkt)&#xA;{&#xA;    /* rescale output packet timestamp values from codec to stream timebase */&#xA;    av_packet_rescale_ts(pkt, *time_base, st->time_base);&#xA;    pkt->stream_index = st->index;&#xA;&#xA;    /* Write the compressed frame to the media file. */&#xA;    //log_packet(fmt_ctx, pkt);&#xA;    OutputDebugString(L"Actually sending video frame: %s\n");&#xA;    return av_interleaved_write_frame(fmt_ctx, pkt);&#xA;}&#xA;&#xA;&#xA;AVFrame  *RTMPWriter::alloc_picture(&#xA;    enum AVPixelFormat pix_fmt, &#xA;    int width, &#xA;    int height)&#xA;{&#xA;    AVFrame *picture;&#xA;    int ret;&#xA;&#xA;    picture = av_frame_alloc();&#xA;    if (!picture)&#xA;        return NULL;&#xA;&#xA;    picture->format = pix_fmt;&#xA;    picture->width = width;&#xA;    picture->height = height;&#xA;&#xA;    /* allocate the buffers for the frame data */&#xA;    ret = av_frame_get_buffer(picture, 32);&#xA;    if (ret &lt; 0) {&#xA;        fprintf(stderr, "Could not allocate frame data.\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    return picture;&#xA;}&#xA;&#xA;void RTMPWriter::open_video(&#xA;    AVFormatContext *oc, &#xA;    AVCodec *codec, &#xA;    OutputStream *ost, &#xA;    AVDictionary *opt_arg)&#xA;{&#xA;    int ret;&#xA;    AVCodecContext *c = ost->enc;&#xA;    AVDictionary *opt = NULL;&#xA;&#xA;    av_dict_copy(&amp;opt, opt_arg, 0);&#xA;&#xA;    /* open the codec */&#xA;    ret = avcodec_open2(c, codec, &amp;opt);&#xA;    av_dict_free(&amp;opt);&#xA;    if (ret &lt; 0) {&#xA;        OutputDebugString(L"Could not open video codec: %s\n");// , av_err2str(ret));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* allocate and init a re-usable frame */&#xA;    ost->frame = alloc_picture(c->pix_fmt, c->width, c->height);&#xA;    if (!ost->frame) {&#xA;        OutputDebugString(L"Could not allocate video frame\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    /* If the output format is not YUV420P, then a temporary YUV420P&#xA;    * picture is needed too. It is then converted to the required&#xA;    * output format. */&#xA;    ost->tmp_frame = NULL;&#xA;    if (c->pix_fmt != AV_PIX_FMT_YUV420P) {&#xA;        ost->tmp_frame = alloc_picture(AV_PIX_FMT_YUV420P, c->width, c->height);&#xA;        if (!ost->tmp_frame) {&#xA;            OutputDebugString(L"Could not allocate temporary picture\n");&#xA;            exit(1);&#xA;        }&#xA;    }&#xA;&#xA;    /* copy the stream parameters to the muxer */&#xA;    ret = avcodec_parameters_from_context(ost->st->codecpar, c);&#xA;    if (ret &lt; 0) {&#xA;        OutputDebugString(L"Could not copy the stream parameters\n");&#xA;        exit(1);&#xA;    }&#xA;}&#xA;&#xA;void RTMPWriter::close_stream(AVFormatContext *oc, OutputStream *ost)&#xA;{&#xA;    avcodec_free_context(&amp;ost->enc);&#xA;    av_frame_free(&amp;ost->frame);&#xA;    av_frame_free(&amp;ost->tmp_frame);&#xA;    sws_freeContext(ost->sws_ctx);&#xA;    swr_free(&amp;ost->swr_ctx);&#xA;}&#xA;&#xA;RTMPWriter::~RTMPWriter()&#xA;{&#xA;    av_write_trailer(oc);&#xA;    /* Close each codec. */&#xA;    if (have_video)&#xA;        close_stream(oc, &amp;video_st);&#xA;    if (have_audio)&#xA;        close_stream(oc, &amp;audio_st);&#xA;&#xA;    if (!(fmt->flags &amp; AVFMT_NOFILE))&#xA;        /* Close the output file. */&#xA;        avio_closep(&amp;oc->pb);&#xA;&#xA;    /* free the stream */&#xA;    avformat_free_context(oc);&#xA;}&#xA;

    &#xA;