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

Add flags to ffmpeg mp4 hook for Safari support #1586

Merged
merged 1 commit into from
Aug 7, 2018

Conversation

brianzhang01
Copy link
Contributor

With the current ffmpeg mp4 converter setup in knitr in-line
animation, I was not able to have my animations show up in
Safari. After adding the flags in this commit, it worked.

https://apple.stackexchange.com/questions/166553/why-wont-video-from-ffmpeg-show-in-quicktime-imovie-or-quick-preview

I found the Safari viewability to be sensitive to exactly where
the flags were placed. For instance, running

ffmpeg -y -r 1 -pix_fmt yuv420p -i foo-%d.png foo.mp4

did not work, otherwise I would consider aliasing my ffmpeg
command. It turned out to be necessary to include the -i flag
first, as so:

ffmpeg -y -r 1 -i foo-%d.png -pix_fmt yuv420p foo.mp4

With the current ffmpeg mp4 converter setup in knitr in-line
animation, I was not able to have my animations show up in
Safari. After adding the flags in this commit, it worked.

https://apple.stackexchange.com/questions/166553/why-wont-video-from-ffmpeg-show-in-quicktime-imovie-or-quick-preview

I found the Safari viewability to be sensitive to exactly where
the flags were placed. For instance, running

ffmpeg -y -r 1 -pix_fmt yuv420p -i foo-%d.png foo.mp4

did not work, otherwise I would consider aliasing my ffmpeg
command. It turned out to be necessary to include the -i flag
first, as so:

ffmpeg -y -r 1 -i foo-%d.png -pix_fmt yuv420p foo.mp4
@brianzhang01
Copy link
Contributor Author

Here is some more information about the motivation behind this pull request.

I really like knitr and I especially found the in-line animation feature appealing -- it saves code and is more intuitive to just make multiple figures within a for loop. It turns out that Safari, my default mobile browser, does not support webm or ogg, the two formats that have been used as the default for knitr output, so I was interested to look into mp4 output. (See #712, https://www.w3schools.com/html/html5_video.asp)

I then discovered that the existing knitr ffmpeg mp4 hook generates output that is not viewable by Safari. After adding the flags recommended in this link (https://apple.stackexchange.com/questions/166553/why-wont-video-from-ffmpeg-show-in-quicktime-imovie-or-quick-preview), things worked for me, so I modified knitr with this small change and re-installed it on my system, using these instructions: https://stackoverflow.com/questions/34800331/r-modify-and-rebuild-package.

With this updated knitr package, I was able to write this blog post (https://brianzhang01.github.io/2018/01/clustering-with-k-means-and-em/) which includes animation that I'm able to view in Safari. I tested on my MacBook Air running macOS Sierra Version 10.12.6, and my iPhone with iOS 10.3.1. I also tested on my MacBook Air with Chrome. I will try to create an example of what things are like if I build without the updated flags.

@brianzhang01
Copy link
Contributor Author

Here is the same post built with knitr 1.20 from CRAN. The animations show up for me in Chrome, but not in Safari. http://www.stats.ox.ac.uk/~bzhang/test/2018/01/clustering-with-k-means-and-em/. Source code is here: https://raw.githubusercontent.com/brianzhang01/blog/master/content/post/2018-01-30-clustering-with-k-means-and-em.Rmd

@yihui yihui added this to the v1.21 milestone Aug 7, 2018
Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an FFmpeg expert. I'm just going to trust you since you seem to have done quite a bit of research :) Thanks a lot!

@yihui yihui merged commit f0f9f07 into yihui:master Aug 7, 2018
yihui added a commit that referenced this pull request Aug 7, 2018
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants