container.mux(...)
? I think start_encoding() is only run once on the first mux call to write file headers, so the audio stream won't get written into the file headers after that (which tallies up with the libavformat docs). However I've not actually tested that I'm afraid!
AudioFrame.from_ndarray
doesn't set the sample rate, try setting it directly after you create the frame, which is what the tests seem to do
I am having trouble installing PyAV.
$ pip install av
Collecting av
Using cached https://files.pythonhosted.org/packages/4d/fe/170a64b51c8f10df19fd2096388e51f377dfec07f0bd2f8d25ebdce6aa50/av-8.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-4yV5M1/av/setup.py", line 9, in <module>
from shlex import quote
ImportError: cannot import name quote
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4yV5M1/av/
copy
"dummy" codecContext? I'm opening a container with av.open(file="/dev/video0", format="v4l2", mode="r", options={"video_size": "1920x1080", "framerate": "30", "input_format": "h264"})
since RPi camera and Logitech C920 can give HW accelerated H264 stream, but then I have trouble working with the Packet object to bitstream over webRTC. Any clues?
ffmpeg -i book.m4b -f ffmetadata book.metadata.txt
). With pyav, I can see a data stream that has 56 'frames', but I'm uncertain how (or if) I can process that chapter info. Does anyone know if this is possible as things stand now?
$PYAV_PYTHON setup.py bdist_wheel
...
if __name__ == "__main__":
fh = open('video_bytes.bin', 'rb')
codec = av.CodecContext.create('h264', 'r')
while True:
chunk = fh.read(1 << 16)
packets = codec.parse(str(chunk))
print("Parsed {} packets from {} bytes:".format(len(packets), len(chunk)))
for packet in packets:
print(' ', packet)
frames = codec.decode(packet)
for frame in frames:
print(' ', frame)
chunk
directly, but parse complained that chunk
was not a str
packet.to_bytes()
) and to a stream container
in_cont = av.open(curr_tempfile.name, mode='r')
out_cont = av.open(output_tempfile.name, mode='w')
in_stream = in_cont.streams.audio[0]
out_stream = out_cont.add_stream(
codec_name=in_stream.codec_context.codec,
rate=audio_signal.sample_rate
)
graph = Graph()
fchain = [graph.add_abuffer(sample_rate=in_stream.rate,
format=in_stream.format.name, layout=in_stream.layout.name,
channels=audio_signal.num_channels)]
for _filter in filters:
fchain.append(_filter(graph))
fchain[-2].link_to(fchain[-1])
fchain.append(graph.add("abuffersink"))
fchain[-2].link_to(fchain[-1])
graph.configure()
for ifr in in_cont.decode(in_stream):
graph.push(ifr)
ofr = graph.pull()
ofr.pts = None
for p in out_stream.encode(ofr):
out_cont.mux(p)
out_cont.close()
filters
contains lambda functions of the format: lambda graph: graph.add("name_of_filter", "named_filter_arguments")
_filter
in filters
would be lambda graph: graph.add("tremolo", "f=15:d=.5")
I got a VideoFrame in yuvj420p
and I want to convert it to OpenCV Mat which is bgr24
.
<av.VideoFrame #3, pts=1920 yuvj420p 1920x1080 at 0x7f16f0aaf7c8>
Currently when I run frame.to_ndarray(format='bgr24')
I get deprecated pixel format used, make sure you did set range correctly
. Is there a proper way to convert to prevent this warning ?
I tried :
arr = frame.to_ndarray()
mat= cv2.cvtColor(arr, cv2.COLOR_YUV2BGR_I420)
But got ValueError: Conversion to numpy array with format yuvj420p is not yet supported
.
I know that I can use av.logging.Capture()
to catch the warning, but just wondering if there is a proper way to do the conversion ?
I'm trying to write a video containing audio using lossless codecs. I'm using "libx264rgb" for my video codec which works perfectly fine and as expected. However, I've been having trouble finding a compatible lossless audio codec.
I tried using "flac", but I got an error saying that that is an experimental feature:
> Traceback (most recent call last):
> File "/data/users/jbitton/fbsource/fbcode/buck-out/dev/gen/aml/ai_red_team/augmentations/tests/video_tests/pytorch_test#binary,link-tree/aml/ai_red_team/augmentations/tests/video_tests/pytorch_test.py", line 92, in test_compose_without_tensor
> audio_codec="flac",
> File "/data/users/jbitton/fbsource/fbcode/buck-out/dev/gen/aml/ai_red_team/augmentations/tests/video_tests/pytorch_test#binary,link-tree/torchvision/io/video.py", line 129, in write_video
> container.mux(packet)
> File "av/container/output.pyx", line 198, in av.container.output.OutputContainer.mux
> File "av/container/output.pyx", line 204, in av.container.output.OutputContainer.mux_one
> File "av/container/output.pyx", line 174, in av.container.output.OutputContainer.start_encoding
> File "av/container/core.pyx", line 180, in av.container.core.Container.err_check
> File "av/utils.pyx", line 107, in av.utils.err_check
> av.AVError: [Errno 733130664] Experimental feature: '/tmp/tmpbwvyrh3j/aug_pt_input_1.mp4' (16: mp4)
Additionally, I tried using "mp4als" which is a valid audio codec in ffmpeg, however PyAV raises an error saying it is an unknown codec.
Would appreciate any advice, thanks in advance!