博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[原]如何在Android用FFmpeg+SDL2.0之同步音频
阅读量:7069 次
发布时间:2019-06-28

本文共 33765 字,大约阅读时间需要 112 分钟。

同步音频的原理可以参考:  本文是在  的基础上面继续进行将视频和音频同步到外部时钟的工作,同时也包含了修正音频解码的问题。

/* * SDL_Lesson.c * *  Created on: Aug 12, 2014 *      Author: clarck */#include 
#include
#include "SDL.h"#include "SDL_thread.h"#include "SDL_events.h"#include "../include/logger.h"#include "../ffmpeg/include/libavcodec/avcodec.h"#include "../ffmpeg/include/libavformat/avformat.h"#include "../ffmpeg/include/libavutil/pixfmt.h"#include "../ffmpeg/include/libswscale/swscale.h"#include "../ffmpeg/include/libswresample/swresample.h"#define SDL_AUDIO_BUFFER_SIZE 1024#define MAX_AUDIOQ_SIZE (5 * 16 * 1024)#define MAX_VIDEOQ_SIZE (5 * 256 * 1024)#define AV_SYNC_THRESHOLD 0.01#define AV_NOSYNC_THRESHOLD 10.0#define SAMPLE_CORRECTION_PERCENT_MAX 10#define AUDIO_DIFF_AVG_NB 20#define FF_ALLOC_EVENT (SDL_USEREVENT)#define FF_REFRESH_EVENT (SDL_USEREVENT + 1)#define FF_QUIT_EVENT (SDL_USEREVENT + 2)#define VIDEO_PICTURE_QUEUE_SIZE 1#define DEFAULT_AV_SYNC_TYPE AV_SYNC_VIDEO_MASTER#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audiotypedef struct PacketQueue { AVPacketList *first_pkt, *last_pkt; int nb_packets; int size; SDL_mutex *mutex; SDL_cond *cond;} PacketQueue;typedef struct VideoPicture { SDL_Window *screen; SDL_Renderer *renderer; SDL_Texture *bmp; AVFrame* rawdata; int width, height; /*source height & width*/ int allocated; double pts;} VideoPicture;typedef struct VideoState { char filename[1024]; AVFormatContext *ic; int videoStream, audioStream; AVStream *audio_st; AVFrame *audio_frame; PacketQueue audioq; unsigned int audio_buf_size; unsigned int audio_buf_index; AVPacket audio_pkt; uint8_t *audio_pkt_data; int audio_pkt_size; uint8_t *audio_buf; DECLARE_ALIGNED(16,uint8_t,audio_buf2) [AVCODEC_MAX_AUDIO_FRAME_SIZE * 4]; enum AVSampleFormat audio_src_fmt; enum AVSampleFormat audio_tgt_fmt; int audio_src_channels; int audio_tgt_channels; int64_t audio_src_channel_layout; int64_t audio_tgt_channel_layout; int audio_src_freq; int audio_tgt_freq; struct SwrContext *swr_ctx; AVStream *video_st; PacketQueue videoq; VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; int pictq_size, pictq_rindex, pictq_windex; SDL_mutex *pictq_mutex; SDL_cond *pictq_cond; SDL_Thread *parse_tid; SDL_Thread *audio_tid; SDL_Thread *video_tid; AVIOContext *io_ctx; struct SwsContext *sws_ctx; double audio_clock; int av_sync_type; double external_clock;/*external clock base*/ int64_t external_clock_time; int audio_hw_buf_size; double audio_diff_cum;/*used of AV difference average computation*/ double audio_diff_avg_coef; double audio_diff_threshold; int audio_diff_avg_count; double frame_timer; double frame_last_pts; double frame_last_delay; double video_current_pts; ///

 

转载地址:http://bgqll.baihongyu.com/

你可能感兴趣的文章
桌面支持--不懂不要乱动-尤其是别人的东西
查看>>
hadoop集群上运行自定义wordcount
查看>>
Linux条件测试
查看>>
阿兰•图灵与人工智能
查看>>
操作系统简单快捷安装方式
查看>>
微软MVA征文参赛作品_微软云计算,缔造新生活
查看>>
openshift 安装
查看>>
使用图形化工具Gitbook Editor编辑gitbook电子书
查看>>
SSH免密码登录原理
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Mbps与MB/s的区别
查看>>
eclipse 导入Maven项目的问题
查看>>
关于Java IO与NIO知识都在这里
查看>>
DEDE如何提取文章内容里面的第一张图片地址
查看>>
SQL Server的CONVERT() 函数介绍
查看>>
关于安装oracle数据库
查看>>
一句励志的英文短句,希望大家喜欢!
查看>>
org.hibernate.AssertionFailure: null id in xxx (don't flush the Session after an exception occurs)
查看>>
我的友情链接
查看>>