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

encode misses start and end frame in v1.6 of Julia v0.8.4 of VideoIO #328

Closed Wikunia closed 3 years ago

Wikunia commented 3 years ago

We currently encounter a problem at Javis.jl (https://github.com/Wikunia/Javis.jl/pull/340) regarding the duration of some videos. I know that VideoIO.jl is already at v0.9.2 but it seems like quite a lot of stuff changed such that we didn't upgrade yet. Furthermore we suspect that the issue might not strictly be at VideoIO.jl but some kind of dependency. Maybe you have an idea though :smile:

Now to the issue itself: This code creates 30 frames with Luxor.jl and renders them to an mp4 with a framerate of 1 frame per second. The video should therefore have a duration of 30 seconds. It is however only 28 seconds long.

using Colors
using Luxor
using VideoIO

function get_frame(i)
    Drawing(1000, 750, :image)
    if i == 1 
        background("black")
    elseif i == 30
        background("red")
    else
        background("white")
    end
    img = image_as_matrix()
    finish()
    return img
end

function main()
    framerate = 1
    frame_images = [convert.(RGB, get_frame(i)) for i in 1:30]
    codec_props = [:priv_data => ("crf" => "22", "preset" => "medium")]
    video_io = Base.open("temp.stream", "w")
    video_encoder = prepareencoder(
        frame_images[1],
        framerate = framerate,
        AVCodecContextProperties = codec_props,
    )
    for i in 1:30
        appendencode!(video_encoder, video_io, frame_images[i], i)
    end
    finishencode!(video_encoder, video_io)
    close(video_io)
    mux("temp.stream", "video.mp4", framerate; silent = true)

    video_duration = VideoIO.get_duration("video.mp4")
    @show video_duration
    isapprox(video_duration, 30.0, atol = 0.1)
end

I changed the background for the first and last frame which shows that those two frames are not being part of the video file.

Interestingly enough it works fine when one runs it in 1.5 of Julia. This however downgrades also the following packages:

  [0dad84c5] - ArgTools
  [56f22d72] + Artifacts v1.3.0
  [6e34b625] ↓ Bzip2_jll v1.0.8+0 ⇒ v1.0.6+5
  [83423d85] ↓ Cairo_jll v1.16.1+0 ⇒ v1.16.0+6
  [e66e0078] + CompilerSupportLibraries_jll v0.3.4+0
  [f43a241f] - Downloads
  [2e619515] ↓ Expat_jll v2.2.10+0 ⇒ v2.2.7+6
  [b22a6f82] ↓ FFMPEG_jll v4.4.0+0 ⇒ v4.3.1+4
  [a3f928ae] ↓ Fontconfig_jll v2.13.93+0 ⇒ v2.13.1+14
  [d7e528f0] ↓ FreeType2_jll v2.10.4+0 ⇒ v2.10.1+5
  [559328eb] ↓ FriBidi_jll v1.0.10+0 ⇒ v1.0.5+6
  [78b55507] ↓ Gettext_jll v0.21.0+0 ⇒ v0.20.1+7
  [7746bdde] ↓ Glib_jll v2.68.1+0 ⇒ v2.59.0+4
  [3b182d85] ↓ Graphite2_jll v1.3.14+0 ⇒ v1.3.13+4
  [2e76f6c2] ↓ HarfBuzz_jll v2.8.1+0 ⇒ v2.6.1+10
  [a51ab1cf] + ICU_jll v67.1.0+3
  [aacddb02] ↓ JpegTurbo_jll v2.1.0+0 ⇒ v2.0.1+3
  [c1c5ebd0] ↓ LAME_jll v3.100.1+0 ⇒ v3.100.0+3
  [dd4b983a] ↓ LZO_jll v2.10.1+0 ⇒ v2.10.0+3
  [b27032c2] - LibCURL
  [deac9b47] - LibCURL_jll
  [29816b5a] - LibSSH2_jll
  [dd192d2f] + LibVPX_jll v1.9.0+1
  [e9f186c6] ↓ Libffi_jll v3.2.2+0 ⇒ v3.2.1+4
  [d4300ac3] ↓ Libgcrypt_jll v1.8.7+0 ⇒ v1.8.5+4
  [7add5ba3] ↓ Libgpg_error_jll v1.42.0+0 ⇒ v1.36.0+3
  [94ce4f54] ↓ Libiconv_jll v1.16.1+1 ⇒ v1.16.0+8
  [4b2f31a3] ↓ Libmount_jll v2.35.0+0 ⇒ v2.34.0+3
  [89763e89] ↓ Libtiff_jll v4.3.0+0 ⇒ v4.1.0+2
  [38a345b3] ↓ Libuuid_jll v2.36.0+0 ⇒ v2.34.0+7
  [c8ffd9c3] - MbedTLS_jll
  [14a3606d] - MozillaCACerts_jll
  [ca575930] - NetworkOptions
  [e7412a2a] ↓ Ogg_jll v1.3.5+0 ⇒ v1.3.4+2
  [458c3c95] ↓ OpenSSL_jll v1.1.10+0 ⇒ v1.1.1+6
  [efe28fd5] ↓ OpenSpecFun_jll v0.5.5+0 ⇒ v0.5.3+4
  [91d4177d] ↓ Opus_jll v1.3.2+0 ⇒ v1.3.1+3
  [2f80f16e] ↓ PCRE_jll v8.44.0+0 ⇒ v8.42.0+4
  [36c8627f] ↓ Pango_jll v1.47.0+0 ⇒ v1.42.4+10
  [30392449] ↓ Pixman_jll v0.40.1+0 ⇒ v0.40.0+0
  [fa267f1f] + TOML v1.0.3
  [a4e569a6] - Tar
  [02c8fc9c] ↓ XML2_jll v2.9.12+0 ⇒ v2.9.10+3
  [aed1982a] ↓ XSLT_jll v1.1.34+0 ⇒ v1.1.33+4
  [83775a58] + Zlib_jll v1.2.11+18
  [3161d3a3] ↓ Zstd_jll v1.5.0+0 ⇒ v1.4.8+0
  [0ac62f75] ↓ libass_jll v0.15.1+0 ⇒ v0.14.0+4
  [f638f0a6] ↓ libfdk_aac_jll v2.0.2+0 ⇒ v0.1.6+4
  [b53b4c65] ↓ libpng_jll v1.6.38+0 ⇒ v1.6.37+6
  [f27f6e37] ↓ libvorbis_jll v1.3.7+0 ⇒ v1.3.6+6
  [8e850ede] - nghttp2_jll
  [3f19e933] - p7zip_jll
  [1270edf5] ↓ x264_jll v2021.5.5+0 ⇒ v2020.7.14+2
  [dfaa095f] ↓ x265_jll v3.5.0+0 ⇒ v3.0.0+3

as my knowledge about VideoIO is relatively limited I can't easily see which of those packages might create the problem in this regard.

We (@thecedarprince) and I are looking forward to any pointers to find out what is going on here :smile:

In this gist you can see the Project,toml which I used for both v1.5 and v1.6 of Julia and the Manifest_1.5/6 for those two to see the differences.

https://gist.github.com/Wikunia/dd471faea18a663ab11ee518d5bb6642

IanButterworth commented 3 years ago

I very much recommend updating to the latest version. There's an upgrade guide in the changelog. A lot of these issues were fixed in v0.9.

@galenlynch would you be able to give some advice on default v0.9 settings that wouldn't result in issue #327?

Wikunia commented 3 years ago

Thanks @IanButterworth . This resulted in another problem but feel free to close this issue as this doesn't seem to be an issue with v0.9.2 of VideoIO