Skip to content

Commit

Permalink
Fix schema to match actually retrieved media info
Browse files Browse the repository at this point in the history
 - Fix import some FFmpeg constants instead of directly using values
  • Loading branch information
HeavenVolkoff committed Apr 20, 2024
1 parent 25aec73 commit 1bad9f1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
10 changes: 7 additions & 3 deletions core/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ model MediaChapter {
start BigInt?
end BigInt?
time_base_den Int
time_base_num Int
metadata MediaMetadata @relation(fields: [metadata_id], references: [id], onDelete: Cascade)
metadata_id Int @unique
Expand Down Expand Up @@ -353,7 +356,8 @@ model MediaStream {
model MediaCodec {
id Int @id @default(autoincrement())
type String?
kind String?
subkind String?
tag String?
name String?
profile String?
Expand Down Expand Up @@ -383,8 +387,8 @@ model MediaVideoProps {
color_transfer String?
field_order String?
chroma_location String?
coded_width Int?
coded_height Int?
width Int?
height Int?
aspect_ratio_num Int?
aspect_ratio_Den Int?
properties String
Expand Down
9 changes: 5 additions & 4 deletions crates/ffmpeg/src/codec_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use ffmpeg_sys_next::{
avcodec_parameters_to_context, avcodec_profile_name, AVBPrint, AVChromaLocation,
AVCodecContext, AVCodecParameters, AVColorPrimaries, AVColorRange, AVColorSpace,
AVColorTransferCharacteristic, AVFieldOrder, AVMediaType, AVPixelFormat, AVRational,
AVSampleFormat, AV_FOURCC_MAX_STRING_SIZE,
AVSampleFormat, AV_FOURCC_MAX_STRING_SIZE, FF_CODEC_PROPERTY_CLOSED_CAPTIONS,
FF_CODEC_PROPERTY_FILM_GRAIN, FF_CODEC_PROPERTY_LOSSLESS,
};
use libc::ENOMEM;

Expand Down Expand Up @@ -257,13 +258,13 @@ impl FFmpegCodecContext {
};

let mut properties = vec![];
if ctx.properties & 0x00000001 /*FF_CODEC_PROPERTY_LOSSLESS*/ != 0 {
if ctx.properties & (FF_CODEC_PROPERTY_LOSSLESS as u32) != 0 {
properties.push("Closed Captions".to_string());
}
if ctx.properties & 0x00000002 /*FF_CODEC_PROPERTY_CLOSED_CAPTIONS*/ != 0 {
if ctx.properties & (FF_CODEC_PROPERTY_CLOSED_CAPTIONS as u32) != 0 {
properties.push("Film Grain".to_string());
}
if ctx.properties & 0x00000004 /*FF_CODEC_PROPERTY_FILM_GRAIN*/ != 0 {
if ctx.properties & (FF_CODEC_PROPERTY_FILM_GRAIN as u32) != 0 {
properties.push("lossless".to_string());
}

Expand Down
22 changes: 12 additions & 10 deletions crates/ffmpeg/src/format_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::{
};

use ffmpeg_sys_next::{
av_cmp_q, av_q2d, av_reduce, avformat_close_input, avformat_find_stream_info,
avformat_open_input, AVFormatContext, AVRational, AV_DISPOSITION_ATTACHED_PIC,
AV_DISPOSITION_CAPTIONS, AV_DISPOSITION_CLEAN_EFFECTS, AV_DISPOSITION_COMMENT,
AV_DISPOSITION_DEFAULT, AV_DISPOSITION_DEPENDENT, AV_DISPOSITION_DESCRIPTIONS,
AV_DISPOSITION_DUB, AV_DISPOSITION_FORCED, AV_DISPOSITION_HEARING_IMPAIRED,
AV_DISPOSITION_KARAOKE, AV_DISPOSITION_LYRICS, AV_DISPOSITION_METADATA,
AV_DISPOSITION_NON_DIEGETIC, AV_DISPOSITION_ORIGINAL, AV_DISPOSITION_STILL_IMAGE,
AV_DISPOSITION_TIMED_THUMBNAILS, AV_DISPOSITION_VISUAL_IMPAIRED, AV_NOPTS_VALUE, AV_TIME_BASE,
av_cmp_q, av_reduce, avformat_close_input, avformat_find_stream_info, avformat_open_input,
AVFormatContext, AVRational, AV_DISPOSITION_ATTACHED_PIC, AV_DISPOSITION_CAPTIONS,
AV_DISPOSITION_CLEAN_EFFECTS, AV_DISPOSITION_COMMENT, AV_DISPOSITION_DEFAULT,
AV_DISPOSITION_DEPENDENT, AV_DISPOSITION_DESCRIPTIONS, AV_DISPOSITION_DUB,
AV_DISPOSITION_FORCED, AV_DISPOSITION_HEARING_IMPAIRED, AV_DISPOSITION_KARAOKE,
AV_DISPOSITION_LYRICS, AV_DISPOSITION_METADATA, AV_DISPOSITION_NON_DIEGETIC,
AV_DISPOSITION_ORIGINAL, AV_DISPOSITION_STILL_IMAGE, AV_DISPOSITION_TIMED_THUMBNAILS,
AV_DISPOSITION_VISUAL_IMPAIRED, AV_NOPTS_VALUE, AV_TIME_BASE,
};

use std::{
Expand Down Expand Up @@ -126,8 +126,10 @@ impl FFmpegFormatContext {
unsafe { chapters.offset(id as isize).as_ref() }.map(|chapter| {
MediaChapter {
id,
start: chapter.start as f64 * unsafe { av_q2d(chapter.time_base) },
end: chapter.end as f64 * unsafe { av_q2d(chapter.time_base) },
start: chapter.start,
end: chapter.end,
time_base_num: chapter.time_base.num,
time_base_den: chapter.time_base.den,
metadata: FFmpegDict::new(Some(chapter.metadata)).into(),
}
})
Expand Down
8 changes: 5 additions & 3 deletions crates/ffmpeg/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ pub struct MediaMetadata {

pub struct MediaChapter {
pub id: u32,
pub start: f64,
pub end: f64,
pub start: i64,
pub end: i64,
pub time_base_den: i32,
pub time_base_num: i32,
pub metadata: MediaMetadata,
}

Expand Down Expand Up @@ -73,9 +75,9 @@ pub enum Props {
pub struct MediaCodec {
pub kind: Option<String>,
pub subkind: Option<String>,
pub tag: Option<String>,
pub name: Option<String>,
pub profile: Option<String>,
pub tag: Option<String>,
pub bit_rate: Option<i64>,
pub props: Option<Props>,
}
Expand Down

0 comments on commit 1bad9f1

Please sign in to comment.