JuliaIO / VideoIO.jl

Reading and writing of video files in Julia via ffmpeg
https://juliaio.github.io/VideoIO.jl/stable
Other
128 stars 53 forks source link

Video all mangled up on Windows with codec libx264rgb #295

Closed Ezequiel92 closed 3 years ago

Ezequiel92 commented 3 years ago

When using the codec libx264rgb on Windows, as recommended in the warning

Warning: Encoding output not lossless.
│ libx264 does not support lossless RGB planes. RGB will be downsampled     
│ to lossy YUV420P. To encode lossless RGB use codec_name="libx264rgb"

from using "crf"=0 to make a video from a bunch of frames, the result is completely distorted. This happen in MP4 and MOV.

Using this MWE

using Plots, VideoIO, Glob, FileIO

for i in 1:10
    plot(rand(10))
    savefig("images_" * string(i) * ".png")
end

imgstack = []
for image in glob("images_*.png")
    push!(imgstack, load(image))
end

props = [:priv_data => ("crf" => "0", "preset" => "ultrafast")]
encodevideo("good.mov", 
            imgstack, 
            framerate=2, 
            AVCodecContextProperties=props)

encodevideo("bad.mov", 
            imgstack, 
            framerate=2, 
            codec_name="libx264rgb",
            AVCodecContextProperties=props)

One gets good.mov which is perfectly fine as one would expect:

good

And bad.mov which is all distorted:

bad

Note: I would've uploaded the actual videos, now that GitHub allows that, but for some reason it said that the files were corrupted even though the reproduce just fine in my machine (both good and bad and both as mp4 and mov).

Versions

From julia> versioninfo()

Julia Version 1.5.3 
Commit 788b2c77c1 (2020-11-09 13:37 UTC) 
Platform Info: 
  OS: Windows (x86_64-w64-mingw32) 
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz 
  WORD_SIZE: 64 
  LIBM: libopenlibm 
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake) 

From (@v1.5) pkg> status

[5789e2e9] FileIO v1.4.4
[c27321d9] Glob v1.3.0
[82e4d734] ImageIO v0.4.0
[91a5bcdd] Plots v1.9.1
[d6d074c3] VideoIO v0.8.4

From (@v1.5) pkg> st -m

[c87230d0] FFMPEG v0.3.0
[b22a6f82] FFMPEG_jll v4.3.1+4
[1270edf5] x264_jll v2020.7.14+2
[dfaa095f] x265_jll v3.0.0+3
Ezequiel92 commented 3 years ago

With the last version, and the MWE updated to the new API,

using Plots, VideoIO, Glob, FileIO

for i in 1:10
    plot(rand(10))
    savefig("images_" * string(i) * ".png")
end

imgstack = []
for image in glob("images_*.png")
    push!(imgstack, load(image))
end

encoder_options = (crf = "0", preset = "ultrafast")
VideoIO.save("good.mov", 
            imgstack, 
            framerate=2;
            encoder_options)

VideoIO.save("bad.mov", 
            imgstack, 
            framerate=2, 
            codec_name="libx264rgb";
            encoder_options)

the problem seems to be fixed, so I'll be closing this issue.

Versions

From julia> versioninfo()

Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  WORD_SIZE: 64    
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =

From (@v1.6) pkg> st

  [5789e2e9] FileIO v1.6.5
  [c27321d9] Glob v1.3.0       
  [82e4d734] ImageIO v0.5.3
  [91a5bcdd] Plots v1.11.2    
  [d6d074c3] VideoIO v0.9.1

From (@v1.6) pkg> st -m

[c87230d0] FFMPEG v0.4.0
[b22a6f82] FFMPEG_jll v4.3.1+4
[1270edf5] x264_jll v2020.7.14+2
[dfaa095f] x265_jll v3.0.0+3