As a Content Management Product, Alfresco has two different modules, DM and WCM.
In this section, we will see how we can use Alfresco with the combination of DM and WCM both as a single repository. Consider a use case of a company where they are using Alfresco WCM for managing their website but at the same time they have an Intranet application, which is more for managing documents and other assets. For this Intranet, they are using the Alfresco DM. Now suppose some of the documents/assets need to be managed in DM but are basically part of the website and need to be deployed. In this scenario, we can get the advantage of both the DM and WCM in the same repository.
Let's take the example of the Cignex company. As we have already seen in the earlier chapter, the website for Cignex is managed by Alfresco WCM. But in this website, some of the images, videos, and so on are being used, which are managed in DM. There are some departments such as Marketing, Sales, HR, IT, and many more available that are using this Intranet application. Now if a Marketing person is uploading a video, then he or she may have some requirements such as it should be transformed into different formats like 3GP (for cell phones), MPEG4 (for iPod), and Flash (the default format for the website). Alfresco can be integrated with FFMPEG, using which we can easily transform the videos to other formats.
FFMPEG is a very popular high performance video and audio transcoder. It has various widely used commercial tools to convert audio and video files from one format to another. It is basically a command-line interface. We can easily integrate any such command-line applications with Alfresco.
You need to download the FFMPEG binary version for Microsoft Windows and put it into the<alfresco_install>/bin
directory. The command used for transformation is:
ffmpeg.exe -i [input_file.extension] [options] [output_file.extension]
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
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.
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:
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>
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"> <props> <prop key="options"></prop> </props> </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>
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>
<transformer name="video/mp4"/>
You can also refer to the following Wikis for more detail on these: http://wiki.alfresco.com/wiki/Custom_Actions
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.
Now 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.
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.
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.
There 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:
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:
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"); } }
copy_wcm.js
JavaScript and copy the content to the WCM in a specified web project and a specified folder, as shown in the following screenshot:You can also configure this 'Execute Script' as a rule on the videos folder. For configuring it as a business rule, you can follow the same steps as mentioned in the DM to WCM Using Business Rule section. Just choose the Execute a Script action during configuration and copy_wcm.js
as a value.
If you configure this rule for Inbound Documents, it will automatically copy the videos file to the corresponding destination folder in WCM.