Recherche avancée

Médias (1)

Mot : - Tags -/net art

Autres articles (53)

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

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Mise à jour de la version 0.1 vers 0.2

    24 juin 2013, par

    Explications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
    Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...)

Sur d’autres sites (6902)

  • vp9 : enable multi-thread decoding when refreshctx is equal to 0

    11 octobre 2014, par Di Wu
    vp9 : enable multi-thread decoding when refreshctx is equal to 0
    

    In vp9_decode_frame function, ff_thread_finish_setup is not called
    when refreshctx is equal to 0, and the next decoding thread can not
    start work until the cunrrent frame has been decoded completely. So
    ff_thread_finish_setup needs to be called to enable Multi-thread
    decoding in this condition.

    Signed-off-by : Di Wu <di1028.wu@samsung.com>
    Signed-off-by : Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>

    • [DH] libavcodec/vp9.c
  • mp4 Vj Animation video lagging hi res video

    21 février 2020, par Ryan Stone

    I am trying to get a video to play inside a video tag at the top left hand corner of my page, it loads ok, the resolution is good and it seems to be looping but it is lagging very much, definatly not achieving 60fps it is in mp4 format and the resolution on the original mp4 is 1920x1080 it is a hi resolution vj free loop called GlassVein, you can see it if you search on youtube. On right clicking properties it comes up with the following inforamtion ;

    Bitrate:127kbs
    Data rate:11270kbps
    Total bitrate:11398kbs
    Audio sample rate is : 44khz
    filetype is:VLC media file(.mp4)
    (but i do not want or need the audio)

    & it also says 30fps, but I’m not sure i believe this as it runs smooth as butter on vlc media player no lagging, just smooth loop animation

    I have searched on :https://trac.ffmpeg.org/wiki/Encode/AAC for encoding information but it is complete gobbldygook to me, I don’t understand a word its saying

    My code is so far as follows ;

       <video src="GlassVeinColorful.mp4" autoplay="1" preload="auto" class="Vid" width="640" height="360" loop="1" viewport="" faststart="faststart" mpeg4="mpeg4" 320x240="320x240" 1080="1080" 128k="128k">  
       </video>

    Does anyone know why this is lagging so much, or what I could do about it.
    it is a quality animation and I don’t really want to loose an of its resolution or crispness.. the -s section was originally set to 1920x1080 as this is what the original file is but i have changed it to try and render it quicker...

    Any helpful sites, articles or answers would be great..

    2020 Update

    The Solution to this problem was to convert the Video to WebM, then use Javascript & a Html5 Canvas Element to render the Video to the page instead of using the video tag to embed the video.

    Html

    <section>
           <video src="Imgs/Vid/PurpGlassVein.webm" type="video/webm" width="684" height="auto" muted="muted" loop="loop" autoplay="autoplay">
                  <source>
                  <source>
                  <source>
           </source></source></source></video>
           <canvas style="filter:opacity(0);"></canvas>
    </section>

    Css

    video{
      display:none !important;
      visibility:hidden;
    }

    Javascript

       const Canv = document.querySelector("canvas");
       const Video = document.querySelector("video");
       const Ctx = Canv.getContext("2d");

       Video.addEventListener('play',()=>{
         function step() {
           Ctx.drawImage(Video, 0, 0, Canv.width, Canv.height)
           requestAnimationFrame(step)
         }
         requestAnimationFrame(step);
       })

       Canv.animate({
           filter: ['opacity(0) blur(5.28px)','opacity(1) blur(8.20px)']
       },{
           duration: 7288,
           fill: 'forwards',
           easing: 'ease-in',
           iterations: 1,
           delay: 728
       })

    I’ve Also Used the Vanilla Javascript .animate() API to fade the element into the page when the page loads. But one Caveat is that both the Canvas and the off-screen Video Tag must match the original videos resolution otherwise it starts to lag again, however you can use Css to scale it down via transform:scale(0.5) ; which doesn’t seem to effect performance at all.

    runs smooth as butter, and doesn’t loose any of the high resolution image.
    Added a slight blur 0.34px onto it aswell to smooth it even more.

    Possibly could of still used ffmpeg to get a better[Smaller File Size] WebM Output file but thats something I’ll have to look into at a later date.

  • ffmpeg record video plays too fast

    29 avril 2023, par Kris Xia

    I'm a college student and I am studying FFmpeg now.

    &#xA;&#xA;

    I have wrote a software that can record desktops and audio('virtual-audio-capturer') with FFmpeg.And I am now writing Audio and Video Synchronization.&#xA;I met some problems that video recording plays too fast.

    &#xA;&#xA;

    When I look for audio and video synchronization help on the Internet,I find a formula for calculating PTS :

    &#xA;&#xA;

    pts = n * ((1 / timbase)/ fps)

    &#xA;&#xA;

    When I use this formula,I find a phenomenon.

    &#xA;&#xA;

    1.The higher frame rate is,the faster the video playback speed.

    &#xA;&#xA;

    2.The slower the frame rate, the faster the video playback.

    &#xA;&#xA;

    Also I find while the framerate is 10,the video playback speed will be right.

    &#xA;&#xA;

    Why has this situation happened ?

    &#xA;&#xA;

    I have thought this question for three days. I really hope someone can help me solve this problem.

    &#xA;&#xA;

    I really appreciate the help.

    &#xA;&#xA;

    #include "stdafx.h"&#xA;&#xA;#ifdef  __cplusplus&#xA;extern "C"&#xA;{&#xA;#endif&#xA;#include "libavcodec/avcodec.h"&#xA;#include "libavformat/avformat.h"&#xA;#include "libswscale/swscale.h"&#xA;#include "libavdevice/avdevice.h"&#xA;#include "libavutil/audio_fifo.h"&#xA;&#xA;#include "libavfilter/buffersink.h"&#xA;#include "libavfilter/buffersrc.h"&#xA;#include "libavutil/imgutils.h"&#xA;#include "libavutil/mathematics.h"&#xA;#include "libavutil/samplefmt.h"&#xA;#include "libavutil/time.h"&#xA;#include "libavutil/opt.h"&#xA;#include "libavutil/pixdesc.h"&#xA;#include "libavutil/file.h"&#xA;#include "libavutil/mem.h"&#xA;#include "libavutil/frame.h"&#xA;#include "libavfilter/avfilter.h"&#xA;#include "libswresample/swresample.h"&#xA;&#xA;#pragma comment(lib, "avcodec.lib")&#xA;#pragma comment(lib, "avformat.lib")&#xA;#pragma comment(lib, "avutil.lib")&#xA;#pragma comment(lib, "avdevice.lib")&#xA;#pragma comment(lib, "avfilter.lib")&#xA;&#xA;#pragma comment(lib, "avfilter.lib")&#xA;#pragma comment(lib, "postproc.lib")&#xA;#pragma comment(lib, "swresample.lib")&#xA;#pragma comment(lib, "swscale.lib")&#xA;#ifdef __cplusplus&#xA;};&#xA;#endif&#xA;&#xA;AVFormatContext *pFormatCtx_Video = NULL, *pFormatCtx_Audio = NULL, *pFormatCtx_Out = NULL;&#xA;&#xA;AVCodecContext *outVideoCodecCtx = NULL;&#xA;AVCodecContext *outAudioCodecCtx = NULL;&#xA;&#xA;AVStream *pVideoStream = NULL, *pAudioStream = NULL;&#xA;&#xA;AVCodec *outAVCodec;&#xA;AVCodec *outAudioCodec;&#xA;&#xA;AVCodecContext  *pCodecCtx_Video;&#xA;AVCodec         *pCodec_Video;&#xA;AVFifoBuffer    *fifo_video = NULL;&#xA;AVAudioFifo     *fifo_audio = NULL;&#xA;int VideoIndex, AudioIndex;&#xA;int codec_id;&#xA;&#xA;CRITICAL_SECTION AudioSection, VideoSection;&#xA;&#xA;&#xA;&#xA;SwsContext *img_convert_ctx;&#xA;int frame_size = 0;&#xA;&#xA;uint8_t *picture_buf = NULL, *frame_buf = NULL;&#xA;&#xA;bool bCap = true;&#xA;&#xA;DWORD WINAPI ScreenCapThreadProc( LPVOID lpParam );&#xA;DWORD WINAPI AudioCapThreadProc( LPVOID lpParam );&#xA;&#xA;int OpenVideoCapture()&#xA;{&#xA;    AVInputFormat *ifmt=av_find_input_format("gdigrab");&#xA;    AVDictionary *options = NULL;&#xA;    av_dict_set(&amp;options, "framerate", "60", NULL);&#xA;    if(avformat_open_input(&amp;pFormatCtx_Video, "desktop", ifmt, &amp;options)!=0)&#xA;    {&#xA;        printf("Couldn&#x27;t open input stream.(无法打开视频输入流)\n");&#xA;        return -1;&#xA;    }&#xA;    if(avformat_find_stream_info(pFormatCtx_Video,NULL)&lt;0)&#xA;    {&#xA;        printf("Couldn&#x27;t find stream information.(无法获取视频流信息)\n");&#xA;        return -1;&#xA;    }&#xA;    if (pFormatCtx_Video->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO)&#xA;    {&#xA;        printf("Couldn&#x27;t find video stream information.(无法获取视频流信息)\n");&#xA;        return -1;&#xA;    }&#xA;    pCodecCtx_Video = pFormatCtx_Video->streams[0]->codec;&#xA;    pCodec_Video = avcodec_find_decoder(pCodecCtx_Video->codec_id);&#xA;    if(pCodec_Video == NULL)&#xA;    {&#xA;        printf("Codec not found.(没有找到解码器)\n");&#xA;        return -1;&#xA;    }&#xA;    if(avcodec_open2(pCodecCtx_Video, pCodec_Video, NULL) &lt; 0)&#xA;    {&#xA;        printf("Could not open codec.(无法打开解码器)\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    av_dump_format(pFormatCtx_Video, 0, NULL, 0);&#xA;&#xA;    img_convert_ctx = sws_getContext(pCodecCtx_Video->width, pCodecCtx_Video->height, pCodecCtx_Video->pix_fmt, &#xA;        pCodecCtx_Video->width, pCodecCtx_Video->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL); &#xA;&#xA;    frame_size = avpicture_get_size(pCodecCtx_Video->pix_fmt, pCodecCtx_Video->width, pCodecCtx_Video->height);&#xA;    fifo_video = av_fifo_alloc(30 * avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx_Video->width, pCodecCtx_Video->height));&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;static char *dup_wchar_to_utf8(wchar_t *w)&#xA;{&#xA;    char *s = NULL;&#xA;    int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);&#xA;    s = (char *) av_malloc(l);&#xA;    if (s)&#xA;        WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);&#xA;    return s;&#xA;}&#xA;&#xA;int OpenAudioCapture()&#xA;{&#xA;    AVInputFormat *pAudioInputFmt = av_find_input_format("dshow");&#xA;    char * psDevName = dup_wchar_to_utf8(L"audio=virtual-audio-capturer");&#xA;&#xA;    if (avformat_open_input(&amp;pFormatCtx_Audio, psDevName, pAudioInputFmt,NULL) &lt; 0)&#xA;    {&#xA;        printf("Couldn&#x27;t open input stream.(无法打开音频输入流)\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    if(avformat_find_stream_info(pFormatCtx_Audio,NULL)&lt;0)  &#xA;        return -1; &#xA;&#xA;    if(pFormatCtx_Audio->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO)&#xA;    {&#xA;        printf("Couldn&#x27;t find video stream information.(无法获取音频流信息)\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    AVCodec *tmpCodec = avcodec_find_decoder(pFormatCtx_Audio->streams[0]->codec->codec_id);&#xA;    if(0 > avcodec_open2(pFormatCtx_Audio->streams[0]->codec, tmpCodec, NULL))&#xA;    {&#xA;        printf("can not find or open audio decoder!\n");&#xA;    }&#xA;&#xA;    av_dump_format(pFormatCtx_Audio, 0, NULL, 0);&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;int OpenOutPut()&#xA;{&#xA;    AVStream *pVideoStream = NULL, *pAudioStream = NULL;&#xA;    const char *outFileName = "test.mp4";&#xA;    avformat_alloc_output_context2(&amp;pFormatCtx_Out, NULL, NULL, outFileName);&#xA;&#xA;    if (pFormatCtx_Video->streams[0]->codec->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;    {&#xA;        VideoIndex = 0;&#xA;        pVideoStream = avformat_new_stream(pFormatCtx_Out, NULL);&#xA;        if (!pVideoStream)&#xA;        {&#xA;            printf("can not new stream for output!\n");&#xA;            return -1;&#xA;        }&#xA;&#xA;        outVideoCodecCtx = avcodec_alloc_context3(outAVCodec);&#xA;        if ( !outVideoCodecCtx )&#xA;        {&#xA;            printf("Error : avcodec_alloc_context3()\n");&#xA;            return -1;&#xA;        }&#xA;&#xA;        //set codec context param&#xA;        outVideoCodecCtx = pVideoStream->codec;&#xA;        outVideoCodecCtx->codec_id = AV_CODEC_ID_MPEG4;&#xA;        outVideoCodecCtx->width = pFormatCtx_Video->streams[0]->codec->width;&#xA;        outVideoCodecCtx->height = pFormatCtx_Video->streams[0]->codec->height;&#xA;        outVideoCodecCtx->time_base = pFormatCtx_Video->streams[0]->codec->time_base;&#xA;        outVideoCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;        outVideoCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;&#xA;        if (codec_id == AV_CODEC_ID_H264)&#xA;        {&#xA;            av_opt_set(outVideoCodecCtx->priv_data, "preset", "slow", 0);&#xA;        }&#xA;&#xA;        outAVCodec = avcodec_find_encoder(AV_CODEC_ID_MPEG4);&#xA;        if( !outAVCodec )&#xA;        {&#xA;            printf("\n\nError : avcodec_find_encoder()");&#xA;            return -1;&#xA;        }&#xA;        if (pFormatCtx_Out->oformat->flags &amp; AVFMT_GLOBALHEADER)&#xA;            outVideoCodecCtx->flags |=CODEC_FLAG_GLOBAL_HEADER;&#xA;&#xA;        if ((avcodec_open2(outVideoCodecCtx,outAVCodec, NULL)) &lt; 0)&#xA;        {&#xA;            printf("can not open the encoder\n");&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;    if(pFormatCtx_Audio->streams[0]->codec->codec_type == AVMEDIA_TYPE_AUDIO)&#xA;    {&#xA;        AVCodecContext *pOutputCodecCtx;&#xA;        AudioIndex = 1;&#xA;        pAudioStream = avformat_new_stream(pFormatCtx_Out, NULL);&#xA;&#xA;        pAudioStream->codec->codec = avcodec_find_encoder(pFormatCtx_Out->oformat->audio_codec);&#xA;&#xA;        pOutputCodecCtx = pAudioStream->codec;&#xA;&#xA;        pOutputCodecCtx->sample_rate = pFormatCtx_Audio->streams[0]->codec->sample_rate;&#xA;        pOutputCodecCtx->channel_layout = pFormatCtx_Out->streams[0]->codec->channel_layout;&#xA;        pOutputCodecCtx->channels = av_get_channel_layout_nb_channels(pAudioStream->codec->channel_layout);&#xA;        if(pOutputCodecCtx->channel_layout == 0)&#xA;        {&#xA;            pOutputCodecCtx->channel_layout = AV_CH_LAYOUT_STEREO;&#xA;            pOutputCodecCtx->channels = av_get_channel_layout_nb_channels(pOutputCodecCtx->channel_layout);&#xA;&#xA;        }&#xA;        pOutputCodecCtx->sample_fmt = pAudioStream->codec->codec->sample_fmts[0];&#xA;        AVRational time_base={1, pAudioStream->codec->sample_rate};&#xA;        pAudioStream->time_base = time_base;&#xA;        //audioCodecCtx->time_base = time_base;&#xA;&#xA;        pOutputCodecCtx->codec_tag = 0;  &#xA;        if (pFormatCtx_Out->oformat->flags &amp; AVFMT_GLOBALHEADER)  &#xA;            pOutputCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;&#xA;&#xA;        if (avcodec_open2(pOutputCodecCtx, pOutputCodecCtx->codec, 0) &lt; 0)&#xA;        {&#xA;            printf("编码器打开失败,退出程序\n");&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;    if (!(pFormatCtx_Out->oformat->flags &amp; AVFMT_NOFILE))&#xA;    {&#xA;        if(avio_open(&amp;pFormatCtx_Out->pb, outFileName, AVIO_FLAG_WRITE) &lt; 0)&#xA;        {&#xA;            printf("can not open output file handle!\n");&#xA;            return -1;&#xA;        }&#xA;    }&#xA;&#xA;    if(avformat_write_header(pFormatCtx_Out, NULL) &lt; 0)&#xA;    {&#xA;        printf("can not write the header of the output file!\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;int _tmain(int argc, _TCHAR* argv[])&#xA;{&#xA;    av_register_all();&#xA;    avdevice_register_all();&#xA;    if (OpenVideoCapture() &lt; 0)&#xA;    {&#xA;        return -1;&#xA;    }&#xA;    if (OpenAudioCapture() &lt; 0)&#xA;    {&#xA;        return -1;&#xA;    }&#xA;    if (OpenOutPut() &lt; 0)&#xA;    {&#xA;        return -1;&#xA;    }&#xA;//  int fps;&#xA;    /*printf("输入帧率:");&#xA;    scanf_s("%d",&amp;fps);&#xA;    if ( NULL == fps)&#xA;    {&#xA;        fps = 10;&#xA;    }*/&#xA;&#xA;    InitializeCriticalSection(&amp;VideoSection);&#xA;    InitializeCriticalSection(&amp;AudioSection);&#xA;&#xA;    AVFrame *picture = av_frame_alloc();&#xA;    int size = avpicture_get_size(pFormatCtx_Out->streams[VideoIndex]->codec->pix_fmt, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->width, pFormatCtx_Out->streams[VideoIndex]->codec->height);&#xA;    picture_buf = new uint8_t[size];&#xA;&#xA;    avpicture_fill((AVPicture *)picture, picture_buf, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->pix_fmt, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->width, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->height);&#xA;&#xA;&#xA;&#xA;    //star cap screen thread&#xA;    CreateThread( NULL, 0, ScreenCapThreadProc, 0, 0, NULL);&#xA;    //star cap audio thread&#xA;    CreateThread( NULL, 0, AudioCapThreadProc, 0, 0, NULL);&#xA;    int64_t cur_pts_v=0,cur_pts_a=0;&#xA;    int VideoFrameIndex = 0, AudioFrameIndex = 0;&#xA;&#xA;    while(1)&#xA;    {&#xA;        if (_kbhit() != 0 &amp;&amp; bCap)&#xA;        {&#xA;            bCap = false;&#xA;            Sleep(2000);&#xA;        }&#xA;        if (fifo_audio &amp;&amp; fifo_video)&#xA;        {&#xA;            int sizeAudio = av_audio_fifo_size(fifo_audio);&#xA;            int sizeVideo = av_fifo_size(fifo_video);&#xA;            //缓存数据写完就结束循环&#xA;            if (av_audio_fifo_size(fifo_audio) &lt;= pFormatCtx_Out->streams[AudioIndex]->codec->frame_size &amp;&amp; &#xA;                av_fifo_size(fifo_video) &lt;= frame_size &amp;&amp; !bCap)&#xA;            {&#xA;                break;&#xA;            }&#xA;        }&#xA;&#xA;        if(av_compare_ts(cur_pts_v, pFormatCtx_Out->streams[VideoIndex]->time_base, &#xA;                         cur_pts_a,pFormatCtx_Out->streams[AudioIndex]->time_base) &lt;= 0)&#xA;        {&#xA;            if (av_fifo_size(fifo_video) &lt; frame_size &amp;&amp; !bCap)&#xA;            {&#xA;                cur_pts_v = 0x7fffffffffffffff;&#xA;            }&#xA;            if(av_fifo_size(fifo_video) >= size)&#xA;            {&#xA;                EnterCriticalSection(&amp;VideoSection);&#xA;                av_fifo_generic_read(fifo_video, picture_buf, size, NULL); //将数据从avfifobuffer馈送到用户提供的回调。&#xA;                LeaveCriticalSection(&amp;VideoSection);&#xA;&#xA;                avpicture_fill((AVPicture *)picture, picture_buf,&#xA;                    pFormatCtx_Out->streams[VideoIndex]->codec->pix_fmt,&#xA;                    pFormatCtx_Out->streams[VideoIndex]->codec->width,&#xA;                    pFormatCtx_Out->streams[VideoIndex]->codec->height); //根据指定的图像参数和提供的图像数据缓冲区设置图片字段。&#xA;&#xA;                //pts = n * ((1 / timbase)/ fps);&#xA;                //picture->pts = VideoFrameIndex * ((pFormatCtx_Video->streams[0]->time_base.den / pFormatCtx_Video->streams[0]->time_base.num) / 24);&#xA;                picture->pts = VideoFrameIndex * ((outVideoCodecCtx->time_base.den * 100000 / outVideoCodecCtx->time_base.num) / 180);&#xA;&#xA;                int got_picture = 0;&#xA;                AVPacket pkt;&#xA;                av_init_packet(&amp;pkt);&#xA;&#xA;                pkt.data = NULL;&#xA;                pkt.size = 0;&#xA;                //从帧中获取输入的原始视频数据&#xA;                int ret = avcodec_encode_video2(pFormatCtx_Out->streams[VideoIndex]->codec, &amp;pkt, picture, &amp;got_picture);&#xA;                if(ret &lt; 0)&#xA;                {&#xA;                    continue;&#xA;                }&#xA;&#xA;                if (got_picture==1)&#xA;                {&#xA;                    pkt.stream_index = VideoIndex;&#xA;                    /*int count = 1;&#xA;                    pkt.pts = pkt.dts = count * ((pFormatCtx_Video->streams[0]->time_base.den / pFormatCtx_Video->streams[0]->time_base.num) / 15);&#xA;                    count&#x2B;&#x2B;;*/&#xA;&#xA;                    //x = pts * (timebase1.num / timebase1.den )* (timebase2.den / timebase2.num);&#xA;&#xA;                    pkt.pts = av_rescale_q_rnd(pkt.pts, pFormatCtx_Video->streams[0]->time_base, &#xA;                        pFormatCtx_Out->streams[VideoIndex]->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));  &#xA;                    pkt.dts = av_rescale_q_rnd(pkt.dts,  pFormatCtx_Video->streams[0]->time_base, &#xA;                        pFormatCtx_Out->streams[VideoIndex]->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX)); &#xA;&#xA;&#xA;                    pkt.duration = ((pFormatCtx_Out->streams[0]->time_base.den / pFormatCtx_Out->streams[0]->time_base.num) / 60);&#xA;                    //pkt.duration = 1000/60;&#xA;                    //pkt.pts = pkt.dts = Count * (ofmt_ctx->streams[stream_index]->time_base.den) /ofmt_ctx->streams[stream_index]->time_base.num / 10;&#xA;&#xA;                    //Count&#x2B;&#x2B;;&#xA;&#xA;&#xA;                    cur_pts_v = pkt.pts;&#xA;&#xA;                    ret = av_interleaved_write_frame(pFormatCtx_Out, &amp;pkt);&#xA;                    //delete[] pkt.data;&#xA;                    av_free_packet(&amp;pkt);&#xA;                }&#xA;                VideoFrameIndex&#x2B;&#x2B;;&#xA;            }&#xA;        }&#xA;        else&#xA;        {&#xA;            if (NULL == fifo_audio)&#xA;            {&#xA;                continue;//还未初始化fifo&#xA;            }&#xA;            if (av_audio_fifo_size(fifo_audio) &lt; pFormatCtx_Out->streams[AudioIndex]->codec->frame_size &amp;&amp; !bCap)&#xA;            {&#xA;                cur_pts_a = 0x7fffffffffffffff;&#xA;            }&#xA;            if(av_audio_fifo_size(fifo_audio) >= &#xA;                (pFormatCtx_Out->streams[AudioIndex]->codec->frame_size > 0 ? pFormatCtx_Out->streams[AudioIndex]->codec->frame_size : 1024))&#xA;            {&#xA;                AVFrame *frame;&#xA;                frame = av_frame_alloc();&#xA;                frame->nb_samples = pFormatCtx_Out->streams[AudioIndex]->codec->frame_size>0 ? pFormatCtx_Out->streams[AudioIndex]->codec->frame_size: 1024;&#xA;                frame->channel_layout = pFormatCtx_Out->streams[AudioIndex]->codec->channel_layout;&#xA;                frame->format = pFormatCtx_Out->streams[AudioIndex]->codec->sample_fmt;&#xA;                frame->sample_rate = pFormatCtx_Out->streams[AudioIndex]->codec->sample_rate;&#xA;                av_frame_get_buffer(frame, 0);&#xA;&#xA;                EnterCriticalSection(&amp;AudioSection);&#xA;                av_audio_fifo_read(fifo_audio, (void **)frame->data, &#xA;                    (pFormatCtx_Out->streams[AudioIndex]->codec->frame_size > 0 ? pFormatCtx_Out->streams[AudioIndex]->codec->frame_size : 1024));&#xA;                LeaveCriticalSection(&amp;AudioSection);&#xA;&#xA;                AVPacket pkt_out;&#xA;                av_init_packet(&amp;pkt_out);&#xA;                int got_picture = -1;&#xA;                pkt_out.data = NULL;&#xA;                pkt_out.size = 0;&#xA;&#xA;                frame->pts = AudioFrameIndex * pFormatCtx_Out->streams[AudioIndex]->codec->frame_size;&#xA;                if (avcodec_encode_audio2(pFormatCtx_Out->streams[AudioIndex]->codec, &amp;pkt_out, frame, &amp;got_picture) &lt; 0)&#xA;                {&#xA;                    printf("can not decoder a frame");&#xA;                }&#xA;                av_frame_free(&amp;frame);&#xA;                if (got_picture) &#xA;                {&#xA;                    pkt_out.stream_index = AudioIndex;&#xA;                    pkt_out.pts = AudioFrameIndex * pFormatCtx_Out->streams[AudioIndex]->codec->frame_size;&#xA;                    pkt_out.dts = AudioFrameIndex * pFormatCtx_Out->streams[AudioIndex]->codec->frame_size;&#xA;                    pkt_out.duration = pFormatCtx_Out->streams[AudioIndex]->codec->frame_size;&#xA;&#xA;                    cur_pts_a = pkt_out.pts;&#xA;&#xA;                    int ret = av_interleaved_write_frame(pFormatCtx_Out, &amp;pkt_out);&#xA;                    av_free_packet(&amp;pkt_out);&#xA;                }&#xA;                AudioFrameIndex&#x2B;&#x2B;;&#xA;            }&#xA;        }&#xA;    }&#xA;&#xA;    delete[] picture_buf;&#xA;&#xA;    av_fifo_free(fifo_video);&#xA;    av_audio_fifo_free(fifo_audio);&#xA;&#xA;    av_write_trailer(pFormatCtx_Out);&#xA;&#xA;    avio_close(pFormatCtx_Out->pb);&#xA;    avformat_free_context(pFormatCtx_Out);&#xA;&#xA;    if (pFormatCtx_Video != NULL)&#xA;    {&#xA;        avformat_close_input(&amp;pFormatCtx_Video);&#xA;        pFormatCtx_Video = NULL;&#xA;    }&#xA;    if (pFormatCtx_Audio != NULL)&#xA;    {&#xA;        avformat_close_input(&amp;pFormatCtx_Audio);&#xA;        pFormatCtx_Audio = NULL;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;DWORD WINAPI ScreenCapThreadProc( LPVOID lpParam )&#xA;{&#xA;    AVPacket packet;&#xA;    int got_picture;&#xA;    AVFrame *pFrame;&#xA;    pFrame=av_frame_alloc();&#xA;&#xA;    AVFrame *picture = av_frame_alloc();&#xA;    int size = avpicture_get_size(pFormatCtx_Out->streams[VideoIndex]->codec->pix_fmt, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->width, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->height);&#xA;&#xA;    avpicture_fill((AVPicture *)picture, picture_buf, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->pix_fmt, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->width, &#xA;        pFormatCtx_Out->streams[VideoIndex]->codec->height);&#xA;&#xA;    FILE *p = NULL;&#xA;    p = fopen("proc_test.yuv", "wb&#x2B;");&#xA;    av_init_packet(&amp;packet);&#xA;    int height = pFormatCtx_Out->streams[VideoIndex]->codec->height;&#xA;    int width = pFormatCtx_Out->streams[VideoIndex]->codec->width;&#xA;    int y_size=height*width;&#xA;    while(bCap)&#xA;    {&#xA;        packet.data = NULL;&#xA;        packet.size = 0;&#xA;        if (av_read_frame(pFormatCtx_Video, &amp;packet) &lt; 0)&#xA;        {&#xA;            continue;&#xA;        }&#xA;        if(packet.stream_index == 0)&#xA;        {&#xA;            if (avcodec_decode_video2(pCodecCtx_Video, pFrame, &amp;got_picture, &amp;packet) &lt; 0)&#xA;            {&#xA;                printf("Decode Error.(解码错误)\n");&#xA;                continue;&#xA;            }&#xA;            if (got_picture)&#xA;            {&#xA;                sws_scale(img_convert_ctx, &#xA;                    (const uint8_t* const*)pFrame->data,&#xA;                    pFrame->linesize, &#xA;                    0, &#xA;                    pFormatCtx_Out->streams[VideoIndex]->codec->height,&#xA;                    picture->data,&#xA;                    picture->linesize);&#xA;&#xA;                if (av_fifo_space(fifo_video) >= size)&#xA;                {&#xA;                    EnterCriticalSection(&amp;VideoSection);                    &#xA;                    av_fifo_generic_write(fifo_video, picture->data[0], y_size, NULL);&#xA;                    av_fifo_generic_write(fifo_video, picture->data[1], y_size/4, NULL);&#xA;                    av_fifo_generic_write(fifo_video, picture->data[2], y_size/4, NULL);&#xA;                    LeaveCriticalSection(&amp;VideoSection);&#xA;                }&#xA;            }&#xA;        }&#xA;        av_free_packet(&amp;packet);&#xA;    }&#xA;    av_frame_free(&amp;pFrame);&#xA;    av_frame_free(&amp;picture);&#xA;    return 0;&#xA;}&#xA;&#xA;DWORD WINAPI AudioCapThreadProc( LPVOID lpParam )&#xA;{&#xA;    AVPacket pkt;&#xA;    AVFrame *frame;&#xA;    frame = av_frame_alloc();&#xA;    int gotframe;&#xA;    while(bCap)&#xA;    {&#xA;        pkt.data = NULL;&#xA;        pkt.size = 0;&#xA;        if(av_read_frame(pFormatCtx_Audio,&amp;pkt) &lt; 0)&#xA;        {&#xA;            continue;&#xA;        }&#xA;&#xA;        if (avcodec_decode_audio4(pFormatCtx_Audio->streams[0]->codec, frame, &amp;gotframe, &amp;pkt) &lt; 0)&#xA;        {&#xA;            av_frame_free(&amp;frame);&#xA;            printf("can not decoder a frame");&#xA;            break;&#xA;        }&#xA;        av_free_packet(&amp;pkt);&#xA;&#xA;        if (!gotframe)&#xA;        {&#xA;            printf("没有获取到数据,继续下一次");&#xA;            continue;&#xA;        }&#xA;&#xA;        if (NULL == fifo_audio)&#xA;        {&#xA;            fifo_audio = av_audio_fifo_alloc(pFormatCtx_Audio->streams[0]->codec->sample_fmt, &#xA;                pFormatCtx_Audio->streams[0]->codec->channels, 30 * frame->nb_samples);&#xA;        }&#xA;&#xA;        int buf_space = av_audio_fifo_space(fifo_audio);&#xA;        if (av_audio_fifo_space(fifo_audio) >= frame->nb_samples)&#xA;        {&#xA;            EnterCriticalSection(&amp;AudioSection);&#xA;            av_audio_fifo_write(fifo_audio, (void **)frame->data, frame->nb_samples);&#xA;            LeaveCriticalSection(&amp;AudioSection);&#xA;        }&#xA;    }&#xA;    av_frame_free(&amp;frame);&#xA;    return 0;&#xA;}&#xA;

    &#xA;&#xA;

    Maybe there is another way to calculate PTS and DTS

    &#xA;&#xA;

    I hope whatever the frame rate is,video playback speed is right.Not too fast or too slow.

    &#xA;