Invalid PTS in (expected to be) automatic conditions.
Created by: StarForestInThePark
I'm trying to do open device both audio and video to output file mp4. here's what i'm trying to do:
#!/usr/bin/env python3
#-*-coding:utf-8-*-
import av
import itertools
#get video device and convert to packets.
def get_vpkts(device,driver):
v = av.open(device,'r',driver)
streams = next(s for s in v.streams if s.type == 'video')
pkts = next(p for p in v.demux(streams))
yield pkts
#get audio device and convert to packets.
def get_apkts(device,driver):
a = av.open(device,'r',driver)
streams = next(s for s in v.streams if s.type == 'audio')
pkts = next(p for p in a.demux(streams))
yield pkts
#error: trying to encoding but operation not permitted. why???
def encoding_frames(pkts,out_videostream,out_audiostream):
frames = next(f for f in pkts.decode())
if pkts.stream.type == 'video':
out_videostream.encode(frames)
if pkts.stream.type == 'audio':
out_audiostream.encode(frames)
if __name__ == '__main__':
try:
out = av.open('test.mp4','w')
out_videostream = out.add_stream("mpeg4",24)
out_audiostream = out.add_stream("mp3")
pkts = [
next(get_vpkts('/dev/video0','v4l2')
next(get_apkts('hw:1,0','alsa')
]
for pkt in itertools.cycle(pkts):
encode_frames(pkt,out_videostream,out_audiostream)
except KeyboardInterrupt:
out.close()
sys.exit(0)
and here's getting error:
Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
last message repeated 1 times
Invalid pts (251813) <= last (251813)
Traceback (most recent call last):
File "./test.py", line 43, in <module>
encode_frames(pkt,ovstream,oastream)
File "./test.py", line 26, in encode_frames
ovstream.encode(frames)
File "av/video/stream.pyx", line 86, in av.video.stream.VideoStream.encode (src/av/video/stream.c:2991)
File "av/video/stream.pyx", line 147, in av.video.stream.VideoStream.encode (src/av/video/stream.c:2681)
File "av/utils.pyx", line 78, in av.utils.err_check (src/av/utils.c:1749)
av.AVError: [Errno 1] Operation not permitted
using raspbian (raspberry pi 3 model b+ armv7l)
maybe i'm doing wrong with using av module. any suggestion for muxing frame??
ps: sorry for code is too long. BTW.