Skip to content

Commit aee2549

Browse files
committed
fixed bitstream filtering
1 parent 59c8b4b commit aee2549

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/lib.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,36 @@ fn process_bsf(
270270
debug!("Ingress packet count: {}", packets.len());
271271
let mut new_packets = Vec::new();
272272
for mut packet in packets.drain(..) {
273+
debug!("Source packet size: {}", packet.size());
273274
unsafe {
274275
if av_bsf_send_packet(filter.ptr, packet.as_mut_ptr()) < 0 {
275276
error!("Unable to send packet to bitstream filter");
276277
}
277278

278279
loop {
279-
let mut new_packet = Packet::new(packet.size() + 2048);
280-
let ret = av_bsf_receive_packet(filter.ptr, packet.as_mut_ptr());
281-
if ret < 0 {
280+
let mut new_packet = Packet::empty();
281+
let ret = av_bsf_receive_packet(filter.ptr, new_packet.as_mut_ptr());
282+
if ret == AVERROR(EAGAIN) {
283+
//debug!("Required extra packets");
284+
break;
285+
}
286+
if ret == AVERROR_EOF {
287+
error!("End of filter");
282288
break;
283289
}
284-
if ret == AVERROR(EAGAIN) || ret == AVERROR_EOF {
290+
if ret < 0 {
291+
error!("Unable to receive packet from bitstream filter: {}", ret);
285292
break;
286293
}
294+
debug!(
295+
"New packet size: {}",
296+
new_packet.data().as_ref().unwrap().len()
297+
);
287298
new_packet.set_stream(packet.stream());
288-
new_packet.set_flags(packet.flags());
289-
new_packet.set_dts(packet.dts());
290-
new_packet.set_pts(packet.pts());
291-
new_packet.set_duration(packet.duration());
299+
//new_packet.set_flags(packet.flags());
300+
// new_packet.set_dts(packet.dts());
301+
// new_packet.set_pts(packet.pts());
302+
// new_packet.set_duration(packet.duration());
292303
new_packets.push(new_packet.clone());
293304
}
294305
}

test.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def bytes_to_bits_binary(byte_data):
1212

1313
if __name__ == '__main__':
1414
# set env LOGLEVEL=info
15-
file = "/home/ivan/Downloads/1_underground_supercut_reencode_bug.mp4"
16-
# file = "/home/ivan/Downloads/1_underground_supercut.mp4"
15+
# file = "/dev/video0"
16+
file = "/home/ivan/Downloads/1_underground_supercut.mp4"
1717
# file = "/home/ivan/Downloads/1_underground_supercut_reencode_bug_x265.mp4"
1818
# file = "/home/ivan/Downloads/1_underground_supercut_reencode_bug_aud.mp4"
1919
s = FFMpegSource(file, params=[],
@@ -25,6 +25,7 @@ def bytes_to_bits_binary(byte_data):
2525
BsfFilter("h265", "hevc_mp4toannexb")])
2626
s.log_level = FFmpegLogLevel.Info
2727
# counter = 0
28+
f = open("output.h264", "wb")
2829
while True:
2930
try:
3031
p = s.video_frame()
@@ -35,6 +36,7 @@ def bytes_to_bits_binary(byte_data):
3536
print("Skipped frames because of queue overflow:", p.queue_full_skipped_count)
3637
# print("Is bytestream", p.is_byte_stream)
3738
payload = p.payload_as_bytes()
39+
f.write(payload)
3840
print("Payload length:", len(payload))
3941
# print 1st 3 bytes of the payload
4042
# bin_res = " ".join(format(x, '#010b')[2:] for x in payload[:16])

0 commit comments

Comments
 (0)