wip: actually set codec_opts to encoder
This commit is contained in:
parent
75600a85de
commit
6adf7401a5
@ -8,7 +8,7 @@ Audio transcoder with simple HTTP API. Work in progress.
|
|||||||
# How to Use
|
# How to Use
|
||||||
|
|
||||||
Transcoding can be done like this:
|
Transcoding can be done like this:
|
||||||
1. Use `cargo run` or [`neur0toxine/atranscoder-rpc`](https://hub.docker.com/r/neur0toxine/atranscoder-rpc/) Docker image.
|
1. Use [`neur0toxine/atranscoder-rpc`](https://hub.docker.com/r/neur0toxine/atranscoder-rpc/) Docker image.
|
||||||
2. Upload file for transcoding:
|
2. Upload file for transcoding:
|
||||||
```bash
|
```bash
|
||||||
curl --location 'http://localhost:8090/enqueue' \
|
curl --location 'http://localhost:8090/enqueue' \
|
||||||
|
@ -95,6 +95,7 @@ impl Task {
|
|||||||
&mut octx,
|
&mut octx,
|
||||||
TranscoderParams {
|
TranscoderParams {
|
||||||
codec: self.params.codec,
|
codec: self.params.codec,
|
||||||
|
codec_opts: self.params.codec_opts,
|
||||||
bit_rate: self.params.bit_rate,
|
bit_rate: self.params.bit_rate,
|
||||||
max_bit_rate: self.params.max_bit_rate,
|
max_bit_rate: self.params.max_bit_rate,
|
||||||
sample_rate: self.params.sample_rate,
|
sample_rate: self.params.sample_rate,
|
||||||
@ -248,10 +249,10 @@ fn upload_file<P: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn params_to_avdictionary(input: &str) -> Dictionary {
|
pub fn params_to_avdictionary(input: &str) -> Dictionary {
|
||||||
let mut dict: Dictionary = Dictionary::new();
|
let mut dict: Dictionary = Dictionary::new();
|
||||||
for pair in input.split(';') {
|
for pair in input.split(';') {
|
||||||
let mut parts = pair.split(':');
|
let mut parts = pair.split('=');
|
||||||
|
|
||||||
if let (Some(key), Some(value)) = (parts.next(), parts.next()) {
|
if let (Some(key), Some(value)) = (parts.next(), parts.next()) {
|
||||||
dict.set(key, value);
|
dict.set(key, value);
|
||||||
|
@ -43,7 +43,14 @@ impl Worker {
|
|||||||
let thread = thread::spawn(move || {
|
let thread = thread::spawn(move || {
|
||||||
ffmpeg_next::init()
|
ffmpeg_next::init()
|
||||||
.unwrap_or_else(|err| tracing::error!("couldn't init FFmpeg: {:?}", err));
|
.unwrap_or_else(|err| tracing::error!("couldn't init FFmpeg: {:?}", err));
|
||||||
ffmpeg_next::util::log::set_level(Level::Quiet);
|
|
||||||
|
ffmpeg_next::util::log::set_level(
|
||||||
|
if std::env::var("FFMPEG_VERBOSE").unwrap_or_default() == "1" {
|
||||||
|
Level::Trace
|
||||||
|
} else {
|
||||||
|
Level::Quiet
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let task = {
|
let task = {
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
extern crate ffmpeg_next as ffmpeg;
|
extern crate ffmpeg_next as ffmpeg;
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
use crate::task::params_to_avdictionary;
|
||||||
use ffmpeg::{codec, filter, format, frame, media};
|
use ffmpeg::{codec, filter, format, frame, media};
|
||||||
|
use ffmpeg_next::codec::Parameters;
|
||||||
use ffmpeg_next::error::EAGAIN;
|
use ffmpeg_next::error::EAGAIN;
|
||||||
|
use ffmpeg_next::Dictionary;
|
||||||
|
use tracing::log::debug;
|
||||||
|
|
||||||
pub struct Transcoder {
|
pub struct Transcoder {
|
||||||
pub(crate) stream: usize,
|
pub(crate) stream: usize,
|
||||||
@ -16,6 +21,7 @@ pub struct Transcoder {
|
|||||||
|
|
||||||
pub struct TranscoderParams {
|
pub struct TranscoderParams {
|
||||||
pub codec: String,
|
pub codec: String,
|
||||||
|
pub codec_opts: Option<String>,
|
||||||
pub bit_rate: usize,
|
pub bit_rate: usize,
|
||||||
pub max_bit_rate: usize,
|
pub max_bit_rate: usize,
|
||||||
pub sample_rate: i32,
|
pub sample_rate: i32,
|
||||||
@ -94,7 +100,11 @@ impl Transcoder {
|
|||||||
output.set_time_base((1, sample_rate));
|
output.set_time_base((1, sample_rate));
|
||||||
|
|
||||||
let in_time_base = decoder.time_base();
|
let in_time_base = decoder.time_base();
|
||||||
let encoder = encoder.open_as(codec)?;
|
let encoder = if let Some(codec_opts) = params.codec_opts {
|
||||||
|
encoder.open_as_with(codec, params_to_avdictionary(codec_opts.as_str()))?
|
||||||
|
} else {
|
||||||
|
encoder.open_as(codec)?
|
||||||
|
};
|
||||||
output.set_parameters(&encoder);
|
output.set_parameters(&encoder);
|
||||||
|
|
||||||
let filter = filter_graph("anull", &decoder, &encoder)?;
|
let filter = filter_graph("anull", &decoder, &encoder)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user