Issue
I am trying the change the resolution of some videos. The original video resolution is 1920x1080. first, I have to change the resolution to 640X480. for this I used the following code:
subprocess.call(['ffmpeg.exe', '-y', '-i', pname1, '-vf', 'scale=-1:480,setsar=1:1', '-c:v','libx264', '-c:a', 'copy', pname2])
when I used this code it produces a file that I cannot open and when I try to open it in cmd it said: "Invalid data found when processing input". I changed the code to this to have 640X480:
subprocess.call(['ffmpeg.exe', '-y', '-i', pname1, '-vf', 'scale=640:-2,setsar=1:1', '-c:v','libx264', '-c:a', 'copy', pname2])
but the output is 640X360, what is the problem and how can I change the resolution from 1920x1080 to 640x480? after that I have to change the resolution of videos to their original resolution (1920x1080) again.
Solution
(1)
"The original video resolution is 1080,
> then I change it to 480...
> and then again change it back into 1080.
...Now I compare the original video in 1080 with this new video in 1080".
(2) "I see this in papers where you have to change the video resolution and then make comparisons."
You can achieve all that with one command, where you vf
scale the input (in memory, no saving needed) and then also later scale
the output (with -s
command). The order of command placement matters as to whether they affect the input or output parts.
Also since you're following some papers, most likely you are expected to use a specific scaling algorithm. When implementing these papers, they might require you to use bilinear or nearest neighbour or such...
You can set that scaling type/algorithm with: sws_flags
(eg: -sws_flags bicubic
).
Your options are: neighbor, area, bilinear, bicubic, spline (for natural cubic), lanczos...
I don't use Python but you can try some code like this:
subprocess.call(['ffmpeg.exe', '-y', '-i', pname1, '-vf', 'scale=640:480', 'sws_flags', 'bicubic', '-pix_fmt', 'yuv420p', '-c:v', 'libx264', '-s', '1920:1080', '-c:a', 'copy', pname2])
Answered By - VC.One
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.