Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[audio_video_recorder] Add audio_video_recorder_server and client library to audio_video_recorder #1704

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions audio_video_recorder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ cmake_minimum_required(VERSION 2.8.3)

project(audio_video_recorder)

find_package(catkin REQUIRED COMPONENTS roscpp audio_common_msgs sensor_msgs)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
audio_common_msgs
message_generation
sensor_msgs
)

find_package(PkgConfig)
pkg_check_modules(GST1.0 gstreamer-1.0 REQUIRED)

find_package(Boost REQUIRED COMPONENTS thread)

catkin_python_setup()

add_message_files(
FILES
RecordTask.msg
RecordTaskArray.msg
)

add_service_files(
FILES
StartRecord.srv
StopRecord.srv
)

generate_messages(
DEPENDENCIES
)

catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS
Expand All @@ -28,8 +52,11 @@ add_executable(audio_video_recorder src/audio_video_recorder.cpp)
target_link_libraries(audio_video_recorder ${catkin_LIBRARIES} ${GST1.0_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(audio_video_recorder ${catkin_EXPORTED_TARGETS})

catkin_install_python(PROGRAMS node_scripts/audio_video_recorder_server node_scripts/sample_audio_video_recorder_client.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

install(TARGETS audio_video_recorder
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

install(DIRECTORY launch sample
install(DIRECTORY launch sample euslisp
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
42 changes: 38 additions & 4 deletions audio_video_recorder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,25 @@ You can record audio and video on your laptop.
roslaunch audio_video_recorder sample_audio_video_recorder.launch
```

## Parameters
If you want to sedd ROS Interface Sample (Topic/Service) of audio_video_recorder, Please run audio_video_recorder_server demo.

```
roslaunch audio_video_recorder sample_audio_video_recorder_server.launch
```

And if you want to see an example of client script for audio_video_recorder_server. please see [sample_audio_video_recorder_client.py](./node_scripts/sample_audio_video_recorder_client.py).

## Nodes

### audio_video_recorder

Node to record audio and video with given parameters.

#### Parameters

Node: `audio_video_recorder/audio_video_recorder`

### Common parameters
##### Common parameters

- `queue_size` (`Int`, default: `100`)

Expand All @@ -33,7 +47,7 @@ Node: `audio_video_recorder/audio_video_recorder`

Output file format (Only `avi` is supported now.)

### Audio parameters
##### Audio parameters

- `audio_format` (`String`, default: `mp3`)

Expand All @@ -55,7 +69,7 @@ Node: `audio_video_recorder/audio_video_recorder`

Audio sample rate

### Video parameters
##### Video parameters

- `video_encoding` (`String`, default: `RGB`)

Expand All @@ -72,3 +86,23 @@ Node: `audio_video_recorder/audio_video_recorder`
- `video_framerate` (`Int`, default: `30`)

Video frame rate

### audio_video_recorder_server

ROS Interface and recording task manager for audio_video_recorder.

#### Services

- `~start_record` (`audio_video_recorder/StartRecord`)

Start a recording task

- `~stop_record` (`audio_video_recorder/StopRecord`)

Stop a specified recording task

#### Publisher

- `~record_tasks` (`audio_video_recorder/RecordTaskArray`)

Recording tasks currently running.
76 changes: 76 additions & 0 deletions audio_video_recorder/euslisp/audio-video-recorder-client.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
(ros::load-ros-manifest "audio_video_recorder")
(ros::load-ros-manifest "sensor_msgs")


(defun call-start-record-service
(audio-topic-name
image-topic-name
file-name
video-framerate
&key
(queue-size 100)
(file-format "avi")
(audio-format "mp3")
(audio-sample-format "S16LE")
(audio-channels 1)
(audio-depth 16)
(audio-sample-rate 16000)
(video-encoding "RGB")
(video-height nil)
(video-width nil))
(let (msg req res)
(if (or (not video-height) (not video-width))
(progn
(setq msg (one-shot-subscribe image-topic-name sensor_msgs::Image :timeout 5000))
(if (not msg)
(progn
(ros::ros-error "Image is not published from ~A" image-topic-name)
(return-from call-start-record-service nil)))
(setq video-height (send msg :height))
(setq video-width (send msg :width))))
(setq req (instance audio_video_recorder::StartRecordRequest :init))
(send req :task :audio_topic_name audio-topic-name)
(send req :task :image_topic_name image-topic-name)
(send req :task :queue_size queue-size)
(send req :task :file_name file-name)
(send req :task :file_format file-format)
(send req :task :audio_format audio-format)
(send req :task :audio_sample_format audio-sample-format)
(send req :task :audio_channels audio-channels)
(send req :task :audio_depth audio-depth)
(send req :task :audio_sample_rate audio-sample-rate)
(send req :task :video_encoding video-encoding)
(send req :task :video_height video-height)
(send req :task :video_width video-width)
(send req :task :video_framerate video-framerate)
(setq res (ros::service-call "/audio_video_recorder_server/start_record" req t))
(if (not (send res :success))
(progn
(ros::ros-error "Failed to start recording: ~A" (send res :message))
(return-from call-start-record-service nil)))
(send res :success)
))

(defun call-stop-record-service
(file-name)
(let (req res)
(setq req (instance audio_video_recorder::StopRecordRequest :init))
(send req :file_name file-name)
(setq res (ros::service-call "/audio_video_recorder_server/stop_record" req t))
(if (not (send res :success))
(progn
(ros::ros-error "Failed to stop recording: ~A" (send res :message))
(return-from call-stop-record-service nil)))
(send res :success)
))

(defun get-recording-task-array
()
(let (msg)
(setq msg (one-shot-subscribe "/audio_video_recorder_server/record_tasks" audio_video_recorder::RecordTaskArray :timeout 10000))
(if (not msg)
(progn
(ros::ros-error "Failed to get a task array message.")
(return-from get-recording-task-array nil)))
(send msg :array)
))
38 changes: 38 additions & 0 deletions audio_video_recorder/euslisp/sample-audio-video-recorder-client.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env roseus

(ros::load-ros-manifest "sensor_msgs")
(ros::load-ros-manifest "audio_common_msgs")

(load "package://audio_video_recorder/euslisp/audio-video-recorder-client.l")

(ros::roseus "audio_video_recorder_client_demo")

(setq destination (ros::get-param "~destination" "/tmp/"))
(setq file-name-01 (concatenate string destination "audio_video_recorder_server_demo_01.avi"))
(setq file-name-02 (concatenate string destination "audio_video_recorder_server_demo_02.avi"))

(setq msg-image (one-shot-subscribe "/usb_cam_node/image_raw" sensor_msgs::Image :timeout 10000))
(setq msg-audio (one-shot-subscribe "/audio" audio_common_msgs::AudioData :timeout 10000))

(if (or (not msg-image) (not msg-audio))
(progn
(ros::ros-error "Failed to get image or audio message")
(exit 1)))

(ros::ros-info "Start a recording task")
(call-start-record-service "/audio" "/usb_cam_node/image_raw" file-name-01 30)
(unix::sleep 5)
(ros::ros-info "Start another recording task")
(call-start-record-service "/audio" "/usb_cam_node/image_raw" file-name-02 30)
(unix::sleep 2)
(ros::ros-info "Get a recording task array")
(setq task-array (get-recording-task-array))
(ros::ros-info " : ~A" task-array)
(unix::sleep 3)
(ros::ros-info "Stopped the first recording task.")
(call-stop-record-service file-name-01)
(unix::sleep 5)
(ros::ros-info "Stopped the second recording task.")
(call-stop-record-service file-name-02)

(exit 0)
2 changes: 1 addition & 1 deletion audio_video_recorder/launch/audio_video_recorder.launch
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<arg name="video_framerate" />
<arg name="video_encoding" />

<node name="audio_video_recorder" pkg="audio_video_recorder"
<node name="$(anon audio_video_recorder)" pkg="audio_video_recorder"
type="audio_video_recorder" output="screen">
<remap from="~input/audio" to="$(arg audio_topic_name)" />
<remap from="~input/image" to="$(arg image_topic_name)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<launch>
<node
pkg="audio_video_recorder"
type="audio_video_recorder_server"
name="audio_video_recorder_server"
/>
</launch>
14 changes: 14 additions & 0 deletions audio_video_recorder/msg/RecordTask.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
string audio_topic_name
string image_topic_name
int32 queue_size
string file_name # This will be used as key
string file_format
string audio_format
string audio_sample_format
int32 audio_channels
int32 audio_depth
int32 audio_sample_rate
string video_encoding
int32 video_height
int32 video_width
int32 video_framerate
1 change: 1 addition & 0 deletions audio_video_recorder/msg/RecordTaskArray.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
audio_video_recorder/RecordTask[] array
16 changes: 16 additions & 0 deletions audio_video_recorder/node_scripts/audio_video_recorder_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import rospy
from audio_video_recorder.audio_video_recorder_server import AudioVideoRecorderServer


def main():

rospy.init_node('audio_video_recorder_server')
server = AudioVideoRecorderServer()
server.spin()


if __name__=='__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import rospy
from audio_video_recorder.audio_video_recorder_client import AudioVideoRecorderClient
from sensor_msgs.msg import Image
from audio_common_msgs.msg import AudioData


def main():

rospy.init_node('audio_video_recorder_client_demo')

destination = rospy.get_param('~destination','/tmp/')
file_name_01 = destination + 'audio_video_recorder_server_demo_01.avi'
file_name_02 = destination + 'audio_video_recorder_server_demo_02.avi'

try:
msg_image = rospy.wait_for_message('/usb_cam_node/image_raw', Image, timeout=rospy.Duration(10))
msg_audio = rospy.wait_for_message('/audio', AudioData, timeout=rospy.Duration(10))
except rospy.ROSException as e:
rospy.logerr(e)
return

client = AudioVideoRecorderClient()
rospy.loginfo('Start a recording task')
client.start_record('/audio','/usb_cam_node/image_raw',file_name_01,30)
rospy.sleep(5)
rospy.loginfo('Start another recording task')
client.start_record('/audio','/usb_cam_node/image_raw',file_name_02,30)
rospy.sleep(2)
task_array = client.get_record_task_array()
rospy.loginfo('Get a recording task array : {}'.format(task_array))
rospy.sleep(3)
rospy.loginfo('Stop the first recording task')
client.stop_record(file_name_01)
rospy.sleep(5)
rospy.loginfo('Stop the second recording task')
client.stop_record(file_name_02)


if __name__ == '__main__':
main()
5 changes: 5 additions & 0 deletions audio_video_recorder/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@
<buildtool_depend>catkin</buildtool_depend>

<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>audio_common_msgs</build_depend>
<build_depend>libgstreamer1.0-dev</build_depend>
<build_depend>libgstreamer-plugins-base1.0-dev</build_depend>
<build_depend>message_filters</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>sensor_msgs</build_depend>

<exec_depend>roscpp</exec_depend>
<exec_depend>roslaunch</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>audio_common_msgs</exec_depend>
<exec_depend>gstreamer1.0</exec_depend>
<exec_depend>gstreamer1.0-plugins-base</exec_depend>
<exec_depend>gstreamer1.0-plugins-good</exec_depend>
<exec_depend>gstreamer1.0-plugins-ugly</exec_depend>
<exec_depend>message_filters</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<launch>
<node pkg="audio_capture" type="audio_capture" name="audio_capture" output="log">
<rosparam subst_value="true">
bitrate: 128
device: ""
channels: 1
sample_rate: 16000
format: mp3
sample_format: S16LE
</rosparam>
</node>

<node name="usb_cam_node" pkg="usb_cam" type="usb_cam_node" output="log">
<rosparam subst_value="true">
pixel_format: yuyv
image_height: 480
image_width: 640
framerate: 30
</rosparam>
</node>

<node
pkg="audio_video_recorder"
type="audio_video_recorder_server"
name="audio_video_recorder_server"
output="screen"
/>

<node
pkg="audio_video_recorder"
type="sample_audio_video_recorder_client.py"
name="sample_audio_video_recorder_client"
required="true"
output="screen"
/>

</launch>
Loading