亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tutorial05.java

?? ffmpeg開發指南
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
## An ffmpeg and SDL TutorialPage 1 2 3 4 5 6 7 8 End Prev Home NextPrintable version Text version## Tutorial 05: Synching VideoCode: tutorial05.c### How Video SyncsSo this whole time, we've had an essentially useless movie player. It playsthe video, yeah, and it plays the audio, yeah, but it's not quite yet what wewould call a _movie_. So what do we do?#### PTS and DTSFortunately, both the audio and video streams have the information about howfast and when you are supposed to play them inside of them. Audio streams havea sample rate, and the video streams have a frames per second value. However,if we simply synced the video by just counting frames and multiplying by framerate, there is a chance that it will go out of sync with the audio. Instead,packets from the stream might have what is called a **decoding time stamp(DTS)** and a **presentation time stamp (PTS)**. To understand these twovalues, you need to know about the way movies are stored. Some formats, likeMPEG, use what they call "B" frames (B stands for "bidirectional雙向的雙通道的"). The twoother kinds of frames are called "I" frames and "P" frames ("I" for "intra在內的"and "P" for "predicted預言預告"). I frames contain a full image. P frames depend uponprevious I and P frames and are like diffs or deltas. B frames are the same asP frames, but depend upon information found in frames that are displayed both_before_ and _after_ them! This explains why we might not have a finishedframe after we call avcodec_decode_video.So let's say we had a movie, and the frames were displayed like: I B B P. Now,we need to know the information in P before we can display either B frame.Because of this, the frames might be stored like this: I P B B. This is why wehave a decoding timestamp and a presentation timestamp on each frame. Thedecoding timestamp tells us when we need to decode something, and thepresentation time stamp tells us when we need to display something. So, inthis case, our stream might look like this:
       PTS: 1 4 2 3
       DTS: 1 2 3 4
    Stream: I P B B
Generally the PTS and DTS will only differ when the stream we are playing hasB frames in it.When we get a packet from av_read_frame(), it will contain the PTS and DTSvalues for the information inside that packet. But what we really want is thePTS of our newly decoded raw frame, so we know when to display it. However,the frame we get from avcodec_decode_video() gives us an AVFrame, whichdoesn't contain a useful PTS value. (Warning: AVFrame does contain a ptsvariable, but this will not always contain what we want when we get a frame.)However, ffmpeg reorders the packets so that the DTS of the packet beingprocessed by avcodec_decode_video() will _always be the same_ as the PTS ofthe frame it returns. But, another warning: we won't always get thisinformation, either.Not to worry, because there's another way to find out the PTS of a frame, andwe can have our program reorder the packets by itself. We save the PTS of thefirst packet of a frame: this will be the PTS of the finished frame. So whenthe stream doesn't give us a DTS, we just use this saved PTS. We can figureout which packet is the first packet of a frame by lettingavcodec_decode_video() tell us. How? Whenever a packet starts a frame, theavcodec_decode_video() will call a function to allocate a buffer in our frame.And of course, ffmpeg allows us to redefine what that allocation function is.So we'll make a new function that saves the pts of the packet.Of course, even then, we might not get a proper pts. We'll deal with thatlater.#### SynchingNow, while it's all well and good to know when we're supposed to show aparticular video frame, but how do we actually do so? Here's the idea: afterwe show a frame, we figure out when the next frame should be shown. Then wesimply set a new timeout to refresh the video again after that amount of time.As you might expect, we check the value of the PTS of the next frame againstthe system clock to see how long our timeout should be. This approach works,but there are two issues that need to be dealt with.First is the issue of knowing when the next PTS will be. Now, you might thinkthat we can just add the video rate to the current PTS -- and you'd be mostlyright. However, some kinds of video call for frames to be repeated. This meansthat we're supposed to repeat the current frame a certain number of times.This could cause the program to display the next frame too soon. So we need toaccount for that.The second issue is that as the program stands now, the video and the audiochugging away happily, not bothering to sync at all. We wouldn't have to worryabout that if everything worked perfectly. But your computer isn't perfect,and a lot of video files aren't, either. So we have three choices: sync theaudio to the video, sync the video to the audio, or sync both to an externalclock (like your computer). For now, we're going to sync the video to theaudio.### Coding it: getting the frame PTSNow let's get into the code to do all this. We're going to need to add somemore members to our big struct, but we'll do this as we need to. First let'slook at our video thread. Remember, this is where we pick up the packets thatwere put on the queue by our decode thread. What we need to do in this part ofthe code is get the PTS of the frame given to us by avcodec_decode_video. Thefirst way we talked about was getting the DTS of the last packet processed,which is pretty easy:
      double pts;

      for(;;) {
        if(packet_queue_get(&is->videoq, packet, 1) < 0) {
          // means we quit getting packets
          break;
        }
        pts = 0;
        // Decode video frame
        len1 = avcodec_decode_video(is->video_st->codec,
                                    pFrame, &frameFinished,
    				packet->data, packet->size);
        if(packet->dts != AV_NOPTS_VALUE) {
          pts = packet->dts;
        } else {
          pts = 0;
        }
        pts *= av_q2d(is->video_st->time_base);
We set the PTS to 0 if we can't figure out what it is.Well, that was easy. But we said before that if the packet's DTS doesn't helpus, we need to use the PTS of the first packet that was decoded for the frame.We do this by telling ffmpeg to use our custom functions to allocate a frame.Here's the types of the functions:
    int get_buffer(struct AVCodecContext *c, AVFrame *pic);
    void release_buffer(struct AVCodecContext *c, AVFrame *pic);
The get function doesn't tell us anything about packets, so what we'll do issave the PTS to a global variable each time we get a packet, and our getfunction can just read that. Then, we can store the value in the AVFramestructure's opaque variable. This is a user-defined variable, so we can use itfor whatever we want. So first, here are our functions:
    uint64_t global_video_pkt_pts = AV_NOPTS_VALUE;

    /* These are called whenever we allocate a frame
     * buffer. We use this to store the global_pts in
     * a frame at the time it is allocated.
     */
    int our_get_buffer(struct AVCodecContext *c, AVFrame *pic) {
      int ret = avcodec_default_get_buffer(c, pic);
      uint64_t *pts = av_malloc(sizeof(uint64_t));
      *pts = global_video_pkt_pts;
      pic->opaque = pts;
      return ret;
    }
    void our_release_buffer(struct AVCodecContext *c, AVFrame *pic) {
      if(pic) av_freep(&pic->opaque);
      avcodec_default_release_buffer(c, pic);
    }
avcodec_default_get_buffer and avcodec_default_release_buffer are the defaultfunctions that ffmpeg uses for allocation. av_freep is a memory managementfunction that not only frees the memory pointed to, but sets the pointer toNULL.Now going way down to our stream open function (stream_component_open), we addthese lines to tell ffmpeg what to do:
        codecCtx->get_buffer = our_get_buffer;
        codecCtx->release_buffer = our_release_buffer;
Now we have to add code to save the PTS to the global variable and then usethe stored PTS when necessary. Our code now looks like this:
      for(;;) {
        if(packet_queue_get(&is->videoq, packet, 1) < 0) {
          // means we quit getting packets
          break;
        }
        pts = 0;

        // Save global pts to be stored in pFrame in first call
        global_video_pkt_pts = packet->pts;
        // Decode video frame
        len1 = avcodec_decode_video(is->video_st->codec, pFrame,&frameFinished,
    				packet->data, packet->size);
        if(packet->dts == AV_NOPTS_VALUE
           && pFrame->opaque && *(uint64_t*)pFrame->opaque != AV_NOPTS_VALUE){
          pts = *(uint64_t *)pFrame->opaque;
        } else if(packet->dts != AV_NOPTS_VALUE) {
          pts = packet->dts;
        } else {
          pts = 0;
        }
        pts *= av_q2d(is->video_st->time_base);
A technical note: You may have noticed we're using int64 for the PTS. This isbecause the PTS is stored as an integer. This value is a timestamp thatcorresponds to a measurement of time in that stream's time_base unit. Forexample, if a stream has 24 frames per second, a PTS of 42 is going toindicate that the frame should go where the 42nd frame would be if there wehad a frame every 1/24 of a second (certainly not necessarily true).We can convert this value to seconds by dividing by the framerate. Thetime_base value of the stream is going to be 1/framerate (for fixed-fpscontent), so to get the PTS in seconds, we multiply by the time_base.### Coding: Synching and using the PTSSo now we've got our PTS all set. Now we've got to take care of the twosynchronization problems we talked about above. We're going to define afunction called synchronize_video that will update the PTS to be in sync witheverything. This function will also finally deal with cases where we don't geta PTS value for our frame. At the same time we need to keep track of when thenext frame is expected so we can set our refresh rate properly. We canaccomplish this by using an internal video_clock value which keeps track ofhow much time has passed according to the video. We add this value to our bigstruct.
    typedef struct VideoState {
      double          video_clock; ///Here's the synchronize_video function, which is pretty self-explanatory:
    double synchronize_video(VideoState *is, AVFrame *src_frame, double pts){

      double frame_delay;

      if(pts != 0) {
        /* if we have pts, set video clock to it */
        is->video_clock = pts;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久久免费| 91精品国产一区二区三区| 日韩精品中文字幕一区二区三区| 自拍av一区二区三区| 久久成人免费网| 欧美日韩精品三区| 亚洲欧美日韩综合aⅴ视频| 久久黄色级2电影| 欧美性色综合网| 亚洲女同女同女同女同女同69| 激情国产一区二区| 91精品国产91久久久久久最新毛片| 亚洲女同ⅹxx女同tv| 成人激情小说乱人伦| 国产午夜精品理论片a级大结局| 日韩精品欧美精品| 91电影在线观看| 最新国产精品久久精品| 国产成人av网站| 精品1区2区在线观看| 热久久国产精品| 欧美日韩大陆在线| 亚洲一区日韩精品中文字幕| 91麻豆产精品久久久久久| 日本一区二区三区免费乱视频| 精品一二三四区| 日韩精品专区在线影院观看| 免费高清视频精品| 日韩精品一区二区三区视频| 三级不卡在线观看| 欧美日韩国产小视频在线观看| 亚洲一二三四在线| 欧美一a一片一级一片| 一区二区三区久久| 欧美性生交片4| 亚洲1区2区3区4区| 精品1区2区3区| 亚洲高清久久久| 欧美日韩mp4| 亚洲中国最大av网站| 91浏览器入口在线观看| 亚洲视频狠狠干| 99久久精品久久久久久清纯| 中文字幕一区二区三区不卡| 99精品久久免费看蜜臀剧情介绍| 国产精品久久久久毛片软件| 97se亚洲国产综合自在线观| 亚洲精品成人天堂一二三| 91久久精品国产91性色tv | 99久久99久久综合| 国产精品美女www爽爽爽| 99久精品国产| 亚洲国产三级在线| 91麻豆精品91久久久久久清纯| 日韩影院在线观看| 欧美videos大乳护士334| 国产精品一区二区久激情瑜伽| 中文字幕第一区二区| 91在线云播放| 香蕉久久一区二区不卡无毒影院| 欧美一区二区三区免费视频| 中文字幕免费观看一区| 成人黄动漫网站免费app| 国产日产欧产精品推荐色 | 亚洲欧美偷拍另类a∨色屁股| 色综合久久综合网欧美综合网| 亚洲一区二区三区激情| 日韩一区二区高清| 国产不卡视频一区二区三区| 亚洲卡通欧美制服中文| 欧美精品久久99| 国精产品一区一区三区mba视频| 中文字幕av免费专区久久| 欧美在线影院一区二区| 麻豆精品一区二区三区| 欧美国产综合一区二区| 91福利视频在线| 精品一区二区三区视频在线观看| 国产精品欧美极品| 欧美精品自拍偷拍动漫精品| 国产伦精品一区二区三区免费迷| 亚洲日本一区二区| 日韩美一区二区三区| 成人ar影院免费观看视频| 亚洲18影院在线观看| 国产亚洲欧美激情| 欧美日韩精品欧美日韩精品一综合| 国产专区综合网| 亚洲综合久久久久| **欧美大码日韩| 一本久道久久综合中文字幕| 青青草国产精品97视觉盛宴| 国产精品午夜春色av| 4438成人网| 99精品欧美一区二区蜜桃免费| 蜜臀91精品一区二区三区| 中文字幕亚洲成人| 日韩精品一区二区三区视频| 色香蕉久久蜜桃| 国产精品影音先锋| 日日欢夜夜爽一区| 成人免费一区二区三区在线观看 | 91玉足脚交白嫩脚丫在线播放| 天天影视网天天综合色在线播放| 精品成人一区二区| 欧美三级三级三级爽爽爽| 粉嫩av一区二区三区在线播放 | 日韩一区中文字幕| 久久影院电视剧免费观看| 精品视频1区2区3区| www.一区二区| 国产自产2019最新不卡| 午夜精品一区二区三区电影天堂| 国产偷国产偷亚洲高清人白洁| 欧美日本一区二区三区| 91麻豆视频网站| 国产精品 欧美精品| 麻豆精品视频在线观看视频| 亚洲午夜在线视频| 亚洲色图制服丝袜| 国产日韩欧美不卡| 国内精品久久久久影院薰衣草 | 日韩三级av在线播放| 色一情一伦一子一伦一区| 粗大黑人巨茎大战欧美成人| 久久激情五月婷婷| 日韩精品乱码免费| 亚洲国产裸拍裸体视频在线观看乱了| 国产精品三级av| 国产欧美视频一区二区| xf在线a精品一区二区视频网站| 欧美一区二区在线播放| 欧美日韩一区中文字幕| 色婷婷久久99综合精品jk白丝| 岛国一区二区在线观看| 精品影院一区二区久久久| 男女性色大片免费观看一区二区| 亚洲线精品一区二区三区| 亚洲免费观看高清完整版在线观看熊 | 欧美日韩在线观看一区二区 | 精品亚洲免费视频| 麻豆精品一二三| 日本成人中文字幕在线视频| 五月婷婷久久丁香| 亚洲成国产人片在线观看| 亚洲国产一区二区a毛片| 亚洲码国产岛国毛片在线| 综合色中文字幕| 裸体在线国模精品偷拍| 亚洲不卡一区二区三区| 91丨porny丨蝌蚪视频| 成a人片国产精品| 99视频在线精品| 99久久精品99国产精品| www.欧美精品一二区| 91在线porny国产在线看| 91视频.com| 欧美在线短视频| 欧美日韩国产首页在线观看| 欧美二区在线观看| 欧美一级黄色片| 精品国产一区二区三区不卡| 精品久久久久久久久久久久包黑料| 精品国产乱码久久| 欧美激情中文字幕| 亚洲婷婷在线视频| 亚洲午夜影视影院在线观看| 午夜视频久久久久久| 热久久一区二区| 国产一区欧美日韩| 丁香婷婷综合激情五月色| 91亚洲永久精品| 欧美日韩国产色站一区二区三区| 欧美日韩亚洲综合在线| 欧美一区二区三区在线电影| 日韩三级视频中文字幕| 久久精品在线观看| 亚洲图片欧美激情| 亚洲成av人片在www色猫咪| 日本色综合中文字幕| 国产伦精品一区二区三区免费迷| 成人动漫视频在线| 欧美日韩专区在线| 日韩欧美一区二区视频| 国产亚洲成aⅴ人片在线观看| 综合激情成人伊人| 丝袜美腿亚洲一区| 国产高清亚洲一区| 色一区在线观看| 日韩欧美电影一二三| 国产欧美日韩在线看| 亚洲一卡二卡三卡四卡五卡| 美女视频网站久久| 99麻豆久久久国产精品免费| 精品视频1区2区| 久久久国产精品不卡| 亚洲一区二区偷拍精品| 狠狠狠色丁香婷婷综合激情 | 国产成人亚洲综合a∨婷婷图片| 色综合色综合色综合色综合色综合 |