Suggestions for optimizing movie quality when working with file size limits?

Dear ChimeraX team, Making movies in ChimeraX is my favorite way of communicating my research, but unfortunately many journals have strict file size limits for supplementary movie files (30 MB in my case). I am wondering if there are suggestions for settings that give relatively small files with good visual appearance, i.e a specific format that works better then others. I am currently encoding in .mp4. Is it preferable to set qscale rather than quality/bitrate? I assume both bitrate and the windowsize scale linear with data size? Or are there recommendations for external software that efficiently compresses high-quality ChimeraX movies? Many thanks, Matthias

Hi Matthias, What journal has a 30 Mbyte limit on supplementary movies? That is an absurdly small size for a video. Here are some thoughts about how to balance movie file size and appearance quality. The four things that matter are the frame size (e.g. 1920 x 1080), the compression level, the video codec, and how much motion is in your video. ChimeraX is using H.264 video codec which has been the standard high performance codec for more than a decade. But in recent years H.265 (also called HVEC) has come along that supposedly can compress 50% more with the same quality. I tried H.265 in ChimeraX by modifying its Python code (ChimeraX.app/Contents/lib/python3.11/site-packages/chimerax/movie/formats.py changing "libx264" to "libx265") and it produced a video that was 50% bigger using the same compression settings (18 MB instead of 12 MB with H.264) but that probably just means the compression setting needs to be changed and the H265 was probably much higher quality. But also the H265 video would not play with Mac QuickTime, and searching online said ffmpeg H265 encoding needs some other special flags (ffmpeg option '-tag:v hvc1') to get it to play in QuickTime. It would probably be worth putting H265 into ChimeraX with the necessary fixes, but I suspect 50% extra compression is a best-case scenario and probably it is typically much less. So sticking with H.264 compression in ChimeraX I tried the different movie encode command quality settings https://www.cgl.ucsf.edu/chimerax/docs/user/commands/movie.html#encode with a test movie made on a Mac retina display with windowsize 960 540 open 7qsk movie record ; turn y 2 180 ; wait 180 ; movie encode ~/Desktop/movie11.mp4 verbose true quality good This produces a movie of size 1920 x 1080 (standard HD resolution) because this Mac has a "retina" display, so twice the pixel resolution of a normal display. The encoded movies with "quality X" where X is highest, higher, high, good, medium, fair, or low gave file sizes 20,17,15,12,8,6,4 Mbytes respectively. The ChimeraX default is "good", so 12 Mbytes. This video is 7 seconds long. You'd have to judge by eye for yourself which quality level you find acceptable, and it will depend on the actual contents of your movie. For this movie with no fine lines even the lowest quality with file size 4 Mbytes looked ok to me. The verbose option in the ChimeraX movie encode command outputs the ffmpeg command used to encode the movie, that looks like /Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/bin/ffmpeg -r 25 -i /var/folders/jb/f14hkn9s19l691b68w_lvm0w0000gn/T/chimovie_0AuT-%05d.ppm -vf crop=floor(in_w/2)*2:floor(in_h/2)*2:0:0 -y -vcodec libx265 -f mp4 -pix_fmt yuv420p -crf 20 /Users/goddard/Desktop/movie.mp4 The movie quality option corresponds to the "-crf 20" ffmpeg option which controls variable bit rate encoding and is described in the ffmpeg manual https://trac.ffmpeg.org/wiki/Encode/H.264 Different ChimeraX quality settings use different CRF values from 15 (highest) to 28 (lowest). I would not use the ChimeraX bitrate option since that uses fixed bit rate. Because some parts of your video will compress extremely small (no motion happening) and others poorly (lots of motion), using fixed bit rate is a bad choice for making smalls. Variable bit rate tries to maintain uniform quality which requires very different bit rates for different segments of the video. The last aspect of getting a small file size is reducing the movement in your video. I would not suggest changing your video in ways that make it less informative just to meet the journal's dumb requirements. But many science videos do slow rotations between different orientations of a molecule to show you one interesting view point or another, and the slow rotations are just bad (a bit nauseating). You should do a pretty fast rotation if the point is just to get to a new view point. A fast rotation is better than instantly jumping to a new viewpoint because the viewer sees the spatial relation if you do a fast rotation. But if the intermediate views during the rotation are not important they should not be dragged out over a 3 second rotation -- it should be 0.5 seconds, then freeze at the interesting viewpoint for several seconds. This better presentation will also make your video much smaller. In summary if you have to meet some absurdly small journal video size limit I would first consider submitting to a journal that has more sense. Then I would make the frame size small such that reasonable visual quality can be achieved with some compression level. That has to be judged by eye trying several recordings. The best trade-off will differ based on the content of the video. In the future ChimeraX will hopefully allow H265 video encoding with better compression for the same quality as H264. But H265 is encumbered by 4 patents (H264 only by one), and has playback compatibility issues as seen on the Mac, and current ChimeraX ffmpeg versions (which are different on different operating systems) may not even support H265, so there is a fair bit of work to get this into ChimeraX. Tom
On Apr 5, 2024, at 1:49 AM, Vorländer,Matthias Kopano via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear ChimeraX team,
Making movies in ChimeraX is my favorite way of communicating my research, but unfortunately many journals have strict file size limits for supplementary movie files (30 MB in my case). I am wondering if there are suggestions for settings that give relatively small files with good visual appearance, i.e a specific format that works better then others. I am currently encoding in .mp4. Is it preferable to set qscale rather than quality/bitrate? I assume both bitrate and the windowsize scale linear with data size? Or are there recommendations for external software that efficiently compresses high-quality ChimeraX movies?
Many thanks, Matthias
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/

Hi Tom, Thanks a lot for the detailed answer and the tips on minimizing mocements! I agree, the file size limit is very annoying, but the nature publishing group policy… I now converted the output from ChimeraX using VLC media player (also H.264 codec) , and get a file that is 50% smaller with no visual loss of quality, at least to my eyes. So perhaps that’s useful to know. Best wishes, Matthias From: Tom Goddard <goddard@sonic.net> Date: Friday, April 5, 2024 at 23:45 To: Vorländer,Matthias Kopano <matthias.vorlaender@imp.ac.at> Cc: ChimeraX-users@cgl.ucsf.edu <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] Suggestions for optimizing movie quality when working with file size limits? Hi Matthias, What journal has a 30 Mbyte limit on supplementary movies? That is an absurdly small size for a video. Here are some thoughts about how to balance movie file size and appearance quality. The four things that matter are the frame size (e.g. 1920 x 1080), the compression level, the video codec, and how much motion is in your video. ChimeraX is using H.264 video codec which has been the standard high performance codec for more than a decade. But in recent years H.265 (also called HVEC) has come along that supposedly can compress 50% more with the same quality. I tried H.265 in ChimeraX by modifying its Python code (ChimeraX.app/Contents/lib/python3.11/site-packages/chimerax/movie/formats.py changing "libx264" to "libx265") and it produced a video that was 50% bigger using the same compression settings (18 MB instead of 12 MB with H.264) but that probably just means the compression setting needs to be changed and the H265 was probably much higher quality. But also the H265 video would not play with Mac QuickTime, and searching online said ffmpeg H265 encoding needs some other special flags (ffmpeg option '-tag:v hvc1') to get it to play in QuickTime. It would probably be worth putting H265 into ChimeraX with the necessary fixes, but I suspect 50% extra compression is a best-case scenario and probably it is typically much less. So sticking with H.264 compression in ChimeraX I tried the different movie encode command quality settings https://www.cgl.ucsf.edu/chimerax/docs/user/commands/movie.html#encode with a test movie made on a Mac retina display with windowsize 960 540 open 7qsk movie record ; turn y 2 180 ; wait 180 ; movie encode ~/Desktop/movie11.mp4 verbose true quality good This produces a movie of size 1920 x 1080 (standard HD resolution) because this Mac has a "retina" display, so twice the pixel resolution of a normal display. The encoded movies with "quality X" where X is highest, higher, high, good, medium, fair, or low gave file sizes 20,17,15,12,8,6,4 Mbytes respectively. The ChimeraX default is "good", so 12 Mbytes. This video is 7 seconds long. You'd have to judge by eye for yourself which quality level you find acceptable, and it will depend on the actual contents of your movie. For this movie with no fine lines even the lowest quality with file size 4 Mbytes looked ok to me. The verbose option in the ChimeraX movie encode command outputs the ffmpeg command used to encode the movie, that looks like /Users/goddard/ucsf/chimerax/ChimeraX.app/Contents/bin/ffmpeg -r 25 -i /var/folders/jb/f14hkn9s19l691b68w_lvm0w0000gn/T/chimovie_0AuT-%05d.ppm -vf crop=floor(in_w/2)*2:floor(in_h/2)*2:0:0 -y -vcodec libx265 -f mp4 -pix_fmt yuv420p -crf 20 /Users/goddard/Desktop/movie.mp4 The movie quality option corresponds to the "-crf 20" ffmpeg option which controls variable bit rate encoding and is described in the ffmpeg manual https://trac.ffmpeg.org/wiki/Encode/H.264 Different ChimeraX quality settings use different CRF values from 15 (highest) to 28 (lowest). I would not use the ChimeraX bitrate option since that uses fixed bit rate. Because some parts of your video will compress extremely small (no motion happening) and others poorly (lots of motion), using fixed bit rate is a bad choice for making smalls. Variable bit rate tries to maintain uniform quality which requires very different bit rates for different segments of the video. The last aspect of getting a small file size is reducing the movement in your video. I would not suggest changing your video in ways that make it less informative just to meet the journal's dumb requirements. But many science videos do slow rotations between different orientations of a molecule to show you one interesting view point or another, and the slow rotations are just bad (a bit nauseating). You should do a pretty fast rotation if the point is just to get to a new view point. A fast rotation is better than instantly jumping to a new viewpoint because the viewer sees the spatial relation if you do a fast rotation. But if the intermediate views during the rotation are not important they should not be dragged out over a 3 second rotation -- it should be 0.5 seconds, then freeze at the interesting viewpoint for several seconds. This better presentation will also make your video much smaller. In summary if you have to meet some absurdly small journal video size limit I would first consider submitting to a journal that has more sense. Then I would make the frame size small such that reasonable visual quality can be achieved with some compression level. That has to be judged by eye trying several recordings. The best trade-off will differ based on the content of the video. In the future ChimeraX will hopefully allow H265 video encoding with better compression for the same quality as H264. But H265 is encumbered by 4 patents (H264 only by one), and has playback compatibility issues as seen on the Mac, and current ChimeraX ffmpeg versions (which are different on different operating systems) may not even support H265, so there is a fair bit of work to get this into ChimeraX. Tom On Apr 5, 2024, at 1:49 AM, Vorländer,Matthias Kopano via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote: Dear ChimeraX team, Making movies in ChimeraX is my favorite way of communicating my research, but unfortunately many journals have strict file size limits for supplementary movie files (30 MB in my case). I am wondering if there are suggestions for settings that give relatively small files with good visual appearance, i.e a specific format that works better then others. I am currently encoding in .mp4. Is it preferable to set qscale rather than quality/bitrate? I assume both bitrate and the windowsize scale linear with data size? Or are there recommendations for external software that efficiently compresses high-quality ChimeraX movies? Many thanks, Matthias _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu<mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
participants (2)
-
Tom Goddard
-
Vorländer,Matthias Kopano