473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Using multi-thread to convert video

Dear All

I am a beginner using python. My boss asks me to write a Python script to call ffmpeg to converter video to flash using multi-thread. the program uses database to be the queue and the thread must be reused after each tread completed convertion.
the program has been completed but "Reuse" part. Anyone has any idea how to write that part

Sean
Jun 1 '07 #1
7 3759
bartonc
6,596 Expert 4TB
Dear All

I am a beginner using python. My boss asks me to write a Python script to call ffmpeg to converter video to flash using multi-thread. the program uses database to be the queue and the thread must be reused after each tread completed convertion.
the program has been completed but "Reuse" part. Anyone has any idea how to write that part

Sean
The most common meaning for the term "Reuse" is code reuse. Object reuse is something that is not dificult because objects hang around in memory. On the third hand, thread reuse could be achieved but it would be smarter to reuse the code that creates a single thread each time you need a new thread (IMHO).
Jun 1 '07 #2
Motoma
3,237 Expert 2GB
I did something quite similar, I had two threads going. Both of these threads were basically while loops, checking the state of each other to determine if they should continue running. Inside the loop one would perform database queries, and build a queue of data to be handled, and the other one would process the queue. This method will allow you to do all of your ffmpeg conversions in one thread, saving a lot of processing (and headache).
Jun 1 '07 #3
I did something quite similar, I had two threads going. Both of these threads were basically while loops, checking the state of each other to determine if they should continue running. Inside the loop one would perform database queries, and build a queue of data to be handled, and the other one would process the queue. This method will allow you to do all of your ffmpeg conversions in one thread, saving a lot of processing (and headache).
Dear Motoma
I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__main__":" function

thanks a lot again

by the way, if its not troubling you, can you post this code architecture for the beginner like me
Jun 5 '07 #4
Motoma
3,237 Expert 2GB
Dear Motoma
I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__main__":" function

thanks a lot again

by the way, if its not troubling you, can you post this code architecture for the beginner like me
I don't have the exact code kicking around, but I will whip up some fresh pseudocode for you!

Expand|Select|Wrap|Line Numbers
  1. # fresh squeezed python code, straight from the source!
  2.  
  3. import DataHandler #Name says it all.
  4. import LibDB     # Database Abstraction Layer
  5. import threading
  6. import Queue
  7.  
  8. class Parser:
  9.     def __init__(self):
  10.         self.db = mysqldal()
  11.         self.db.connect("localhost", "database", "username", "password")
  12.         self.qData = Queue.Queue(0)
  13.         self.dh = dataHandler()
  14.  
  15.     def DoQuery(self):
  16.         self.running = True
  17.         self.min = 0
  18.         numresults = -1
  19.         while self.running and numresults != 0:
  20.             numresults = self.db.query("SELECT * FROM myDataTable LIMIT " + self.min + ", 50")
  21.             self.db.populateQueue(self.qData)
  22.             self.min = self.min + 50
  23.         self.running = False
  24.  
  25.     def ParseData(self):
  26.         while self.Running or self.qData.empty == False:
  27.             self.dh.HandleData(self.qData.get(false))
  28.  
  29.     def Begin(self):
  30.         threading.Thread(none, self.DoQuery).start()
  31.         self.ParseData()
  32.  
  33. dItem = Parser()
  34. dItem.Begin()
  35.  
Hope this gives you an idea, I am quite sure none of this will work :P
Jun 5 '07 #5
bartonc
6,596 Expert 4TB
Dear Motoma
I have a silly question that " while loops" needs to be coded in the thread`s "Run()" function or Main "__name__=="__main__":" function

thanks a lot again

by the way, if its not troubling you, can you post this code architecture for the beginner like me
To try to further explain:
run( )

Method representing the thread's activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
So: When an instance of the base class is created, it is given a "callable object" (that's the function that you want run in this thread). The base class's run() calls your function. When your function returns (reaches its end), run() will also return.
If you are creating a subclass of Threading.thread, then you would define your function as an override of run() (which gets called by the base class's start() function.

Hope that helps clear things up a bit.
Jun 5 '07 #6
Dear Motoma and Bartonc

Thank you guys for this great replies. These help a lot
Thanks again

Sean
Jun 7 '07 #7
bartonc
6,596 Expert 4TB
Dear Motoma and Bartonc

Thank you guys for this great replies. These help a lot
Thanks again

Sean
(Another satified customer.) You are welcome. I have the feeling that TheScripts.com is going to be around a good long time and your partisipation helps us grow. So, thank you. Drop on in any ol' time.
Jun 7 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
0
by: Eddie | last post by:
In Microsoft Access form, combo box can be binded to the table or query and can be shown as multi column, getting a actual binded column and showing columns. I'm struggling to make a...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
4
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.