FFMPEG timestamp conception and Unit Conversion
来源:互联网 发布:柠檬绿茶淘宝店网址 编辑:程序博客网 时间:2024/05/16 06:58
1. FFMPEGtimestamp conception and Unit Conversion
a. FFMPEG timebase is presentationby AVRational
typedef struct AVRational{
int num; ///< numerator
int den; ///< denominator
} AVRational;
Convert rational to double call av_q2d(AVRationala) function
b. FFMPEG internal timebase macrodefine
#define AV_TIME_BASE 1000000
#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
AV_TIME_BASE : FFmpeg internal timebase and timestamp definitions, the unit is microsecond.
Convert time to ffmpeg internal timestamp:
timestamp(ffmpeg internal timestamp us) = AV_TIME_BASE * time(second)
Convert ffmpeg internal timestamp to time(second)
time(second) = AV_TIME_BASE_Q * timestamp(ffmpeg internal timebase)
Example:
Media Duration(s) = AVFormatContext.duration / AV_TIME_BASE
Sreaming_start_time(s) = AVFormatContext.start_time/ AV_TIME_BASE
Getting DTS/PTS
DTS decides when send frame to decode mode.
AVStream .time_base’s fundamental unit of time is in seconds
Convert dts in second units
DTS(s) = packet.dts * av_q2d(AVStream .time_base)
2. Seekfunction
Media player supports seek to any positionof media file then start playing
Through av_seek_frame or avformat_seek_file function to implementseek feature
av_seek_frame(AVFormatContext*s, int stream_index, int64_t timestamp,
int flags)
if stream_index is -1, timestamp’s unit will be ffmpeg internaltimestamp unit,so we need convert in AV_TIME_BASE units(us)
if stream_index is the selected by specify AVStream index,the timestamps are in units of the stream_index, So we need convert to in AVStream.time_baseunits
flags : AVSEEK_FLAG_BACKWARD // Seek the nearest IDR frame backward
AVSEEK_FLAG_ANY // seek to any frame, evennon-keyframes
AVSEEK_FLAG_FRAME //seeking based on frame number
Commonly we set the flag to AVSEEK_FLAG_BACKWARD
3. Getmedia duration and video frame rate
Media duration = AVFormatContext. Duration,the unit is in AV_TIME_BASE
Function av_guess_frame_rate to get framerate
frame_rate =av_q2d(av_guess_frame_rate(context,context->streams[i],NULL));
- FFMPEG timestamp conception and Unit Conversion
- Oracle Cursor and OOP Conception
- design pattern ------- defintion and conception
- Conception
- basic conception of minterm and maxterm
- Epoch & Unix Timestamp Conversion Tools
- Spark学习笔记 --- Stage and Task, Jobs conception
- convertall release 6.0基于python: unit conversion
- 智能选择:单位转换(unit conversion)
- FFmpeg之timebase和timestamp
- timestamp and av sync
- int and char conversion
- AOA Conception
- Yii and PHP Unit test
- 转贴:Conversion to Delphi 6: Missing unit Proxies.pas
- mysql date and timestamp operations
- Java: string and int conversion
- Conversion between json and object
- 我的openwrt学习笔记(六):MTK的OpenWrt系统编译以及下载
- 在输入的字符串中判断是否有a,多种方法(比较前两种不同的表示方法)
- Android播放在线音乐文件
- 【Linux】常用命令及参数
- Android Material Design之Toolbar与Palette实践
- FFMPEG timestamp conception and Unit Conversion
- BAT批处理文件语法
- hdu 5400 等差数列
- HDU 1421
- UICollectionView介绍
- nginx限制每个ip访问的频率和并发量
- 数学H - The Land of Justice
- Struts2 全局结果类型<global-results>
- C++逐行读取文本文件的正确做法