Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use packed bigarray in ffmpeg swscale calls. #4183

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
(dssi (< 0.1.3))
(faad (< 0.5.0))
(fdkaac (< 0.3.1))
(ffmpeg (< 1.2.0))
(ffmpeg-avutil (< 1.2.0))
(ffmpeg (< 1.2.1))
(ffmpeg-avutil (< 1.2.1))
(flac (< 0.3.0))
(frei0r (< 0.1.0))
(inotify (< 1.0))
Expand Down
4 changes: 2 additions & 2 deletions liquidsoap-core.opam
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ conflicts: [
"dssi" {< "0.1.3"}
"faad" {< "0.5.0"}
"fdkaac" {< "0.3.1"}
"ffmpeg" {< "1.2.0"}
"ffmpeg-avutil" {< "1.2.0"}
"ffmpeg" {< "1.2.1"}
"ffmpeg-avutil" {< "1.2.1"}
"flac" {< "0.3.0"}
"frei0r" {< "0.1.0"}
"inotify" {< "1.0"}
Expand Down
2 changes: 1 addition & 1 deletion src/core/builtins/builtins_ffmpeg_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let ffmpeg_raw_decode =
module InternalResampler =
Swresample.Make (Swresample.Frame) (Swresample.PlanarFloatArray)

module InternalScaler = Swscale.Make (Swscale.Frame) (Swscale.BigArray)
module InternalScaler = Swscale.Make (Swscale.Frame) (Swscale.PackedBigArray)

let log = Log.make ["ffmpeg"; "internal"; "decoder"]

Expand Down
2 changes: 1 addition & 1 deletion src/core/builtins/builtins_ffmpeg_encoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let ffmpeg_raw_encode =
module InternalResampler =
Swresample.Make (Swresample.PlanarFloatArray) (Swresample.Frame)

module InternalScaler = Swscale.Make (Swscale.BigArray) (Swscale.Frame)
module InternalScaler = Swscale.Make (Swscale.PackedBigArray) (Swscale.Frame)

type source_idx = { source : Source.source; idx : int64 }

Expand Down
2 changes: 1 addition & 1 deletion src/core/decoder/ffmpeg_internal_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Converter_pcm_f32 = struct
include ConverterInput (Swresample.FltPlanarBigArray)
end

module Scaler = Swscale.Make (Swscale.Frame) (Swscale.BigArray)
module Scaler = Swscale.Make (Swscale.Frame) (Swscale.PackedBigArray)

let mk_audio_decoder ~channels ~stream ~field ~pcm_kind codec =
let converter =
Expand Down
2 changes: 1 addition & 1 deletion src/core/decoder/image/ffmpeg_image_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*****************************************************************************)

module Scaler = Swscale.Make (Swscale.Frame) (Swscale.BigArray)
module Scaler = Swscale.Make (Swscale.Frame) (Swscale.PackedBigArray)

let log = Log.make ["decoder"; "ffmpeg"; "image"]

Expand Down
2 changes: 1 addition & 1 deletion src/core/encoder/encoders/ffmpeg_internal_encoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module InternalResampler_pcm_f32 = struct
end

module RawResampler = Swresample.Make (Swresample.Frame) (Swresample.Frame)
module InternalScaler = Swscale.Make (Swscale.BigArray) (Swscale.Frame)
module InternalScaler = Swscale.Make (Swscale.PackedBigArray) (Swscale.Frame)
module RawScaler = Swscale.Make (Swscale.Frame) (Swscale.Frame)

let log = Log.make ["ffmpeg"; "encoder"; "internal"]
Expand Down
38 changes: 35 additions & 3 deletions src/core/tools/ffmpeg_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,47 @@ let pack_image f =
let y, u, v = Image.YUV420.data f in
let sy = Image.YUV420.y_stride f in
let s = Image.YUV420.uv_stride f in
[| (y, sy); (u, s); (v, s) |]
{
Swscale.PackedBigArray.data;
planes =
[|
{ plane_size = Image.Data.length y; stride = sy };
{ plane_size = Image.Data.length u; stride = s };
{ plane_size = Image.Data.length v; stride = s };
|];
}

let unpack_image ~width ~height = function
| [| (y, sy); (u, su); (v, sv) |] ->
| {
Swscale.PackedBigArray.data;
planes =
[|
{ plane_size = y_len; stride = sy };
{ plane_size = u_len; stride = su };
{ plane_size = v_len; stride = sv };
|];
} ->
assert (su = sv);
let y = Image.Data.sub data 0 y_len in
let u = Image.Data.sub data y_len u_len in
let v = Image.Data.sub data (y_len + u_len) v_len in
Image.YUV420.make width height y sy u v su
| [| (y, sy); (u, su); (v, sv); (alpha, sa) |] ->
| {
Swscale.PackedBigArray.data;
planes =
[|
{ plane_size = y_len; stride = sy };
{ plane_size = u_len; stride = su };
{ plane_size = v_len; stride = sv };
{ plane_size = alpha_len; stride = sa };
|];
} ->
assert (su = sv);
assert (sa = sy);
let y = Image.Data.sub data 0 y_len in
let u = Image.Data.sub data y_len u_len in
let v = Image.Data.sub data (y_len + u_len) v_len in
let alpha = Image.Data.sub data (y_len + u_len + v_len) alpha_len in
Image.YUV420.make width height ~alpha y sy u v su
| _ -> assert false

Expand Down
4 changes: 2 additions & 2 deletions src/core/tools/ffmpeg_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ val liq_video_sample_time_base : unit -> Avutil.rational
val liq_frame_time_base : unit -> Avutil.rational
val liq_frame_pixel_format : unit -> Avutil.Pixel_format.t
val pixel_format : 'a Avcodec.Video.t -> string option -> Avutil.Pixel_format.t
val pack_image : Image.YUV420.t -> (Image.Data.t * int) array
val pack_image : Image.YUV420.t -> Swscale.PackedBigArray.t

val unpack_image :
width:int -> height:int -> (Image.Data.t * int) array -> Image.YUV420.t
width:int -> height:int -> Swscale.PackedBigArray.t -> Image.YUV420.t

val convert_time_base :
src:Avutil.rational -> dst:Avutil.rational -> int64 -> int64
Expand Down
Loading