fix: fail on hw frame
This commit is contained in:
parent
f37b399faa
commit
f900d96340
@ -3,7 +3,6 @@ use ffmpeg_sys_the_third::AVHWDeviceType::{
|
|||||||
AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_D3D12VA, AV_HWDEVICE_TYPE_MEDIACODEC,
|
AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_D3D12VA, AV_HWDEVICE_TYPE_MEDIACODEC,
|
||||||
AV_HWDEVICE_TYPE_OPENCL, AV_HWDEVICE_TYPE_VDPAU, AV_HWDEVICE_TYPE_VULKAN,
|
AV_HWDEVICE_TYPE_OPENCL, AV_HWDEVICE_TYPE_VDPAU, AV_HWDEVICE_TYPE_VULKAN,
|
||||||
};
|
};
|
||||||
use ffmpeg_sys_the_third::AVPixelFormat::AV_PIX_FMT_BGR24;
|
|
||||||
use ffmpeg_sys_the_third::{av_frame_free, av_packet_free, AVMediaType};
|
use ffmpeg_sys_the_third::{av_frame_free, av_packet_free, AVMediaType};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
18
src/lib.rs
18
src/lib.rs
@ -1,8 +1,5 @@
|
|||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use ffmpeg_sys_the_third::{
|
use ffmpeg_sys_the_third::{av_dict_set, av_frame_alloc, av_frame_free, av_hwframe_transfer_data, av_make_error_string, av_opt_next, av_opt_set, AVDictionary, AVFrame, AVOption, AV_OPT_SEARCH_CHILDREN};
|
||||||
av_dict_set, av_make_error_string, av_opt_next, av_opt_set, AVDictionary, AVOption,
|
|
||||||
AV_OPT_SEARCH_CHILDREN,
|
|
||||||
};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
@ -117,6 +114,19 @@ fn set_opts(ctx: *mut libc::c_void, options: HashMap<String, String>) -> Result<
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the frame as CPU frame
|
||||||
|
pub unsafe fn get_frame_from_hw(mut frame: *mut AVFrame) -> Result<*mut AVFrame, Error> {
|
||||||
|
if (*frame).hw_frames_ctx.is_null() {
|
||||||
|
Ok(frame)
|
||||||
|
} else {
|
||||||
|
let new_frame = av_frame_alloc();
|
||||||
|
let ret = av_hwframe_transfer_data(new_frame, frame, 0);
|
||||||
|
return_ffmpeg_error!(ret);
|
||||||
|
av_frame_free(&mut frame);
|
||||||
|
Ok(new_frame)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub use decode::*;
|
pub use decode::*;
|
||||||
pub use demux::*;
|
pub use demux::*;
|
||||||
pub use ffmpeg_sys_the_third;
|
pub use ffmpeg_sys_the_third;
|
||||||
|
@ -54,6 +54,9 @@ impl Resample {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn process_frame(&mut self, frame: *mut AVFrame) -> Result<*mut AVFrame, Error> {
|
pub unsafe fn process_frame(&mut self, frame: *mut AVFrame) -> Result<*mut AVFrame, Error> {
|
||||||
|
if !(*frame).hw_frames_ctx.is_null() {
|
||||||
|
anyhow::bail!("Hardware frames are not supported in this software re-sampler");
|
||||||
|
}
|
||||||
self.setup_swr(frame)?;
|
self.setup_swr(frame)?;
|
||||||
|
|
||||||
let mut out_frame = av_frame_alloc();
|
let mut out_frame = av_frame_alloc();
|
||||||
|
@ -80,6 +80,10 @@ impl Scaler {
|
|||||||
width: u16,
|
width: u16,
|
||||||
height: u16,
|
height: u16,
|
||||||
) -> Result<*mut AVFrame, Error> {
|
) -> Result<*mut AVFrame, Error> {
|
||||||
|
if !(*frame).hw_frames_ctx.is_null() {
|
||||||
|
anyhow::bail!("Hardware frames are not supported in this software scalar");
|
||||||
|
}
|
||||||
|
|
||||||
self.setup_scaler(frame, width, height)?;
|
self.setup_scaler(frame, width, height)?;
|
||||||
|
|
||||||
let dst_frame = av_frame_alloc();
|
let dst_frame = av_frame_alloc();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user