Skip to content

Contents transfer

Tomohiko Ozawa edited this page Oct 1, 2016 · 5 revisions

If your camera supports Contents Transfer API group, you can transfer the contents recorded in the camera storage to your client PC. Contents transfer is divided into 4 steps:

  1. Change Camera Function by #change_function_to_transfer
  2. [Optional] Get a list of dates and content counts by #get_date_list.
  3. Get a list of content information by #get_content_list.
  4. Transfer contents to your client PC by #transfer_contents giving the list of contents.

Change camera function

You have to change Camera Function to 'Contents Transfer' before handling contents. You can do it by calling #change_function_to_transfer.

cam = SonyCameraRemoteAPI::Camera.new
cam.change_function_to_transfer

When you want to perform shooting again, don't forget to call #change_function_to_shoot to restore the function.

[Optional] Get a list of dates and content counts

This step is only needed if you want to search contents by dates. If you want some contents of specific date, you should get the list of dates and content counts by #get_date_list to confirm the existence of contents. You can also narrow down dates by specifying the type of contents. Following options are available for #get_date_list.

Argument Usage If not specified
type Type of contents. 'still', 'movie_mp4' or 'movie_xavcs'. All types
sort Sort order. 'descending' or 'ascending'. descending
date_count Number of date to get. All dates
content_count Number of contents to get. All contents

Values to be returned are two arrays:

  • An array of Hash objects of date information. You can get the actual date of 'YYYYMMdd' format by 'title' key.
  • An array of content counts of the associated date.

Here are examples:

# Get all dates and content counts of the associated date.
dates = cam.get_date_list
# Get 5 newest dates that contains XAVC-S movie contents.
dates = cam.get_date_list(type: 'movie_xavcs', date_count: 5)
# Get dates until the sum of still contents of each date exceeds 100.
dates = cam.get_date_list(type: 'still', content_count: 100)

dates.each do |date|
  puts "date: #{date['title']}"                # Date in the format 'YYYYMMdd'
  puts "count: #{date['contentCount']}"        # Content count
  puts "contentKind: #{date['contentKind']}"   # Content kind (always 'directory' in this case) 
end

Get a list of content information

Content information is a Hash object that contains the information of the content, e.g. filename, created time, URI and so on. It can be obtained by #get_content_list, which has many options for searching contents as listed below.

Argument Usage If not specified
type Type of contents. still, movie_mp4 or movie_xavcs. All types
date Creation date in the format of YYYYMMDD. All dates
sort Sort order. descending or ascending. descending
count Number of contents to get. All contents

type allows to be a list of types, such as ['movie_xavcs', 'movie_mp4']. Here are examples:

# Get all contents
contents = cam.get_content_list
# Get still contents created on 2016/8/1
contents = cam.get_content_list(type: 'still', date: '20160801')
# Get 3 oldest movie contents
contents = cam.get_content_list(type: ['movie_xavcs', 'movie_mp4'], 
                                sort: 'ascending', count: 3)

contents.each do |c|
  puts c['content']['original'][0]['fileName']    # File name of contents
  puts c['contentKind']                           # Kind of contents, 'still', 'movie_mp4' or 'movie_xavcs'
  puts c['createdTime']                           # Created time of contents in ISO8610 format
  puts c['content']['original'][0]['url']         # Content URI
end

Transfer contents

After obtaining content informations, you can transfer them by #transfer_contents giving the content informations. Following keyword arguments are available for #transfer_contents.

Argument Class Usage
filenames Array Filenames, which the contents are saved as
dir String Directory where the contents are saved
size String Size of contents (only available for 'still' type contents). 'original', 'large', 'small' or 'thumbnail'.

For example, you can transfer 2 latest still images with small size and save as '1.JPG' and '2.JPG' to 'contents' directory by:

cam.get_content_list type: 'still', count: 2
cam.transfer_contents contents, filenames: ['1.JPG', '2.JPG'], 
                                dir: 'contents', size: 'small'

Now then, here is the throughout example that transfer MP4 movies recorded in the past 7 days to 'movies' directory:

cam.change_function_to_transfer
dates = cam.get_date_list type: 'movie_mp4', date_count: 7
dates.each do |date|
  # Get MP4 movies of each date
  contents = cam.get_content_list type: 'movie_mp4', date: date['title']
  # Transfer contents
  cam.transfer_contents contents dir: 'movies'
end