Title: blocksize function, is it possible to limit the video output size · python-ffmpegio/python-ffmpegio · Discussion #39 · GitHub
Open Graph Title: blocksize function, is it possible to limit the video output size · python-ffmpegio/python-ffmpegio · Discussion #39
X Title: blocksize function, is it possible to limit the video output size · python-ffmpegio/python-ffmpegio · Discussion #39
Description: blocksize function, is it possible to limit the video output size
Open Graph Description: have 2 questions : what is blocksize parameter in open() function ? how to limit video output size (in mb, or gb) ? code input = 'http://195.196.36.242/mjpg/video.mjpg' output = 'rtsp.mp4' with ffm...
X Description: have 2 questions : what is blocksize parameter in open() function ? how to limit video output size (in mb, or gb) ? code input = 'http://195.196.36.242/mjpg/video.mjpg' output = 'rtsp.m...
Opengraph URL: https://github.com/python-ffmpegio/python-ffmpegio/discussions/39
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"blocksize function, is it possible to limit the video output size","text":"\u003cp dir=\"auto\"\u003ehave 2 questions :\u003c/p\u003e\n\u003col dir=\"auto\"\u003e\n\u003cli\u003ewhat is blocksize parameter in open() function ?\u003c/li\u003e\n\u003cli\u003ehow to limit video output size (in mb, or gb) ?\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003ecode\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"input = 'http://195.196.36.242/mjpg/video.mjpg'\noutput = 'rtsp.mp4'\nwith ffmpegio.open(input, 'rv') as fin, ffmpegio.open(output, 'wv', rate_in = fin.rate, blocksize = 1, overwrite = True) as fout:\n for frames in fin:\n fout.write(frames)\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003einput = 'http://195.196.36.242/mjpg/video.mjpg'\noutput = 'rtsp.mp4'\nwith ffmpegio.open(input, 'rv') as fin, ffmpegio.open(output, 'wv', rate_in = fin.rate, blocksize = 1, overwrite = True) as fout:\n for frames in fin:\n fout.write(frames)\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eresult\u003c/strong\u003e\u003cbr\u003e\nno error occured, but seems looping forever\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eexpected result\u003c/strong\u003e\u003cbr\u003e\nthe loop is ended when the output file 'rtsp.mp4' size is 1 mb\u003c/p\u003e\n\u003cp dir=\"auto\"\u003ebest regards\u003c/p\u003e","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"\u003cblockquote\u003e\n\u003cp dir=\"auto\"\u003ewhat is blocksize parameter in open() function ?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp dir=\"auto\"\u003esets the number of frames to read at once (only used by a reader or filter streams). For example,\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"with ffmpegio.open(input, 'rv', blocksize=100) as fin\n for frames in fin:\n assert frames.shape[0]==100\"\u003e\u003cpre class=\"notranslate\"\u003e\u003cspan class=\"pl-k\"\u003ewith\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003effmpegio\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eopen\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003einput\u003c/span\u003e, \u003cspan class=\"pl-s\"\u003e'rv'\u003c/span\u003e, \u003cspan class=\"pl-s1\"\u003eblocksize\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e=\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e100\u003c/span\u003e) \u003cspan class=\"pl-k\"\u003eas\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003efin\u003c/span\u003e\n \u003cspan class=\"pl-s1\"\u003efor\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eframes\u003c/span\u003e \u003cspan class=\"pl-c1\"\u003ein\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003efin\u003c/span\u003e:\n \u003cspan class=\"pl-k\"\u003eassert\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eframes\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eshape\u003c/span\u003e[\u003cspan class=\"pl-c1\"\u003e0\u003c/span\u003e]\u003cspan class=\"pl-c1\"\u003e==\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e100\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eshould read all the frames. The last block likely does not contain 100 frames, and it would results in the assertion error.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp dir=\"auto\"\u003ehow to limit video output size (in mb, or gb) ?\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp dir=\"auto\"\u003eThis is a quintessential FFmpeg question. The short answer is you cannot in a one-pass encoding. You can use a two-pass encoding to specify the size. See \u003ca href=\"https://trac.ffmpeg.org/wiki/Encode/H.264#twopass\" rel=\"nofollow\"\u003ehttps://trac.ffmpeg.org/wiki/Encode/H.264#twopass\u003c/a\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eHowever, \u003ccode class=\"notranslate\"\u003effmpegio\u003c/code\u003e currently provide a simple interface for \u003ccode class=\"notranslate\"\u003etranscode\u003c/code\u003e function (See the example on \u003ca href=\"https://github.com/python-ffmpegio/python-ffmpegio?tab=readme-ov-file#transcoding\"\u003ethe readme page\u003c/a\u003e. Actually, I'm not even sure if you can do it with an input pipe, which is requirement for with any \u003ccode class=\"notranslate\"\u003effmpegio\u003c/code\u003e writer function/class to do two-pass operation.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eBut I don't think this is what you're interested in. You want to know if you can stop the reader stream when it has written so many frames. As far as I know, you cannot do it by the file size, but you can specify the duration in seconds by \u003ccode class=\"notranslate\"\u003es\u003c/code\u003e option or in frames by \u003ccode class=\"notranslate\"\u003evframes\u003c/code\u003e option. See the \u003ca href=\"https://ffmpeg.org/ffmpeg.html#Main-options\" rel=\"nofollow\"\u003eFFmpeg documentation\u003c/a\u003e.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eThere is a way to terminate it by the number of bytes read using the progress callback. But I'm spotting bugs which freezes the execution (interlocked thread). If you're interested, I'll remember to come back to this thread for a solution once the bugs are sorted out.\u003c/p\u003e","upvoteCount":1,"url":"https://github.com/python-ffmpegio/python-ffmpegio/discussions/39#discussioncomment-8780769"}}}
| 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:59ff8641-9f8b-73f7-479a-badb62c6f2d3 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | 858E:8F0FA:29476F:396C44:6AFD7397 |
| html-safe-nonce | 3409828b108039eda3604d843c7d775b1fd41dd85649a709c87e0c275f0c2a18 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NThFOjhGMEZBOjI5NDc2RjozOTZDNDQ6NkFGRDczOTciLCJ2aXNpdG9yX2lkIjoiMTIzNzg2Nzc4NjE5Mzk1Nzc4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4eb1858cf8302ae63911dd5bf90a32f759d315973213c1dfa7436587cc8d8304 |
| hovercard-subject-tag | discussion:6369948 |
| 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/39/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/3b3eff50d184cf93859ddc96d0d220010a1406461c245d28bfce87fafa6aae24/python-ffmpegio/python-ffmpegio/discussions/39 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b3eff50d184cf93859ddc96d0d220010a1406461c245d28bfce87fafa6aae24/python-ffmpegio/python-ffmpegio/discussions/39 |
| og:image:alt | have 2 questions : what is blocksize parameter in open() function ? how to limit video output size (in mb, or gb) ? code input = 'http://195.196.36.242/mjpg/video.mjpg' output = 'rtsp.mp4' with ffm... |
| 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