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

Object has no attribute 'format' #20

Open
reem90 opened this issue May 2, 2021 · 6 comments
Open

Object has no attribute 'format' #20

reem90 opened this issue May 2, 2021 · 6 comments

Comments

@reem90
Copy link

reem90 commented May 2, 2021

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
Copy link

vinesmsuic commented Jun 1, 2021

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

python rosbag2video.py yourfile.bag 

@Zoey-946
Copy link

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

@Pallav1299
Copy link

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

@ZhangZixuan97
Copy link

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
Copy link

DrChungAlbert commented Jun 13, 2024

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
Copy link
Collaborator

cardboardcode commented Oct 12, 2024

Was able to reproduce this faulty behaviour.

Cause of Issue 🐛

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] 🩹

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] 🟢

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants