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

renderer = ffmpeg_renderer() not working on windows 10 #201

Closed
andresrcs opened this issue Oct 22, 2018 · 21 comments
Closed

renderer = ffmpeg_renderer() not working on windows 10 #201

andresrcs opened this issue Oct 22, 2018 · 21 comments
Milestone

Comments

@andresrcs
Copy link

andresrcs commented Oct 22, 2018

System details

RStudio Edition : Desktop
RStudio Version : 1.2.1069
OS Version      : Windows 10 Pro
R Version       : 3.5.1

I want to embed an animation into a rmd file but I'm getting this error

library(ggplot2)
library(gganimate)
p <- ggplot(airquality, aes(Day, Temp)) +
    geom_line(size = 2, colour = 'steelblue') +
    transition_states(Month, 4, 1) +
    shadow_mark(size = 1, colour = 'grey')
animate(p, renderer = ffmpeg_renderer())
#> Warning in file(what, "rb"): no fue posible abrir el archivo 'C:
#> \Users\andre\AppData\Local\Temp\Rtmpu6UB5X\file25b066e545aa.mp4': No such
#> file or directory
#> Error in file(what, "rb"): no se puede abrir la conexión

Created on 2018-10-22 by the reprex package (v0.2.1)

This is the traceback

traceback()
#> 9: file(what, "rb")
#> 8: base64enc::base64encode(x)
#> 7: paste0("<video controls autoplay><source src=\"data:video/", 
#>       format, ";base64,", base64enc::base64encode(x), "\" type=\"video/mp4\"></video>")
#> 6: htmltools::HTML(paste0("<video controls autoplay><source src=\"data:video/", 
#>       format, ";base64,", base64enc::base64encode(x), "\" type=\"video/mp4\"></video>"))
#> 5: as_html_video(x)
#> 4: htmltools::browsable(as_html_video(x))
#> 3: print(htmltools::browsable(as_html_video(x)))
#> 2: print.video_file(x)
#> 1: function (x, ...) 
#>    UseMethod("print")(x)

On this setup is working fine

RStudio Edition : Server
RStudio Version : 1.2.1069
OS Version      : Ubuntu 16.04.5 LTS
R Version       : 3.5.1
@thomasp85
Copy link
Owner

I must admit I don't understand the language of your errors - can you translate it?

@andresrcs
Copy link
Author

andresrcs commented Nov 12, 2018

Ok, here it is

library(ggplot2)
library(gganimate)
p <- ggplot(airquality, aes(Day, Temp)) +
    geom_line(size = 2, colour = 'steelblue') +
    transition_states(Month, 4, 1) +
    shadow_mark(size = 1, colour = 'grey')
animate(p, renderer = ffmpeg_renderer())
#> Warning in file(what, "rb"): cannot open file 'C:
#> \Users\andre\AppData\Local\Temp\Rtmpu6UB5X\file25b066e545aa.mp4': No such
#> file or directory
#> Error in file(what, "rb"): cannot open the connection

@thomasp85
Copy link
Owner

maybe you don't have write permissions to your temp folder? But that would bring up all sorts of issues...

@andresrcs
Copy link
Author

I have them all (permitir = allow)

image

@thomasp85 thomasp85 added this to the CRAN release milestone Dec 4, 2018
@verajosemanuel
Copy link

I've replicated the issue on a fresh clean install of Windows 10
"luckily" i formatted my laptop yesterday so is a perfect candidate for testing due to lack of many packages I usually install along the first week.


> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252   
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gganimate_0.9.9.9999 ggplot2_3.1.0       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0        pillar_1.3.0      compiler_3.5.1    plyr_1.8.4       
 [5] base64enc_0.1-3   class_7.3-14      prettyunits_1.0.2 tools_3.5.1      
 [9] progress_1.2.0    digest_0.6.18     tibble_1.4.2      gtable_0.2.0     
[13] pkgconfig_2.0.2   png_0.1-7         rlang_0.3.0.1     DBI_1.0.0        
[17] rstudioapi_0.8    yaml_2.2.0        e1071_1.7-0       spData_0.2.9.6   
[21] transformr_0.1.0  withr_2.1.2       hms_0.4.2         classInt_0.2-3   
[25] grid_3.5.1        glue_1.3.0        sf_0.7-1          R6_2.3.0         
[29] gifski_0.8.6      tweenr_1.0.0      farver_1.1.0      magrittr_1.5     
[33] htmltools_0.3.6   units_0.6-1       scales_1.0.0      assertthat_0.2.0 
[37] lpSolve_5.6.13    colorspace_1.3-2  labeling_0.3      stringi_1.2.4    
[41] lazyeval_0.2.1    munsell_0.5.0     crayon_1.3.4     

dtl8nzlwwaaaee5 jpg large

@dmi3kno
Copy link
Contributor

dmi3kno commented Dec 4, 2018

Thomas,
I replicated the issue and found out what causes it. You are relying on default -pattern_type glob_sequence flag, which is going to be deprecated soon. By the type of pattern you are providing (%*.png), it will always fall back onto the -pattern_type glob. When this flag is added into the system2() call explicitly it reports:

[image2 @ 003a23a0] Pattern type 'glob' was selected but globbing is not supported by this libavformat build       

What can be done is specify -pattern_type sequence and pass the filename pattern explicitly in line 118 of renderers.R:

    file_glob <- sub('^.*(\\..+$)', 'gganim_plot%4d\\1', basename(frames[1]))

Try installing my version:

remotes::install_github("dmi3kno/gganimate")

Happy to PR, if you want to keep the sequence pattern, instead of relying on ffmpeg being compiled with glob support (which is not the case on my windows build)

@thomasp85
Copy link
Owner

@verajosemanuel and @andresrcs - can you confirm that @dmi3kno's fix resolves your issue?

@dmi3kno
Copy link
Contributor

dmi3kno commented Dec 4, 2018

Since you are suppressing the verbose output of ffmpeg with -loglevel quiet, it is a good idea to check if the output_file has been created at all right after the system2() call (e.g. stopifnot(file.exists(output_file)), but perhaps more elegant)

Btw, av_renderer() is super verbose. Maybe it is a good idea to allow verbosity in ffmpeg_renderer() as well? This issue shows that the problem could be spotted much earlier if the verbosity of system2() call would not be suppressed.

@andresrcs
Copy link
Author

With @dmi3kno version, I no longer get the error message but, I'm just getting an empty file as output.

image

@verajosemanuel
Copy link

Same here. Empty file.

@dmi3kno
Copy link
Contributor

dmi3kno commented Dec 5, 2018

My experience is the same, but this is a different type of issue. It is not empty, its just not playing in Rstudio browser. Pop it out into Chrome to view.

Nothing is shown with av_renderer() either, btw. So it's something to do with playing bit64 encoded videos in Rstudio chromium engine.

@thomasp85
Copy link
Owner

Do you see a video if you render it outside of a RMarkdown document?

@dmi3kno
Copy link
Contributor

dmi3kno commented Dec 5, 2018

No. It does not show in Viewer window either, only in browser (when popped out) or when locating the file on disk and playing in Windows Media Player. Might have something to do with access of Rstudio's chromium to ffmpeg

@holisticinfosec
Copy link

@dmi3kno Thank you, your updated version works like a champ for me. I'm running on Win10 1809 Build 18290 and your fix solved the error and renders in Viewer as well.

@andrewbaxter439
Copy link

andrewbaxter439 commented Dec 8, 2018

Hi @dmi3kno and @thomasp85 - I've been getting the same error message. Tried the new version and still happening (haven't changed anything else).

Here's the rundown of my R session:

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mapproj_1.2.6        maps_3.3.0           rgdal_1.3-6          dplyr_0.7.6         
[5] gganimate_0.9.9.9999 ggplot2_3.1.0        sp_1.3-1 

@thomasp85
Copy link
Owner

The changes proposed by @dmi3kno has only just been merged - can I get you to update and try again?

@thomasp85
Copy link
Owner

@dmi3kno ffmpeg is not used to display the video - It is a basic base64 encoding embedded in a video tag... don't know why that won't display in windows..?

@andrewbaxter439
Copy link

Working perfectly now, thanks!

@dcao1123
Copy link

dcao1123 commented Feb 5, 2019

HI Thomas,
I have an issue with ffmpeg after running the code above.
Error in system2("ffmpeg", "-version", stdout = TRUE) : '"ffmpeg"' not found

what could be issue here?

Thanks

@thomasp85
Copy link
Owner

It looks like you either haven’t installed ffmpeg or don’t have it available on your path. In general I would recommend using the av_renderer for creating video files

@dush88gs
Copy link

HI Thomas,
I have an issue with ffmpeg after running the code above.
Error in system2("ffmpeg", "-version", stdout = TRUE) : '"ffmpeg"' not found

what could be issue here?

Thanks

This issue can be fixed with manually installing "ffmpeg". The instructions are in the following link
https://www.rdocumentation.org/packages/ndtv/versions/0.13.0/topics/install.ffmpeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants