From there we can trigger some business rules on the spaces, which will execute this custom action to perform transformation of all video files.. Inside the videos space, create spaces f
Trang 1Various options for video transcoding
Following are the various options for video transcoding:
• -b bitrate
Set the video bitrate in bit/s (default = 200 kb/s)
=>512 k
• -r fps
Set frame rate (Hz value, fraction, or abbreviation), (default = 25)
=>15.02
• -s size
Set frame size The format is 'wxh' (ffserver default = 160x128, ffmpeg default
= same as source)
=>320x240
• -aspect aspect
Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
=>4:3
Various options for audio transcoding
Following are the various options for audio transcoding:
• -ar freq
Set the audio sampling frequency (default = 44100 Hz)
=> 44100
• -ab bitrate
Set the audio bitrate in bit/s (default = 64 k)
=> 64 k
• -ac channels
Set the number of audio channels (default = 1 Mono; 2 = stereo)
=> 2
For further details and all options, you can refer to http://www.ffmpeg.org/
ffmpeg-doc.html
Trang 2Integrating transformation as an Action in Alfresco
In this section, we will see how we can use FFMPEG transformations as a custom action in Alfresco From there we can trigger some business rules on the spaces, which will execute this custom action to perform transformation of all video files Follow these steps to execute the transformation:
1 We need to configure the extra mime types that we want to use Here in our case, we are using 3GP, MP2, MP4, AVI, MOV, and many more All others are already supported by Alfresco and are defined in the mimetype-map.xml file
in Alfresco (except 3GP) So we need to add 3GP as a mimetype supported by Alfresco in the mimetype-map file, as follows:
<config evaluator="string-compare" condition="Mimetype Map">
<mimetypes>
<mimetype mimetype="video/3gp" display="Mobile video">
<extension>3gp</extension>
</mimetype>
</mimetypes>
</config>
2 The next step is, as FFMPEG is a command-line interface, we can use
Alfresco's org.alfresco.util.exec.RuntimeExec class to execute this command For that we need to configure it as a bean, which will be referred
by our custom action executer We can make these bean entries in the
custom-services-context.xml file
<bean id="transformer.ffmpegVideo"
class="com.cignex.alfresco.repo.content.transform
FfmpegVideoContentTransformer"
parent="baseContentTransformer"
init-method=»init»>
<property name=»executer»>
<bean name=»transformer.ffmpegVideo.Command»
class=»org.alfresco.util.exec.RuntimeExec»>
<property name=»commandMap»>
<map>
<entry key=»Windows.*»>
<value>ffmpeg -i «${source}» ${options}
«${target}»</value>
</entry>
</map>
</property>
<property name=»defaultProperties»>
Trang 3</property>
</bean>
</property>
</bean>
<bean id="transform-video"
class="com.cignex.alfresco.repo.action.executer
FfmpegVideoTransformActionExecuter"
parent=»transform»>
<property name=»videoContentTransformer»>
<ref bean=»transformer.ffmpegVideo» />
</property>
</bean>
3 In the web-client-config-custom.xml file, add the following:
<config evaluator="string-compare" condition="Action Wizards">
<video-transformers>
<transformer name="video/x-msvideo"/>
<transformer name="video/mp4"/>
<transformer name="video/3gp"/>
<transformer name="video/x-ms-wmv"/>
</video-transformers>
<action-handlers>
<handler name="transform-video"
class="com.cignex.alfresco.web.bean.actions.handlers
FfmpegTransformVideoHandler" />
</action-handlers>
</config>
4 Here you can specify all transformer names, and the formats you want to support in the transform action from the Alfresco UI as:
<transformer name="video/mp4"/>
5 You can add more if you want; here we have configured four
different formats
6 Once this is done, you need to create custom Action Executer classes and do the configurations for this
You can also refer to the following Wikis for more detail on these:
http://wiki.alfresco.com/wiki/Custom_Actions http://wiki.alfresco.com/wiki/Wizard_Framework
Trang 47 After finishing creation and configuration of the Action Executer, you are ready with the example code Now start the Alfresco server and we will see how you can configure the rule for transformation
8 We will create the folder structure such as Company Home | Cignex | videos Inside the videos space, create spaces for all different types of formats
(for video) that you want to support (that is, MPEG4, 3GP, and so on)
Configuring FFMPEG transformation as a
business rule
Alfresco DM provides the business rule; you can configure a business rule for a particular type of content or for all the content in a particular space Here we will
configure a business rule on the videos space to transform the videos we upload in
this space to convert into other formats
1 Browse to Company Home | Cignex | videos and click on More Actions | Manage Content Rules On the next screen, click on the Create Rule link In the first step of the Create Rule Wizard, select All Items and click on Add to List Click on Next.
2 In the next step, you can see the action created by us in the Select Action combo box Select the action Transform video using FFMPEG and copy, as shown in the following screenshot Click on Next:
Trang 53 In the next step, you need to select the proper value for the required format (the target format for transformation) As we have configured 3GP, MP4, AVI, and WMV in the configuration file, we will have all these four options available to us for transforming the video After that, provide the proper options for a particular video transformation selection based on source- and target-type of video file Also, you need to provide the destination space to
copy the transformed video Here we have created the 3GP space inside the videos folder, so provide it as a destination folder Click on OK.
4 In the next step, choose Type as Inbound; also provide Title and
Description Check the option Apply rule to sub spaces as shown in the following screenshot Click on Finish:
Trang 6Now whenever you upload any video in videos space, it will be transformed into the 3GP video format It will also be copied to the 3GP space inside the videos space as
shown in the next screenshot:
You can create as many rules and transformations as you want to perform for
different video types
Download the sample code files from the Packt website
Copying videos from DM to WCM
In this section, we will discuss the different ways to copy the content—here videos from DM to WCM One is with the help of business rule and the other one is using JavaScript Both of these are described in the following sections
DM to WCM using business rule
We have videos available in all required formats under Company Home | Cignex | videos and the respective folders for the video formats Now we need to move these
videos in WCM in the proper web project and to the proper folder
Trang 7There is one more rule available in DM, which will copy the DM content to WCM For this, you need to configure that rule Use the following steps:
1 Browse to Company Home | Cignex | videos and click on More Actions | Manage Content Rules In the next screen, click on the Create Rule link In the first step of the Create Rule Wizard, select All Items and click on Add to List Click on Next.
2 In the next step, you can see the action created by us in the Select Action combo box Select the Copy item to a folder in a web project action, as shown in the following screenshot Click on Next:
Trang 83 In the next screen, select the web project and the specific folder in that
web project as Destination folder and click on OK as shown in the
following screenshot:
4 Then click on Next In the next screen, choose Type as Inbound and provide the Title and the Description Also select Apply rule to sub spaces as shown
in the next screenshot Click on Finish:
Trang 9DM to WCM using JavaScript
There is one API available in Alfresco JavaScript, which allows you to copy content from one repository to another Using this API, you can copy the content from DM
to WCM Here we will copy all the videos, which we transformed previously to a specific folder in the web project
Alfresco JavaScript has crossRepoCopy as one of the root objects, using which
we can copy nodes or content between the different repositories (Document
Management and Web Content Management)
copy(ScriptNode source, ScriptNode destination, String name): This will copy a source node to the specified destination node and return the new node In the parameter name, you can specify the new name for that content, which is being copied to some other location
Using this API, we can copy all of the transformed video from the DM repository to the WCM repository, as follows:
1 Create new JavaScript file, copy_wcm.js, with the following content:
logger.log("Document :: " + document.name);
var l_cignex_root=avm.lookupStore("wwwcignex admin");
l_video_path="/ROOT/videos";
if(l_cignex_root != null) {
l_videoNode = l_cignex_root.lookupNode(l_video_path + "/"); if(l_videoNode != null){
crossRepoCopy.copy(document,l_videoNode,document.name);
logger.log(document.name + " is copied");
}
}
2 Upload this JavaScript file to the Company Home | Data Dictionary | Scripts space in Alfresco.
Trang 103 Now, with the help of Run Action, you can execute this script Go to the View Details page of the video content, which you want to copy to the WCM Click on Run Action from the available actions, as shown in the
following screenshot: