yihui / animation

A gallery of animations in statistics and utilities to create animations
https://yihui.org/animation/
206 stars 60 forks source link

avconv to replace ffmpeg? #26

Closed yihui closed 9 years ago

yihui commented 12 years ago

ffmpeg has been renamed to libav: http://libav.org

ubitux commented 11 years ago

No. See http://stackoverflow.com/a/9477756/1109017.

yihui commented 11 years ago

thanks! good to know that

skyebend commented 9 years ago

For some time it seemed that Debian and Ubuntu systems simply 'aliased' ffmepg to avconv, so animation library worked with default settings. At the moment, it seems that this is no longer the case, so saveVideo() fails unless ffmpeg='avconv' argument is given or ffmpeg is build from source.

sh: 1: ffmpeg: not found
Error in system(paste(ffmpeg, "-version"), intern = TRUE) : 
  error in running command
NULL
Warning message:
In saveVideo({ :
  The command "'ffmpeg'" is not available in your system. Please install FFmpeg first: http://ffmpeg.org/download.html

Since avconv is provided by default on these systems, maybe animation package should set it as the default if it can't find ffmpeg? like having something in zzz.R like:

 if (.Platform$OS.type != "windows")
{
  # check if ffmpeg installed
  if (Sys.which('ffmpeg')==''){
    # can't find ffmpeg, so try avconv
    if(Sys.which('avconv')!=''){
      ani.options(ffmpeg = "avconv")
      message("'ffmpeg' not found on system, using 'avconv' as default instead')
    }
  }
}

Does this approach seem feasible to include in animation? Or should I just add it in my dependent library? Or does anyone know more about the ffmpeg/avconv future on these platforms?

yulijia commented 9 years ago

Hi, @skyebend I made a little change in saveVideo.R based on your code, please see my own repository (branch issue26)

Would you mind to help me test if it can works on your Ubuntu or Debain system?

Try install the development version of animation packages on github repository

install.packages("devtools")

library(devtools)

dev_mode(on=T)

install_github("animation",username="yulijia",ref="issue26")

library(animation)
saveVideo({
par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3, cex.axis = 0.8,
cex.lab = 0.8, cex.main = 1)
ani.options(interval = 0.05, nmax = 300)
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow")
}, video.name = "BM.mp4", other.opts = "-b 300k")

# when finished do:
dev_mode(on=F)

@yihui

I didn't delete the "version check" and "if function" in this code hunk, because I do not know if this function supports any other converters.

#if saveVideo() only support `ffmpeg` and `avconv` , we can delete some lines
version = try(system(paste(ffmpeg, '-version'), intern = TRUE),silent = TRUE) #  this line can be deleted
if (inherits(version,'try-error')){ #  this line can be deleted
  warning()
} # this line can be deleted
skyebend commented 9 years ago

Hi Lijia,

Thanks for looking at this!

I found that your patch doesn't work, I think because

when you assign ani.options(ffmpeg = "avconv") on line 52, you asign to the global parameter, and its state has already been read on line 45, so it is ignored.

I think there is a bit of a question about how this function should work wrt preset defaults

I'd think if the user as specifically set ani.oopts ffmpeg, that choise should be respected. And perhaps also if they passed in directly via the saveVideo ffmpeg= argument. (In the CRAN version ani.opts overides command argument).

I'd think ideally it might work as follows:

I think this would preserve existing behavior, allow defaulting or user specification of either ffmpeg or avconv via either ani.options or the saveVideo argument, with the later overriding the former.

Does that make sense?

If not I can try a fork and make a pull request

best, -skye

On 06/17/2015 02:14 AM, Lijia Yu wrote:

Hi, @skyebend https://github.com/skyebend I made a little change in |saveVideo.R| based on your code, please see my own repository (branch issue26) https://github.com/yulijia/animation/blob/issue26/R/saveVideo.R

Would you mind to help me test if it can works on your Ubuntu or Debain system?

Try install the development version of animation packages on github repository

|install.packages("devtools")

library(devtools)

dev_mode(on=T)

install_github("animation",username="yulijia",ref="issue26")

library(animation) saveVideo({ par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3, cex.axis = 0.8, cex.lab = 0.8, cex.main = 1) ani.options(interval = 0.05, nmax = 300) brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow") }, video.name = "BM.mp4", other.opts = "-b 300k")

when finished do:

dev_mode(on=F) |

@yihui https://github.com/yihui

I didn't delete the "version check" and "if function" in this code hunk, because I do not know if this function supports any other converters.

|#if saveVideo() only support ffmpeg and avconv , we can delete some lines version = try(system(paste(ffmpeg, '-version'), intern = TRUE),silent = TRUE) # this line can be deleted if (inherits(version,'try-error')){ # this line can be deleted warning() } # this line can be deleted

— Reply to this email directly or view it on GitHub https://github.com/yihui/animation/issues/26#issuecomment-112731582.

yulijia commented 9 years ago

Hi skye ( @skyebend ),

Thanks for your suggestions. Pull requests are welcome:) Let me know if there is anything I can do to help.

Best, Lijia

yulijia commented 9 years ago

Thanks to skye, saveVideo function now support avconv on linux (Ubuntu and Debian).

I prefer to install ffmpeg as video converter on linux.

Starting with Ubuntu 15.04 "Vivid", FFmpeg's ffmpeg is back in the repositories again.

skyebend commented 9 years ago

One question stilil on this, since it now sets a default ani.opts$ffmpeg on linux machines with ffmpeg or avconv installed, should it do so on windows as well? (left a TODO: in the code)

yulijia commented 9 years ago

Is there any default installed video converter on Windows ? I am not familiar with those converters, for me, I do not install any video converter before using animation package on Windows. When I need using saveVideo, I just need install ffmpeg.

skyebend commented 9 years ago

There is not a default converter with Window (that I know of) but I think ffmpeg does install to a default location? At least the example for saveVideo() does specify a full path. I think that if user has added ffmpeg to their System Path, the default 'ffmpeg' command will work, but if they have installed ffmpeg but not altered their System Path, the full path is more likely to work? I don't normally use windows machines so I'm not quite sure.

On 06/30/2015 06:13 AM, Lijia Yu wrote:

Is there any default installed video converter on Windows ? I am not familiar with those converters, for me, I do not install any video converter before using |animation| package on Windows. When I need using |saveVideo|, I just need install ffmpeg.

— Reply to this email directly or view it on GitHub https://github.com/yihui/animation/issues/26#issuecomment-117175893.