Title: Question regarding the frame rate options (seems inconsistent with ffmpeg command-line) · python-ffmpegio/python-ffmpegio · Discussion #50 · GitHub
Open Graph Title: Question regarding the frame rate options (seems inconsistent with ffmpeg command-line) · python-ffmpegio/python-ffmpegio · Discussion #50
X Title: Question regarding the frame rate options (seems inconsistent with ffmpeg command-line) · python-ffmpegio/python-ffmpegio · Discussion #50
Description: Question regarding the frame rate options (seems inconsistent with ffmpeg command-line)
Open Graph Description: Thanks for this nice project! I have a question regarding the framerate change. For example, import ffmpegio with ffmpegio.open( "test_video.mp4", mode="rv", r=24, pix_fmt="rgb24", ) as videostream...
X Description: Thanks for this nice project! I have a question regarding the framerate change. For example, import ffmpegio with ffmpegio.open( "test_video.mp4", mode="rv", r=24, pix_fmt="...
Opengraph URL: https://github.com/python-ffmpegio/python-ffmpegio/discussions/50
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"Question regarding the frame rate options (seems inconsistent with ffmpeg command-line)","text":"\u003cp dir=\"auto\"\u003eThanks for this nice project! I have a question regarding the framerate change. For example,\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"import ffmpegio\n\nwith ffmpegio.open(\n \u0026quot;test_video.mp4\u0026quot;,\n mode=\u0026quot;rv\u0026quot;,\n r=24,\n pix_fmt=\u0026quot;rgb24\u0026quot;,\n) as videostream, ffmpegio.open(\n \u0026quot;low_fps.mp4\u0026quot;,\n \u0026quot;wv\u0026quot;,\n rate_in=24,\n format=\u0026quot;mp4\u0026quot;,\n vcodec=\u0026quot;libx264\u0026quot;,\n pix_fmt=\u0026quot;yuv420p\u0026quot;,\n overwrite=True,\n) as videoout:\n for frame in videostream:\n videoout.write(frame)\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003eimport ffmpegio\n\nwith ffmpegio.open(\n \"test_video.mp4\",\n mode=\"rv\",\n r=24,\n pix_fmt=\"rgb24\",\n) as videostream, ffmpegio.open(\n \"low_fps.mp4\",\n \"wv\",\n rate_in=24,\n format=\"mp4\",\n vcodec=\"libx264\",\n pix_fmt=\"yuv420p\",\n overwrite=True,\n) as videoout:\n for frame in videostream:\n videoout.write(frame)\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eI have a test_video.mp4 with 60fps, I'm trying to convert it to 24fps without changing the playback time. This means I need to drop some frames for the new framerate. Surprisingly, I find the above code seems working well. However, if I use \u003ccode class=\"notranslate\"\u003effmpeg -r 24 -i test_video.mp4 low_fps.mp4\u003c/code\u003e, the video won't drop any frame but the output video will have longer playback time. I assume the \u003ccode class=\"notranslate\"\u003e-r\u003c/code\u003e in ffmpegio here performs differently to ffmpeg command-line? I would be appreciated if you have any insight, thanks!\u003c/p\u003e","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"\u003cp dir=\"auto\"\u003e\u003ca class=\"user-mention notranslate\" data-hovercard-type=\"user\" data-hovercard-url=\"/users/buggyyang/hovercard\" data-octo-click=\"hovercard-link-click\" data-octo-dimensions=\"link_type:self\" href=\"https://github.com/buggyyang\"\u003e@buggyyang\u003c/a\u003e - Glad you found it useful, and I moved this conversation to Discussions as it is not an \u003ccode class=\"notranslate\"\u003effmpegio\u003c/code\u003e issue.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp dir=\"auto\"\u003eI assume the -r in ffmpegio here performs differently to ffmpeg command-line?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp dir=\"auto\"\u003eYes and no. Yes, they are different but no because you are invoking the difference.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen calling FFmpeg, the option order matters.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWith \u003ccode class=\"notranslate\"\u003effmpeg -r 24 -i test_video.mp4 -\u003c/code\u003e, you're forcing the input to have 24 fps, i.e., play back in slow-mo as you described, because \u003ccode class=\"notranslate\"\u003e-r\u003c/code\u003e here is an input stream option.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you want to change the framerate, you need to use the output \u003ccode class=\"notranslate\"\u003e-r\u003c/code\u003e option: \u003ccode class=\"notranslate\"\u003effmpeg -i test_video.mp4 -r 24 -\u003c/code\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIn \u003ccode class=\"notranslate\"\u003effmpegio\u003c/code\u003e, if you give an \u003ccode class=\"notranslate\"\u003effmpeg\u003c/code\u003e option name (minus the leading dash \u003ccode class=\"notranslate\"\u003e-\u003c/code\u003e) as your keyword argument then you are defining \u003ccode class=\"notranslate\"\u003effmpeg\u003c/code\u003e output options. By appending \u003ccode class=\"notranslate\"\u003e_in\u003c/code\u003e to the \u003ccode class=\"notranslate\"\u003effmpeg\u003c/code\u003e option name, your keyword argument turns into an \u003ccode class=\"notranslate\"\u003effmpeg\u003c/code\u003e input option. Using \u003ccode class=\"notranslate\"\u003effmpegio.transcode\u003c/code\u003e as an example,\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"ffmpegio.transcode('test_video.mp4','low_fps.mp4',r=24) # equivalent to ffmpeg -i test_video.mp4 -r 24 -\nffmpegio.transcode('test_video.mp4','slow_mo.mp4',r_in=24) # equivalent to ffmpeg -r 24 -i test_video.mp4 -\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003effmpegio.transcode('test_video.mp4','low_fps.mp4',r=24) # equivalent to ffmpeg -i test_video.mp4 -r 24 -\nffmpegio.transcode('test_video.mp4','slow_mo.mp4',r_in=24) # equivalent to ffmpeg -r 24 -i test_video.mp4 -\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThis applies everywhere including \u003ccode class=\"notranslate\"\u003effmpegio.open\u003c/code\u003e. Notice that your first call \u003ccode class=\"notranslate\"\u003evideostream\u003c/code\u003e opens with the new output rate (thus dropping excess frames) while the second call \u003ccode class=\"notranslate\"\u003evideoout\u003c/code\u003e with its input rate, which matches the \u003ccode class=\"notranslate\"\u003evideostream\u003c/code\u003e framerate.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eHope this makes sense to you. Also, if you're only transcoding, use the \u003ccode class=\"notranslate\"\u003effmpegio.transcode\u003c/code\u003e as I show above as it's a whole lot faster than the dual-stream \u003ccode class=\"notranslate\"\u003efor\u003c/code\u003e loop solution you have currently.\u003c/p\u003e","upvoteCount":2,"url":"https://github.com/python-ffmpegio/python-ffmpegio/discussions/50#discussioncomment-10263908"}}}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:d3475b08-7157-acb9-8326-21a8e0908d64 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | 84B2:109AD5:2A331B:3AEF21:6AFD739B |
| html-safe-nonce | ac2edd71b9909588c2cf11d7e25207732cae95619f1af347cf1d131793adf04d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEIyOjEwOUFENToyQTMzMUI6M0FFRjIxOjZBRkQ3MzlCIiwidmlzaXRvcl9pZCI6Ijg0OTIxNzk2OTA3MzQwNTYzNDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 20c1ddf08099e19a8770c8d7081a44bb03bc9f3ca2f141033444ac861fed1b3b |
| hovercard-subject-tag | discussion:7021506 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-ffmpegio/python-ffmpegio/50/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/890403698ce83116f754bd9b6e3681687aa115deebd1ade19462c0bba4184ede/python-ffmpegio/python-ffmpegio/discussions/50 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/890403698ce83116f754bd9b6e3681687aa115deebd1ade19462c0bba4184ede/python-ffmpegio/python-ffmpegio/discussions/50 |
| og:image:alt | Thanks for this nice project! I have a question regarding the framerate change. For example, import ffmpegio with ffmpegio.open( "test_video.mp4", mode="rv", r=24, pix_fmt="rgb24", ) as videostream... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e54006cf2b96d1ac260960edd10003132911469ccd1ec99c9803119fe2a4e032 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-ffmpegio/python-ffmpegio git https://github.com/python-ffmpegio/python-ffmpegio.git |
| octolytics-dimension-user_id | 98168493 |
| octolytics-dimension-user_login | python-ffmpegio |
| octolytics-dimension-repository_id | 355600490 |
| octolytics-dimension-repository_nwo | python-ffmpegio/python-ffmpegio |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 355600490 |
| octolytics-dimension-repository_network_root_nwo | python-ffmpegio/python-ffmpegio |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5be0bf2b8cf26f8897d31e6bc3c232d328b12a54 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width