mlaiacker / rosbag2video

converts image sequence in ros bag files to video files
GNU General Public License v2.0
313 stars 111 forks source link

Object has no attribute 'format' #20

Open reem90 opened 3 years ago

reem90 commented 3 years ago

I installed the code and I run it. There was no problem but no video has been generated. After that, I installed the following dependencies and tried to run the python code again and an error occurred.

sudo apt install python3-roslib python3-sensor-msgs python3-opencv

The error is as follows:


Traceback (most recent call last):
  File "./rosbag2video.py", line 209, in addBag
    if msg.format.find("jpeg")!=-1 :
AttributeError: '_sensor_msgs__Image' object has no attribute 'format'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./rosbag2video.py", line 305, in <module>
    videowriter.addBag(bagfile)
  File "./rosbag2video.py", line 264, in addBag
    self.write_output_video( msg, topic, t, RAWIMAGE_VIDEO, pix_fmt )
  File "./rosbag2video.py", line 185, in write_output_video
    self.p_avconv[topic].stdin.write(msg.data)
BrokenPipeError: [Errno 32] Broken pipe

Are there any other dependencies required? 
vinesmsuic commented 3 years ago

Encountered same problem, but I found it can run only when you did not specify any parameter.

python rosbag2video.py yourfile.bag 
Zoey-946 commented 2 years ago

Hi! I had also faced this problem. Would you please tell me what should I do to solve this?

Pallav1299 commented 2 years ago

Try deleting the existing output file that was created. Must be naive to solve.

ZhangZixuan97 commented 1 year ago

I made some attempts and found that it has strict requirements on the format of the command. As written in -h: rosbag2video.py [--fps 25] [--rate 1] [-o outputfile] [-v] [-s] [-t topic] bagfile1 [bagfile2] ...

It seems that the parameter needs to be entered before the bagfile name. Work like: python rosbag2video.py -t /usb_cam/image_raw mybag.bag Parameters don't work: python rosbag2video.py mybag.bag -t /usb_cam/image_raw

In addition, there cannot already be an MP4 file with the same name in the folder.

DrChungAlbert commented 5 months ago

I think this cmd can solve the broken pipe issue

if video_fmt == MJPEG_VIDEO: cmd = [VIDEO_CONVERTER_TO_USE, '-y', '-v', '1', '-stats', '-r', str(self.fps), '-c', 'mjpeg', '-f', 'mjpeg', '-i', '-', '-an', out_file] elif video_fmt == RAWIMAGE_VIDEO: size = str(msg.width) + "x" + str(msg.height) cmd = [VIDEO_CONVERTER_TO_USE, '-y', '-v', '1', '-stats', '-r', str(self.fps), '-f', 'rawvideo', '-s', size, '-pix_fmt', pix_fmt, '-i', '-', '-an', out_file]

cardboardcode commented 1 month ago

Was able to reproduce this faulty behaviour.

Cause of Issue :bug:

This is typically caused by the fact that a file of the same name ffmpeg is writing to exist. When attempting to overwite the existing output video file, it will result in the following error captured in this thread:

BrokenPipeError: [Errno 32] Broken pipe

The error AttributeError: '_sensor_msgs__Image' object has no attribute 'format is a red herring, meaning that it has already been handled appropriately in function addBag. The core error lies with the former.

Solution [Short-Term] :adhesive_bandage:

Just remove the output video file with the same name in the directory you are running rosbag2video.py in.

If unsure which video is it, please remove all video files in the directory in question.

Solution [Long-Term] :green_circle:

Will write up a Pull Request with a modification to generate timestamped output video file name by default to generate uniquely-named output video file.

Will update here once done.