Class: Wiretap::Clip

Inherits:
Node
  • Object
show all
Defined in:
lib/wiretap.rb,
ext/node.cpp

Direct Known Subclasses

HiresClip, LowresClip, SlateClip

Instance Attribute Summary

Attributes inherited from Node

#parent, #server

Instance Method Summary collapse

Methods inherited from Node

#==, #[], #audio?, #children, #create_clip, #create_library, #create_node, #create_project, #create_reel, #destroy, #destroyed?, #find, #find_child, #hires?, #host?, #id, #id=, #import_image, #import_video, #library?, #lowres?, #ls, #meta, #metadata, #name, #node?, #project?, #reel?, #reload, #slate?, #type, #volume?

Instance Method Details

#clip?Boolean

Returns:

  • (Boolean)

#dump(path) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/wiretap.rb', line 176

def dump(path)
  return unless frame_names = dump!(path)
  fmt = format
  mencoder_cmd = "mencoder mf://#{frame_names.join(",")} -mf w=#{fmt.width}:h=#{fmt.height}:fps=25:type=sgi " +
     " -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo -oac copy -o output.avi"
  `(cd #{path} && #{mencoder_cmd} && ffmpeg -i output.avi output.mov) 2>&1 >/dev/null`
end

#formatObject

Returns the format of the clip



307
308
309
310
311
312
313
314
315
316
317
# File 'ext/node.cpp', line 307

static VALUE wiretap_clip_format(VALUE self) {
	Check_Node_Alive(self);
	
	WireTapNodeHandle* node;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	WireTapClipFormat format;
	NODERUN_E(node, node->getClipFormat(format));
	VALUE clipformat = Data_Wrap_Struct(cClipFormat, 0, wiretap_format_free, new WireTapClipFormat(format));
	rb_iv_set(clipformat, "@node", self);
	return clipformat;
}

#framesObject

Returns a Wiretap::NodeFrames object that gives access to the frames of the clip



333
334
335
336
337
338
339
340
341
# File 'ext/node.cpp', line 333

static VALUE wiretap_clip_frames(VALUE self) {
	Check_Node_Alive(self);
	
	WireTapNodeHandle* node;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	VALUE frames = Data_Wrap_Struct(cNodeFrames, 0, node_leave, node);
	rb_iv_set(frames, "@node", self);
	return frames;
}

#import_directory(dir_name) ⇒ Object

Import a directory of PPM files into the clip



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'ext/node.cpp', line 128

static VALUE wiretap_clip_import_directory(VALUE self, VALUE dir_name) {
	Check_Node_Alive(self);
	
	Check_Type(dir_name, T_STRING);
	
	WireTapNodeHandle* node;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	
	int count = 0;
	struct stat sb;
	/*
	 * Mplayer decoding video always start writing frame from 00000001.ppm
	 */
	for(int i = 1;; i++) {
		char filename[PATH_MAX];
		snprintf(filename, sizeof(filename), "%s/%08d.ppm", STR(dir_name), i);
		if(stat(filename, &sb) != 0) {
			break;
		}
		count = i;
	}
	
	if(count <= 0) {
		return Qnil;
	}
	

	NODERUN_EX_E(node, node->setNumFrames(count));
	WireTapClipFormat format;
	NODERUN_E(node, node->getClipFormat(format));	

	for(int i = 0; i < count; i++) {
		char filename[PATH_MAX];
		snprintf(filename, sizeof(filename), "%s/%08d.ppm", STR(dir_name), i+1);
		//rb_warn("Opening file %s", filename);

		std::auto_ptr<ImageIO> image(ImageIO::open(filename, format));
		if(!image.get()) {
			image.release();
			THROW("Couldn't open file %s for reading", filename);
		}
		image->read_format();
		std::auto_ptr<unsigned char> frame(image->read_data());
		NODERUN_EX_E(node, node->writeFrame(i, frame.get(), format.frameBufferSize()));
	}
	return self;
}

#slateObject

Returns the slate clip



222
223
224
# File 'lib/wiretap.rb', line 222

def slate
  children.find{|c| c.kind_of?(SlateClip)}
end

#to_sObject



163
164
165
# File 'lib/wiretap.rb', line 163

def to_s
  "#<#{self.class.to_s} '#{self.name}', frames: #{self.frames.count}>"
end

#to_video(path, options = {}) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/wiretap.rb', line 184

def to_video(path, options = {})
  return unless frame_names = dump!(path)
  fmt = format
  
  if options[:resize]
    target_width = options[:resize].split(/x/)[0]
    target_height = options[:resize].split(/x/)[1]
    
    frame_names.map! do | n |
      `convert -resize #{options[:resize]}! #{File.join(path,n)} #{File.join(path,n +'.resized.sgi')}`
      n + '.resized.sgi'
    end
  else
    target_width = fmt.width
    target_height = fmt.height
  end
  
  
  mencoder_cmd = "mencoder mf://#{frame_names.join(",")} -mf w=#{target_width}:h=#{target_height}:fps=25:type=sgi " +
     " -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo -o output.avi"
     
  begin
    # Try to assimilate audio in the clip
    find("#{self.name} (audio)").find("#{self.name} (stream)").dump "#{path}/audio.aiff"
    `(cd #{path} && #{mencoder_cmd} && ffmpeg -i output.avi -acodec aac -i audio.aiff output.mov) 2>&1 >/dev/null`
  rescue NoMethodError, Wiretap::Error
    # No audio given, proceed with images only
    `(cd #{path} && #{mencoder_cmd} && ffmpeg -i output.avi -acodec aac output.mov) 2>&1 >/dev/null`
  end
  
  outfile = path + "/output.mov"
  File.unlink(path + "/0.sgi")
  File.unlink(path + "/output.avi")
  
  outfile
end

#uriObject

Returns a name-based path to the clip (as opposed to the frame ID ranges provided by Wiretap ID)



168
169
170
171
172
173
174
# File 'lib/wiretap.rb', line 168

def uri
  ident = (self.server.hostname + '/' + self.id).split(/\//)
  ident[-1] = name
  ident[-2] = parent.name if parent.reel?

  return ident.join('/')
end