Skip to content

Commit

Permalink
vqa_demo: v3 port
Browse files Browse the repository at this point in the history
  • Loading branch information
HuHeng committed Jan 19, 2024
1 parent 1968b65 commit d0d9c66
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
56 changes: 29 additions & 27 deletions bmf/demo/video_quality_assessment/module_utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
else:
from queue import *
import bmf

#from module_utils.util import generate_out_packets

from bmf import VideoFrame
from bmf.lib._bmf.sdk import ffmpeg
import bmf.hml.hmp as mp

def generate_out_packets(packet, np_arr, out_fmt):
video_frame = bmf.VideoFrame.from_ndarray(np_arr, format=out_fmt)
video_frame.pts = packet.get_data().pts
video_frame.time_base = packet.get_data().time_base
rgbformat = mp.PixelInfo(mp.kPF_RGB24)
image = mp.Frame(mp.from_numpy(np_arr), rgbformat)
video_frame = VideoFrame(image)

video_frame.pts = packet.get(VideoFrame).pts
video_frame.time_base = packet.get(VideoFrame).time_base

pkt = bmf.Packet()
pkt.set_timestamp(packet.get_timestamp())
pkt.set_data(video_frame)
pkt = bmf.Packet(video_frame)
pkt.timestamp = packet.timestamp
return pkt


Expand All @@ -42,45 +44,45 @@ def __init__(self, node=None, nb_in=1, in_fmt='yuv420p', out_fmt='yuv420p'):
def process(self, task):
print(task.get_inputs().items(),'####',task.get_outputs().items())
input_queue = task.get_inputs()[0]
output_queue = task.get_outputs()[0]

while not input_queue.empty():
pkt = input_queue.get()
pkt_timestamp = pkt.get_timestamp()
pkt_data = pkt.get_data()
print('##',pkt_data)

pkt_timestamp = pkt.timestamp

if pkt_timestamp == bmf.Timestamp.EOF:
self._eof = True
for _ in range(self._margin_num):
self._in_packets.append(self._in_packets[-1])
self._frames.append(self._frames[-1])
self._consume()

# output_queue.put(bmf.Packet.generate_eof_packet())
task.set_timestamp(bmf.Timestamp.DONE)
return bmf.ProcessResult.OK

pkt_data = pkt.get(VideoFrame)
if pkt_data is not None:
self._in_packets.append(pkt)
self._frames.append(pkt.get_data().to_ndarray(format=self._in_fmt))
# self._frames.append(pkt.get(VideoFrame).to_ndarray(format=self._in_fmt))

self._frames.append(
ffmpeg.reformat(pkt.get(VideoFrame),
self._in_fmt).frame().plane(0).numpy())

# padding first frame.
if len(self._in_packets) == 1:
for _ in range(self._margin_num):
self._in_packets.append(self._in_packets[0])
self._frames.append(self._frames[0])

if self._eof:
#print(self._in_packets, self._frames)
# padding last frame.
for _ in range(self._margin_num):
self._in_packets.append(self._in_packets[-1])
self._frames.append(self._frames[-1])
self._consume(output_queue)

output_queue.put(bmf.Packet.generate_eof_packet())
task.set_timestamp(bmf.Timestamp.DONE)
self._consume()

return bmf.ProcessResult.OK

def _consume(self, output_queue):
def _consume(self, output_queue = None):
while len(self._in_packets) >= self._in_frame_num:
out_frame = self.core_process(self._frames[:self._in_frame_num])
out_packet = generate_out_packets(self._in_packets[self._out_frame_index], out_frame, self._out_fmt)
output_queue.put(out_packet)
self._in_packets.pop(0)
self._frames.pop(0)

Expand Down
4 changes: 2 additions & 2 deletions bmf/demo/video_quality_assessment/vqa_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def segment_decode_ticks(video_path, seg_dur=4.0, lv1_dur_thres=24.0, max_dur=10

if __name__=='__main__':
input_path='files/VD_0290_00405.png'
out_path='result/20f72ebc978c4b06830e23adee6b6ff7.json'
out_path='20f72ebc978c4b06830e23adee6b6ff7.json'

# check input path
if not os.path.exists(input_path):
Expand Down Expand Up @@ -89,7 +89,7 @@ def segment_decode_ticks(video_path, seg_dur=4.0, lv1_dur_thres=24.0, max_dur=10
py_entry = 'vqa_module.BMFVQA_4kpgc'
video_stream = streams['video'].module('vqa_4kpgc_module', option,
py_module_path, py_entry)
video_stream.upload().run()
video_stream.run()



Expand Down

0 comments on commit d0d9c66

Please sign in to comment.