You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8KB

  1. /*
  2. * Copyright (C) 2006 Smartjog S.A.S, Baptiste Coudurier <baptiste.coudurier@gmail.com>
  3. * Copyright (C) 2011 Smartjog S.A.S, Clément Bœsch <clement.boesch@smartjog.com>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public
  9. * License as published by the Free Software Foundation;
  10. * version 2 of the License.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Timecode helpers
  24. */
  25. #include <stdio.h>
  26. #include "timecode.h"
  27. #include "libavutil/log.h"
  28. int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
  29. {
  30. int hh, mm, ss, ff, fps;
  31. char c;
  32. if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
  33. av_log(avcl, AV_LOG_ERROR, "unable to parse timecode, "
  34. "syntax: hh:mm:ss[:;.]ff\n");
  35. return -1;
  36. }
  37. fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
  38. tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
  39. tc->drop = c != ':'; // drop if ';', '.', ...
  40. if (tc->drop) { /* adjust frame number */
  41. int tmins = 60*hh + mm;
  42. if (tc->rate.den != 1001 || fps != 30) {
  43. av_log(avcl, AV_LOG_ERROR, "error: drop frame is only allowed with"
  44. "30000/1001 FPS");
  45. return -2;
  46. }
  47. tc->start -= 2 * (tmins - tmins/10);
  48. }
  49. return 0;
  50. }