rust-ffmpeg
rust-ffmpeg copied to clipboard
Could not find tag for codec pcm_s16be in stream #1
I'm trying to modify a data track in mp4 file. I followed the remux example and have the following code.
The input mp4 is taken from a sony camera. The output is also mp4.
Running this function gives: Could not find tag for codec pcm_s16be in stream #1, codec not currently supported in container
I'm using macOS 12.5, ffmpeg 4.4.2
Thanks for the help!
fn pure_copy(original_path: &str, output_path: &str) -> std::io::Result<bool>{
use ffmpeg_next::{media, encoder, codec};
ffmpeg_next::init()?;
let mut input = ffmpeg_next::format::input(&original_path)?;
let mut output = ffmpeg_next::format::output(&output_path)?;
let mut stream_mapping = vec![0; input.nb_streams() as _];
let mut time_bases = vec![ffmpeg_next::Rational(0, 1); input.nb_streams() as _];
let mut ost_index = 0;
for (i, stream) in input.streams().enumerate() {
let medium = stream.parameters().medium();
stream_mapping[i] = -1;
if medium != media::Type::Video && medium != media::Type::Audio && medium != media::Type::Data {
continue;
}
if medium == media::Type::Data {
//pcm not supported
continue;
}
stream_mapping[i] = ost_index;
time_bases[i] = stream.time_base();
ost_index += 1;
let mut ost = output.add_stream(encoder::find(codec::Id::None))?;
let mut params = stream.parameters();
unsafe { (*params.as_mut_ptr()).codec_tag = 0; }
ost.set_parameters(params);
}
output.set_metadata(input.metadata().to_owned());
output.write_header()?;
for (stream, mut packet) in input.packets() {
let i = stream.index();
let j = stream_mapping[i];
if j == -1 {
continue;
}
let ost = output.stream(j as _).unwrap();
packet.rescale_ts(time_bases[i], ost.time_base());
packet.set_position(-1);
packet.set_stream(j as _);
packet.write_interleaved(&mut output)?;
}
output.write_trailer()?;
return Ok(true);
}