options.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package ffmpeg
  2. import (
  3. "fmt"
  4. "reflect"
  5. "strconv"
  6. )
  7. // Options defines allowed FFmpeg arguments
  8. type Options struct {
  9. Aspect *string `flag:"-aspect"`
  10. Resolution *string `flag:"-s"`
  11. VideoBitRate *string `flag:"-b:v"`
  12. VideoBitRateTolerance *int `flag:"-bt"`
  13. VideoMaxBitRate *int `flag:"-maxrate"`
  14. VideoMinBitrate *int `flag:"-minrate"`
  15. VideoCodec *string `flag:"--c:v"`
  16. Vframes *int `flag:"-vframes"`
  17. FrameRate *int `flag:"-r"`
  18. AudioRate *int `flag:"-ar"`
  19. KeyframeInterval *int `flag:"-g"`
  20. AudioCodec *string `flag:"-c:a"`
  21. AudioBitrate *string `flag:"-ab"`
  22. AudioChannels *int `flag:"-ac"`
  23. AudioVariableBitrate *bool `flag:"-q:a"`
  24. BufferSize *int `flag:"-bufsize"`
  25. Threadset *bool `flag:"-threads"`
  26. Threads *int `flag:"-threads"`
  27. Preset *string `flag:"-preset"`
  28. Tune *string `flag:"-tune"`
  29. AudioProfile *string `flag:"-profile:a"`
  30. VideoProfile *string `flag:"-profile:v"`
  31. Target *string `flag:"-target"`
  32. Duration *string `flag:"-t"`
  33. Qscale *uint32 `flag:"-qscale"`
  34. Crf *uint32 `flag:"-crf"`
  35. Strict *int `flag:"-strict"`
  36. MuxDelay *string `flag:"-muxdelay"`
  37. SeekTime *string `flag:"-ss"`
  38. SeekUsingTimestamp *bool `flag:"-seek_timestamp"`
  39. MovFlags *string `flag:"-movflags"`
  40. HideBanner *bool `flag:"-hide_banner"`
  41. OutputFormat *string `flag:"-f"`
  42. CopyTs *bool `flag:"-copyts"`
  43. NativeFramerateInput *bool `flag:"-re"`
  44. InputInitialOffset *string `flag:"-itsoffset"`
  45. RtmpLive *string `flag:"-rtmp_live"`
  46. HlsPlaylistType *string `flag:"-hls_playlist_type"`
  47. HlsListSize *int `flag:"-hls_list_size"`
  48. HlsSegmentDuration *int `flag:"-hls_time"`
  49. HlsMasterPlaylistName *string `flag:"-master_pl_name"`
  50. HlsSegmentFilename *string `flag:"-hls_segment_filename"`
  51. HTTPMethod *string `flag:"-method"`
  52. HTTPKeepAlive *bool `flag:"-multiple_requests"`
  53. Hwaccel *string `flag:"-hwaccel"`
  54. StreamIds map[string]string `flag:"-streamid"`
  55. VideoFilter *string `flag:"-vf"`
  56. AudioFilter *string `flag:"-af"`
  57. SkipVideo *bool `flag:"-vn"`
  58. SkipAudio *bool `flag:"-an"`
  59. CompressionLevel *int `flag:"-compression_level"`
  60. MapMetadata *string `flag:"-map_metadata"`
  61. Metadata map[string]string `flag:"-metadata"`
  62. EncryptionKey *string `flag:"-hls_key_info_file"`
  63. Bframe *int `flag:"-bf"`
  64. PixFmt *string `flag:"-pix_fmt"`
  65. WhiteListProtocols []string `flag:"-protocol_whitelist"`
  66. Overwrite *bool `flag:"-y"`
  67. ExtraArgs map[string]interface{}
  68. }
  69. // GetStrArguments ...
  70. func (opts Options) GetStrArguments() []string {
  71. f := reflect.TypeOf(opts)
  72. v := reflect.ValueOf(opts)
  73. values := []string{}
  74. for i := 0; i < f.NumField(); i++ {
  75. flag := f.Field(i).Tag.Get("flag")
  76. value := v.Field(i).Interface()
  77. if !v.Field(i).IsNil() {
  78. if _, ok := value.(*bool); ok {
  79. values = append(values, flag)
  80. }
  81. if vs, ok := value.(*string); ok {
  82. values = append(values, flag, *vs)
  83. }
  84. if vs, ok := value.(*int); ok {
  85. values = append(values, flag, strconv.Itoa(*vs))
  86. }
  87. if va, ok := value.([]string); ok {
  88. for i := 0; i < len(va); i++ {
  89. item := va[i]
  90. values = append(values, flag, item)
  91. }
  92. }
  93. if vm, ok := value.(map[string]string); ok {
  94. for k, v := range vm {
  95. values = append(values, flag, fmt.Sprintf("%v:%v", k, v))
  96. }
  97. }
  98. }
  99. }
  100. return values
  101. }
  102. // Metadata ...
  103. type Metadata struct {
  104. Streams []Streams `json:"streams"`
  105. Format Format `json:"format"`
  106. }
  107. // Streams defines allowed stream options
  108. type Streams struct {
  109. Index int
  110. ID string `json:"id"`
  111. CodecName string `json:"codec_name"`
  112. CodecLongName string `json:"codec_long_name"`
  113. Profile string `json:"profile"`
  114. CodecType string `json:"codec_type"`
  115. CodecTimeBase string `json:"codec_time_base"`
  116. CodecTagString string `json:"codec_tag_string"`
  117. CodecTag string `json:"codec_tag"`
  118. Width int `json:"width"`
  119. Height int `json:"height"`
  120. CodedWidth int `json:"coded_width"`
  121. CodedHeight int `json:"coded_height"`
  122. HasBFrames int `json:"has_b_frames"`
  123. SampleAspectRatio string `json:"sample_aspect_ratio"`
  124. DisplayAspectRatio string `json:"display_aspect_ratio"`
  125. PixFmt string `json:"pix_fmt"`
  126. Level int `json:"level"`
  127. ChromaLocation string `json:"chroma_location"`
  128. Refs int `json:"refs"`
  129. QuarterSample string `json:"quarter_sample"`
  130. DivxPacked string `json:"divx_packed"`
  131. RFrameRrate string `json:"r_frame_rate"`
  132. AvgFrameRate string `json:"avg_frame_rate"`
  133. TimeBase string `json:"time_base"`
  134. DurationTs int `json:"duration_ts"`
  135. Duration string `json:"duration"`
  136. Disposition Disposition `json:"disposition"`
  137. BitRate string `json:"bit_rate"`
  138. }
  139. // Disposition ...
  140. type Disposition struct {
  141. Default int `json:"default"`
  142. Dub int `json:"dub"`
  143. Original int `json:"original"`
  144. Comment int `json:"comment"`
  145. Lyrics int `json:"lyrics"`
  146. Karaoke int `json:"karaoke"`
  147. Forced int `json:"forced"`
  148. HearingImpaired int `json:"hearing_impaired"`
  149. VisualImpaired int `json:"visual_impaired"`
  150. CleanEffects int `json:"clean_effects"`
  151. }
  152. // Format ...
  153. type Format struct {
  154. Filename string
  155. NbStreams int `json:"nb_streams"`
  156. NbPrograms int `json:"nb_programs"`
  157. FormatName string `json:"format_name"`
  158. FormatLongName string `json:"format_long_name"`
  159. Duration string `json:"duration"`
  160. Size string `json:"size"`
  161. BitRate string `json:"bit_rate"`
  162. ProbeScore int `json:"probe_score"`
  163. Tags Tags `json:"tags"`
  164. }
  165. // Tags ...
  166. type Tags struct {
  167. Encoder string `json:"ENCODER"`
  168. }