I use h264 as encode codec, and got the error bellow, and I change this to be mpeg4 and it works well.
My os is ubuntu 20.04 and python is 3.9 and pip install BabitMF
[2023-09-25 03:08:33.274] [error] node id:1 Process node failed, will exit.
import io
import numpy as np
import bmf
from bmf import GraphMode, Module, Log, LogLevel, InputType, ProcessResult, Packet, Timestamp, scale_av_pts, av_time_base, BmfCallBackType, VideoFrame, AudioFrame, BMFAVPacket
from PIL import Image
def init_push_graph(output):
graph = bmf.graph({"dump_graph": 1, "loglevel": "debug"})
video_stream = graph.input_stream("video_stream")
# audio_stream = graph.input_stream("wav_stream")
decode_stream = video_stream.decode({
"loglevel": "trace",
's': '720:1280',
'pix_fmt': 'rgb24',
"push_raw_stream": 1,
"video_codec": "bmp",
"video_time_base": "1,30000"
})
bmf.encode(
decode_stream,
None,
{
"video_params": {
"codec": "h264",
"width": 720,
"height": 1280,
"max_fr": 30,
"crf": "23",
"preset": "veryfast"
},
# "audio_params": {"sample_rate": 44100, "codec": "aac"},
"loglevel": "trace",
"output_path": output
},
)
graph.run_wo_block(mode=GraphMode.PUSHDATA)
return graph
graph = init_push_graph('./test1.mp4')
pts = 0
timestamp = 0
for _ in range(100):
frame = np.zeros((1280, 720, 3), dtype=np.uint8)
image = Image.fromarray(frame, mode="RGB")
byte_stream = io.BytesIO()
image.save(byte_stream, format='BMP')
image_bytes = byte_stream.getvalue()
pkt = BMFAVPacket(len(image_bytes))
memview = pkt.data.numpy()
memview[:] = np.frombuffer(image_bytes, dtype=np.uint8)
pkt.pts = pts
packet = Packet(pkt)
packet.timestamp = timestamp
pts += 1001
timestamp += 1
graph.fill_packet("video_stream", packet)
graph.fill_packet("video_stream", Packet.generate_eof_packet())
graph.close()