accessing MPEG4 - H.264 video #1404
Replies: 3 comments 2 replies
-
I've never had any opportunities to check, but looking at what the DICOM Standard says:
I would try: from pydicom.encaps import generate_pixel_data_frame
with open('test.mp4', 'wb') as f:
f.write(next(generate_pixel_data_frame(ds.PixelData))) Also this might be relevant:
And
If you had a (small) anonymised dataset we could probably add a guide to our documentation for dealing with MPEG transfer syntaxes and/or a pixel data handler. |
Beta Was this translation helpful? Give feedback.
-
@armenabnousi did you figure it out? |
Beta Was this translation helpful? Give feedback.
-
Hi, Your suggested method from above works like a charm. Now I would be interested in the reverse method: how to encapsulate a h.264-ByteStream into PixelData ? I played around with encapsulation: with open('video.mp4', 'rb') as f:
ds.PixelData = encapsulate(f.read()) But since this function expects a List of bytes, this throws an error `TypeError: object of type 'int' has no len()´ The following technically "works" and would produce an readable DICOM, however the encoded video seems to be wrong; since I can't play it in any DICOM-Viewer or also the initial video extraction does not produce a valid video file: with open('video.mp4', 'rb') as f:
ds.PixelData = encapsulate(f.readlines()) The rest of the relevant tags should be correct: among others ds.file_meta.TransferSyntaxUID = pydicom.uid.MPEG4HP41
ds.PhotometricInterpretation = 'YBR_PARTIAL_420'
ds.LossyImageCompressionMethod = 'ISO_14496_10'
... Do you have advice on how to encapsulate the raw mp4-ByteStream into PixelData? Thanks! |
Beta Was this translation helpful? Give feedback.
-
I'm running into the following error. I understand this specific format is not supported yet. Could you suggest any workarounds? Is there a way to extract the bytes for the video and pass it to another library to run (or save it to the disk as an mp4)? thanks!
Unable to decode pixel data with a transfer syntax UID of '1.2.840.10008.1.2.4.102' (MPEG-4 AVC/H.264 High Profile / Level 4.1) as there are no pixel data handlers available that support it. Please see the pydicom documentation for information on supported transfer syntaxes
Beta Was this translation helpful? Give feedback.
All reactions