You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with video streams from a hardware device, which adding SEI NAL-units with specific data, in slightly malformed format.
ffmpeg complains about some problems of this format, but working fine.
I'm reading this NAL-units by programmatically parsing Packet bytes for NAL-units, finding the needed one, and reading data from it, as normal methods of working with side_data is not usable in my case.
Now, I need to be able to create such streams by myself for testing purposes, so I'm writing script to convert any mp4 (h264) file into file with such NAL-units.
Solution is simple: demux, add NAL-unit to package, mux to new stream.
But: I cannot add NAL-unit to package as it size is fixed.
So, I need to have function grow on Packet class, what it implementing existing ffmpeg functionality.
So, pyav should just expose function Packet.grow(self, grow_by: int) what would do the trick.
Example:
# open source and destination fileswithav.open("source.mp4", "r") assrc_container:
withav.open("dest.mp4", "w") asdest_container:
# create video stream for destination filenew_stream=dest_container.add_stream(template=src_container.streams.video[0])
# walking through the packetsforpacketinsrc_container.demux(container.streams.video[0]):
# changing packet streampacket.stream=new_stream# enlarging package by 16 bytes (the size of new NAL-unit)packet.grow(16)
# appending packege with new NAL-unit, hardcoded for simplicity, actually would be generatedpacket.update(bytes(packet) +b"\0\0\0\0\0\0\1\0\6\6\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"# muxing packetdest_container.mux(packet)
Investigation
I've written small snippet on C++ with using av_grow_packet, and it worked, but I don't have enough knowledge to solve many problems that arise in C++, and doesn't in your wonderful python library
I'm going to fork your repo, and try to create this functionality by myself, as I'm already need it, maybe you can tell me what pitfalls should I avoid, especially considering that I have never written on Pyrex yet :)
The text was updated successfully, but these errors were encountered:
Update: I've managed to work around this problem. There are no av_grop_packet function exported, but I can create new packet from old packet's data.
So, my code is:
# open source and destination fileswithav.open("source.mp4", "r") assrc_container:
withav.open("dest.mp4", "w") asdest_container:
# create video stream for destination filenew_stream=dest_container.add_stream(template=src_container.streams.video[0])
# walking through the packetsforpacketinsrc_container.demux(container.streams.video[0]):
# this is NALu I want to add:nalu=b"\0\0\0\0\0\0\1\0\6\6\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"# creating new packet new_packet=av.Packet(input=bytes(packet) +nalu)
# copy some fields values to new packet:forfieldin ["pts", "dts", "time_base"]:
setattr(new_packet, field, getattr(packet, field))
new_packet.stream=new_stream# muxing packetdest_container.mux(new_packet)
I have some problems with NALu format, and first key frame didn't go to the resulting file, but at first sight this method is working.
The Grow method would be needed to make this operations faster, as creating new packets in python would be quite slow
Overview
I'm working with video streams from a hardware device, which adding SEI NAL-units with specific data, in slightly malformed format.
ffmpeg complains about some problems of this format, but working fine.
I'm reading this NAL-units by programmatically parsing Packet bytes for NAL-units, finding the needed one, and reading data from it, as normal methods of working with side_data is not usable in my case.
Now, I need to be able to create such streams by myself for testing purposes, so I'm writing script to convert any mp4 (h264) file into file with such NAL-units.
Solution is simple: demux, add NAL-unit to package, mux to new stream.
But: I cannot add NAL-unit to package as it size is fixed.
So, I need to have function grow on Packet class, what it implementing existing ffmpeg functionality.
Existing FFmpeg API
ffmpeg has function av_grow_packet that can increase size of packet by specific amount:
https://ffmpeg.org/doxygen/trunk/group__lavc__packet.html#ga74f66e072998b8ce81ef3aba8d617a58
Expected PyAV API
So, pyav should just expose function
Packet.grow(self, grow_by: int)
what would do the trick.Example:
Investigation
I've written small snippet on C++ with using av_grow_packet, and it worked, but I don't have enough knowledge to solve many problems that arise in C++, and doesn't in your wonderful python library
Reproduction
nope
Versions
Additional context
I'm going to fork your repo, and try to create this functionality by myself, as I'm already need it, maybe you can tell me what pitfalls should I avoid, especially considering that I have never written on Pyrex yet :)
The text was updated successfully, but these errors were encountered: