@@ -47,12 +47,21 @@ def media(*ffprobe_args, load: true, autoload: true)
4747
4848 attr_reader :name , :metadata , :presets , :reporters , :timeout
4949
50- def initialize ( name : nil , metadata : nil , presets : [ ] , reporters : nil , timeout : nil , &compose_inargs )
50+ def initialize (
51+ name : nil ,
52+ metadata : nil ,
53+ presets : [ ] ,
54+ reporters : nil ,
55+ retries : nil ,
56+ timeout : nil ,
57+ &compose_inargs
58+ )
5159 @name = name
5260 @metadata = metadata
5361 @presets = presets
5462 @reporters = reporters
5563 @timeout = timeout
64+ @retries = retries &.abs || 0
5665 @compose_inargs = compose_inargs
5766 end
5867
@@ -63,34 +72,46 @@ def initialize(name: nil, metadata: nil, presets: [], reporters: nil, timeout: n
6372 # @yield The block to execute to report the transcoding process.
6473 # @return [FFMPEG::Transcoder::Status] The status of the transcoding process.
6574 def process ( media , output_path , &)
66- media = Media . new ( media , load : false ) unless media . is_a? ( Media )
67-
68- output_paths = [ ]
69- output_path = Pathname . new ( output_path )
70- output_dir = output_path . dirname
71- output_filename_kwargs = {
72- basename : output_path . basename ( output_path . extname ) ,
73- extname : output_path . extname
74- }
75-
76- args = [ ]
77- @presets . each do |preset |
78- filename = preset . filename ( **output_filename_kwargs )
79- args += preset . args ( media )
80- args << ( filename . nil? ? output_path . to_s : output_dir . join ( filename ) . to_s )
81- output_paths << args . last
82- end
75+ status = nil
76+
77+ attempts = 0
78+ while attempts <= @retries
79+ media = Media . new ( media , load : false ) unless media . is_a? ( Media )
80+ context = { attempts : }
81+ context [ :retry ] = true if attempts . positive?
82+
83+ output_paths = [ ]
84+ output_path = Pathname . new ( output_path )
85+ output_dir = output_path . dirname
86+ output_filename_kwargs = {
87+ basename : output_path . basename ( output_path . extname ) ,
88+ extname : output_path . extname
89+ }
90+
91+ args = [ ]
92+ @presets . each do |preset |
93+ filename = preset . filename ( **output_filename_kwargs )
94+ args += preset . args ( media , context :)
95+ args << ( filename . nil? ? output_path . to_s : output_dir . join ( filename ) . to_s )
96+ output_paths << args . last
97+ end
98+
99+ inargs = CommandArgs . compose ( media , context :, &@compose_inargs ) . to_a
100+ status = media . ffmpeg_execute (
101+ *args ,
102+ inargs :,
103+ reporters :,
104+ timeout :,
105+ status : Status . new ( output_paths ) ,
106+ &
107+ )
83108
84- inargs = CommandArgs . compose ( media , &@compose_inargs ) . to_a
109+ return status if status . success?
110+
111+ attempts += 1
112+ end
85113
86- media . ffmpeg_execute (
87- *args ,
88- inargs :,
89- reporters :,
90- timeout :,
91- status : Status . new ( output_paths ) ,
92- &
93- )
114+ status
94115 end
95116
96117 # Transcodes the media file using the preset configurations
0 commit comments