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

Animated plots, hook_ffmpeg_html and video format #712

Closed
basille opened this issue Jan 22, 2014 · 8 comments
Closed

Animated plots, hook_ffmpeg_html and video format #712

basille opened this issue Jan 22, 2014 · 8 comments
Labels
feature Feature requests
Milestone

Comments

@basille
Copy link

basille commented Jan 22, 2014

Since knitr 1.3, animated plots using hook_ffmpeg_html uses OGG video flies instead of MP4. I think it is a sensible default (although WebM would be equally good, according to browser support. However, would it be possible to have the file type as an option, so that people could, if needed, switch to MP4?

It might be already possible, in which case I apologize: I couldn't find a way to do it. As far as I understand it, the file type is hard-coded in hook_ffmpeg_html:

mov.fname = str_c(sub(paste(fig.num, "$", sep = ""), "", 
    x[1]), ".ogg")

After a couple of trials, I couldn't find a way to do it manually. For instance, modifying directly hook_ffmpeg_html using:

knit_hooks$set(hook_ffmpeg_html = function(x, options) 
    ...
    mov.fname = str_c(sub(paste(fig.num, "$", sep = ""), "", 
        x[1]), ".mp4")
    ...

does nothing: output is still a OGG file. Or setting up a new hook_ffmpeg_html_mp4, which would be called by opts_knit$get(animation.fun = hook_ffmpeg_html_mp4), results in an error. In the end, I'm not too sure what to modify or what option to change to make this choice possible.

By the way, I'm using knitr 1.5.
Mathieu.

@yihui
Copy link
Owner

yihui commented Jan 26, 2014

Thanks for the feedback. The animation support in HTML was not carefully designed, and there is a lot of room for improvement. I do not really want to hard-code the video format. Perhaps I can clean up the mess in knitr 1.7.

@basille
Copy link
Author

basille commented Jan 27, 2014

Admittedly, I'm not a video expert, but I would think that the more control given to the user the better (given sane default settings for those who don't want to bother with details, and just want an out-of-the-box result). So, in advance, thanks for taking care of the code about videos!

@yihui yihui added this to the v1.8 milestone Oct 26, 2014
@yihui yihui added the feature Feature requests label Oct 26, 2014
@yihui yihui closed this as completed in 0e9dd93 Oct 26, 2014
@yihui
Copy link
Owner

yihui commented Oct 26, 2014

I added an internal function so you can define your own video format, e.g. if you want mp4:

knitr::opts_knit$set(animation.fun = function(x, options) {
  knitr:::hook_ffmpeg(x, options, '.mp4')
})

Note the default video format has been changed to WebM in the latest version of knitr.

@basille
Copy link
Author

basille commented Oct 30, 2014

Thanks Yihui, that looks great! Looks like I have everything I was hoping for there (not tested yet).

yihui added a commit that referenced this issue Aug 16, 2015
@yihui
Copy link
Owner

yihui commented Aug 16, 2015

FYI, I just added a chunk option ffmpeg.format so you can easily change the video format from the default webm to mp4 by using the chunk option ffmpeg.format = 'mp4'.

@basille
Copy link
Author

basille commented Sep 8, 2015

Hey Yihui,

This looks great! Did the new option make it to v1.11? I couldn't have it work, with e.g. ffmpeg.format = "mp4". Shall I use the dev version instead?

In addition, does the option allow to change other settings, or is it necessary to go through opts_knit$set/hook_ffmpeg for detailed settings?

Thanks for your work!
Mathieu.

@yihui
Copy link
Owner

yihui commented Sep 8, 2015

@basille It is in the development version: https://github.com/yihui/knitr/blob/master/NEWS.md (1.12 is not released yet) This option does not allow you to change any other settings.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants