Skip to content

Commit 2448ae7

Browse files
committed
code update
1 parent 6e56c1d commit 2448ae7

File tree

10 files changed

+41
-107
lines changed

10 files changed

+41
-107
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,28 @@ permissions:
2121

2222
jobs:
2323
linux:
24-
runs-on: ubuntu-latest
2524
strategy:
2625
matrix:
2726
include:
2827
- docker_file: docker/Dockerfile.manylinux_2_28_ARM64
2928
name: manylinux-arm
3029
arch: linux/arm64
30+
runner: ARM64
3131
- docker_file: docker/Dockerfile.manylinux_2_28_X64
3232
name: manylinux-x86
3333
arch: linux/amd64
34-
- docker_file: docker/Dockerfile.u2004
34+
runner: X86
35+
- docker_file: docker/Dockerfile.u2204
3536
name: native-arm
3637
arch: linux/arm64
37-
- docker_file: docker/Dockerfile.u2004
38+
runner: ARM64
39+
- docker_file: docker/Dockerfile.u2204
3840
name: native-x86
3941
arch: linux/amd64
40-
42+
runner: X86
43+
runs-on:
44+
- self-hosted
45+
- ${{ matrix.runner }}
4146
steps:
4247
- uses: actions/checkout@v3
4348

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repository = "https://github.com/insight-platform/FFmpeg-Input"
77
readme = "README.md"
88
keywords = ["FFmpeg", "Video"]
99
categories = ["computer-vision"]
10-
version = "0.1.21"
10+
version = "0.1.22"
1111
edition = "2021"
1212
license="Apache-2.0"
1313
rust-version = "1.62"
@@ -18,19 +18,20 @@ crate-type = ["cdylib", "lib"]
1818
[dependencies]
1919
crossbeam = "0.8"
2020
log = "0.4"
21-
env_logger = "0.10"
21+
env_logger = "0.11"
22+
parking_lot = "0.12"
2223

2324
[dependencies.ffmpeg-next]
24-
git = "https://github.com/insight-platform/rust-ffmpeg.git"
25-
branch = "master"
25+
version = "6"
2626
features = ["default"]
2727

2828
[dependencies.pyo3]
29-
version = "0.19"
29+
version = "0.20"
3030
features = ["extension-module"]
3131

32+
[build-dependencies]
33+
pyo3-build-config = { version = "0.20"}
34+
3235
[profile.release]
3336
opt-level = 3
34-
35-
[features]
36-
rpi = ["ffmpeg-next/rpi"]
37+
codegen-units = 1

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
pyo3_build_config::add_extension_module_link_args();
3+
}

docker/Dockerfile.manylinux_2_28_ARM64

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
FROM quay.io/pypa/manylinux_2_28_aarch64 as base
1+
FROM ghcr.io/insight-platform/manylinux_2_28_arm64:v0.0.3 as builder
22

3-
RUN dnf install -y epel-release
4-
# RUN dnf config-manager --set-enabled crb
5-
RUN dnf install -y --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
6-
RUN dnf install -y --nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm
7-
RUN dnf install -y ffmpeg ffmpeg-devel
8-
RUN dnf install -y clang clang-devel
9-
ENV PATH="/root/.cargo/bin:/opt/python/cp37-cp37m/bin:/opt/python/cp38-cp38/bin:/opt/python/cp39-cp39/bin:/opt/python/cp310-cp310/bin:/opt/python/cp311-cp311/bin:/opt/python/cp312-cp312/bin:$PATH"
10-
RUN pip3 install maturin==0.15 patchelf cffi ziglang sccache>=0.4.0
11-
12-
WORKDIR /opt
13-
COPY docker/install-basic-deps-manylinux.sh .
14-
RUN bash /opt/install-basic-deps-manylinux.sh
15-
16-
FROM base as chef
17-
ENV PATH="/root/.cargo/bin:$PATH"
18-
RUN rustc -V
19-
20-
FROM chef AS planner
21-
WORKDIR /opt
22-
COPY . .
23-
RUN cargo chef prepare --recipe-path recipe.json
24-
25-
FROM chef AS builder
263
WORKDIR /opt
27-
COPY --from=planner /opt/recipe.json recipe.json
28-
RUN cargo chef cook --release --recipe-path recipe.json
294
COPY . .
305
ENV LD_LIBRARY_PATH="/usr/lib64/pulseaudio:$LD_LIBRARY_PATH"
316
ARG PYTHON_INTERPRETER

docker/Dockerfile.manylinux_2_28_X64

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
FROM quay.io/pypa/manylinux_2_28_x86_64 as base
1+
FROM ghcr.io/insight-platform/manylinux_2_28_x64:v0.0.3 as builder
22

3-
RUN dnf install -y epel-release
4-
# RUN dnf config-manager --set-enabled crb
5-
RUN dnf install -y --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
6-
RUN dnf install -y --nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm
7-
RUN dnf install -y ffmpeg ffmpeg-devel
8-
RUN dnf install -y clang clang-devel
9-
ENV PATH="/root/.cargo/bin:/opt/python/cp37-cp37m/bin:/opt/python/cp38-cp38/bin:/opt/python/cp39-cp39/bin:/opt/python/cp310-cp310/bin:/opt/python/cp311-cp311/bin:/opt/python/cp312-cp312/bin:$PATH"
10-
RUN pip3 install maturin==0.15 patchelf cffi ziglang sccache>=0.4.0
11-
12-
WORKDIR /opt
13-
COPY docker/install-basic-deps-manylinux.sh .
14-
RUN bash /opt/install-basic-deps-manylinux.sh
15-
16-
FROM base as chef
17-
ENV PATH="/root/.cargo/bin:$PATH"
18-
RUN rustc -V
19-
20-
FROM chef AS planner
21-
WORKDIR /opt
22-
COPY . .
23-
RUN cargo chef prepare --recipe-path recipe.json
24-
25-
FROM chef AS builder
263
WORKDIR /opt
27-
COPY --from=planner /opt/recipe.json recipe.json
28-
RUN cargo chef cook --release --recipe-path recipe.json
294
COPY . .
305
ENV LD_LIBRARY_PATH="/usr/lib64/pulseaudio:$LD_LIBRARY_PATH"
316
ARG PYTHON_INTERPRETER

docker/Dockerfile.u2004 renamed to docker/Dockerfile.u2204

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM ubuntu:20.04 as base
1+
FROM ubuntu:22.04 as base
22

33
WORKDIR /opt
4-
COPY docker/install-basic-deps-u2004.sh .
5-
RUN bash /opt/install-basic-deps-u2004.sh
4+
COPY docker/install-basic-deps-u2204.sh .
5+
RUN bash /opt/install-basic-deps-u2204.sh
66

77
FROM base as chef
88
ENV PATH="/root/.cargo/bin:$PATH"

docker/install-basic-deps-manylinux.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.
File renamed without changes.

src/lib.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ use ffmpeg_next::format::{input_with_dictionary, Pixel};
66
use ffmpeg_next::log::Level;
77
use ffmpeg_next::software::converter;
88
use log::{debug, error, info, warn};
9+
use parking_lot::Mutex;
910
use pyo3::exceptions::PyBrokenPipeError;
1011
use pyo3::prelude::*;
1112
use pyo3::types::PyBytes;
1213
use std::collections::HashMap;
1314
use std::path::Path;
14-
use std::sync::{Arc, Mutex};
15+
use std::sync::Arc;
1516
use std::thread::{spawn, JoinHandle};
1617
use std::time::SystemTime;
1718

@@ -123,10 +124,7 @@ pub struct FFMpegSource {
123124
impl Drop for FFMpegSource {
124125
fn drop(&mut self) {
125126
{
126-
let mut exit_signal = self
127-
.exit_signal
128-
.lock()
129-
.expect("Exit mutex must be always locked without problems");
127+
let mut exit_signal = self.exit_signal.lock();
130128
*exit_signal = true;
131129
}
132130
let t = self.thread.take();
@@ -145,10 +143,7 @@ fn handle(
145143
) {
146144
let mut queue_full_skipped_count = 0;
147145
ffmpeg::init().expect("FFmpeg initialization must be successful");
148-
let ll = log_level
149-
.lock()
150-
.expect("Log level mutex must always be available")
151-
.take();
146+
let ll = log_level.lock().take();
152147

153148
if let Some(l) = ll {
154149
info!("Setting log level to {:?}", l);
@@ -206,13 +201,10 @@ fn handle(
206201

207202
let mut skip_until_first_key_frame = true;
208203
for (stream, packet) in ictx.packets() {
209-
if *signal.lock().expect("Mutex is poisoned. Critical error.") {
204+
if *signal.lock() {
210205
break;
211206
}
212-
let ll = log_level
213-
.lock()
214-
.expect("Log level mutex must always be available")
215-
.take();
207+
let ll = log_level.lock().take();
216208

217209
if let Some(l) = ll {
218210
info!("Setting log level to {:?}", l);
@@ -416,11 +408,7 @@ impl FFMpegSource {
416408

417409
#[setter]
418410
pub fn log_level(&self, ffmpeg_log_level: FFmpegLogLevel) {
419-
let mut ll = self
420-
.log_level
421-
.lock()
422-
.expect("Log Level mutex must be available");
423-
411+
let mut ll = self.log_level.lock();
424412
*ll = Some(assign_log_level(ffmpeg_log_level));
425413
}
426414
}

test_decode.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55

66
if __name__ == '__main__':
77
s = FFMpegSource("/dev/video0",
8-
params={"video_size": "1280x720", "c:v": "v4l2m2m", "input_format": "mjpeg"},
8+
params={"video_size": "1920x1080", "c:v": "v4l2m2m", "input_format": "mjpeg"},
99
queue_len=100,
10-
decode=True,
10+
decode=False,
1111
ffmpeg_log_level=FFmpegLogLevel.Info)
1212
s.log_level = FFmpegLogLevel.Panic
1313
while True:
1414
try:
1515
p = s.video_frame()
1616
res = p.payload_as_bytes()
1717
# 1944 2592
18-
print(p.frame_height, p.frame_width)
19-
res = np.frombuffer(res, dtype=np.uint8)
20-
res = np.reshape(res, (p.frame_height, p.frame_width, 3))
18+
#print(p.frame_height, p.frame_width)
19+
#res = np.frombuffer(res, dtype=np.uint8)
20+
#res = np.reshape(res, (p.frame_height, p.frame_width, 3))
2121
end = time.time()
2222
print(p.codec, p.pixel_format, p.queue_len, "all_time={}".format(int(end * 1000 - p.frame_received_ts)),
2323
"python_time={}".format(int(end * 1000 - p.frame_processed_ts)))
24-
cv2.imshow('Image', res)
25-
if cv2.waitKey(1) & 0xFF == ord('q'):
26-
break
24+
# cv2.imshow('Image', res)
25+
#if cv2.waitKey(1) & 0xFF == ord('q'):
26+
# break
2727
except BrokenPipeError:
2828
print("EOS")
2929
break

0 commit comments

Comments
 (0)