![]() ![]() Depending on the video probed by ffprobe your keys are going to store different values. ![]() The output displayed on the console should look similar to the one shown below. If the above python statement does not produce any errors it means we can easily print the information using a print statement. format_information = parse_format(output) Let’s see if our parsing function does the job it is supposed to do. Then use the communicate method as shown here: output, _ = format_p.communicate() Stdin=subprocess.PIPE, stderr=subprocess.PIPE) Making use of the function which deals with parsing the information returned from ffprobe is really easy.īefore making use of the above function it is needed to spawn a new process as shown below: cmds = įormat_p = subprocess.Popen(cmds, stdout=subprocess.PIPE, So far we have written some code in our interactive shell. So make sure you write it in the python interactive shell as we are going to make use of it. ffmpeg -i input.mkv -c:a copy -s hd720 output.mkv This modifies the video to 1280x720 in the output, but you can set the width and height manually if you want: ffmpeg -i input.mkv -c:a copy -s 1280x720 output.mkv This produces the exact same output as the earlier command. The following is the final code for our function. how to transcode a video in python using ffmpeg. So doing a = test(5) on the python interactive shell after defining the above function is going to assign the variable a the value of five.Īn if statement can help to check if any of this line is present in the string, so if this condition is met we go skip them and go to the next line. It takes an argument and returns it back as it is. ![]() The function test is really simple and self explanatory. output, p.communicate () Then print the format information using the print statement as shown below: print (output) Something similar to the string shown below is going to be displayed on the python console. ![]() Python makes is really easy to define a function by making use of the def syntax. The following example makes it easy to understand the kind of object we plan to return inside the function which is going to deal with parsing the string: Ī function is needed to handle the parsing. So basically we need to build a simple function which is going to receive a long string as an input like the one shown above and return a python dictionary with all the information. This is the perfect case where parsing becomes really useful. As you can see from the above example the long string is being stored in the variable output. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |