00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include <stdio.h>
00028 #include "timecode.h"
00029 #include "libavutil/log.h"
00030
00031 int ff_framenum_to_drop_timecode(int frame_num)
00032 {
00033
00034 int d = frame_num / 17982;
00035 int m = frame_num % 17982;
00036
00037 return frame_num + 18 * d + 2 * ((m - 2) / 1798);
00038 }
00039
00040 uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
00041 {
00042 return (0 << 31) |
00043 (drop << 30) |
00044 ( ((frame % fps) / 10) << 28) |
00045 ( ((frame % fps) % 10) << 24) |
00046 (0 << 23) |
00047 ((((frame / fps) % 60) / 10) << 20) |
00048 ((((frame / fps) % 60) % 10) << 16) |
00049 (0 << 15) |
00050 ((((frame / (fps * 60)) % 60) / 10) << 12) |
00051 ((((frame / (fps * 60)) % 60) % 10) << 8) |
00052 (0 << 7) |
00053 (0 << 6) |
00054 ((((frame / (fps * 3600) % 24)) / 10) << 4) |
00055 ( (frame / (fps * 3600) % 24)) % 10;
00056 }
00057
00058 int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
00059 {
00060 int hh, mm, ss, ff, fps;
00061 char c;
00062
00063 if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
00064 av_log(avcl, AV_LOG_ERROR, "unable to parse timecode, "
00065 "syntax: hh:mm:ss[:;.]ff\n");
00066 return -1;
00067 }
00068
00069 fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
00070 tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
00071 tc->drop = c != ':';
00072
00073 if (tc->drop) {
00074 int tmins = 60*hh + mm;
00075 if (tc->rate.den != 1001 || fps != 30) {
00076 av_log(avcl, AV_LOG_ERROR, "error: drop frame is only allowed with"
00077 "30000/1001 FPS");
00078 return -2;
00079 }
00080 tc->start -= 2 * (tmins - tmins/10);
00081 }
00082 return 0;
00083 }