timecode.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  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. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser 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 header
  24. */
  25. #ifndef AVCODEC_TIMECODE_H
  26. #define AVCODEC_TIMECODE_H
  27. #include <stdint.h>
  28. #include "libavutil/rational.h"
  29. #define TIMECODE_OPT(ctx, flags) \
  30. "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \
  31. "use ';' or '.' before frame number for drop frame", \
  32. offsetof(ctx, tc.str), \
  33. AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, flags
  34. struct ff_timecode {
  35. char *str; ///< string following the hh:mm:ss[:;.]ff format
  36. int start; ///< timecode frame start
  37. int drop; ///< drop flag (1 if drop, else 0)
  38. AVRational rate; ///< Frame rate in rationnal form
  39. };
  40. /**
  41. * @brief Adjust frame number for NTSC drop frame time code
  42. * @param frame_num Actual frame number to adjust
  43. * @return Adjusted frame number
  44. * @warning Adjustment is only valid in NTSC 29.97
  45. */
  46. int ff_framenum_to_drop_timecode(int frame_num);
  47. /**
  48. * @brief Convert frame id (timecode) to SMPTE 12M binary representation
  49. * @param frame Frame number
  50. * @param fps Frame rate
  51. * @param drop Drop flag
  52. * @return The actual binary representation
  53. */
  54. uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
  55. /**
  56. * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
  57. * from tc struct must be set.
  58. *
  59. * @param avcl A pointer to an arbitrary struct of which the first field is a
  60. * pointer to an AVClass struct (used for av_log).
  61. * @param tc Timecode struct pointer
  62. * @return 0 on success, negative value on failure
  63. * @warning Adjustement is only valid in NTSC 29.97
  64. */
  65. int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc);
  66. #endif /* AVCODEC_TIMECODE_H */