如何使用ffmpeg将视频分割为2个单独的文件,用于奇数和偶数字段?
我有一个h.264渐进式640x480视频.我正在尝试创建2个单独的视频文件,每个文件均为640x240,仅分别包含奇数字段和偶数字段.首先,我将文件转换为隔行扫描,但现在我需要转换为2个文件.如何根据yuv格式执行此操作?
I have a h.264 progressive 640x480 video. I'm trying to create 2 separate video files, each is 640x240 and consisting only the odd fields and even fields seperately. Firstly I converted the file to interlaced but now I need to convert to 2 files. How do I do that based on yuv format?
完成后,我将分别对文件进行编码,然后将它们重新加入一个隔行扫描的文件中.
Once I'm done, I will encode the files separately and then rejoin them to a single interlaced file.
我该怎么做?
从完整的渐进式视频开始,您可以一步完成.
Starting with the full progressive video, you can do it in one step.
ffmpeg -i in.mp4 -filter_complex "[0]il=l=d:c=d,split[o][e];[o]crop=iw:ih/2:0:0[odd];[e]crop=iw:ih/2:0:ih/2[even]" -map "[odd]" -f rawvideo odd.yuv -map "[even]" -f rawvideo even.yuv
il滤波器将奇数行移至结果的上半部分,将偶数行移至结果的底部.从那里开始,结果分成两部分,一个副本裁剪到上半部分.另一个到下半部分.每个都输出到单独的YUV文件中.
The il filter takes the odd lines and moves them to top-half of the result, and the even lines to the bottom. From there on, the result is split to two, and one copy cropped to the top half; the other to the bottom half. Each is output to a separate YUV file.
要反转效果,您需要输入两个YUV文件并以相反的模式使用滤镜
To reverse the effect, you would input the two YUV files and use the filter in the opposite mode
ffmpeg -i odd.yuv -i even.yuv -filter_complex "[0][1]vstack,il=l=i:c=i" rejoined.mp4
(您必须为每个YUV文件手动设置输入流属性,例如 -video_size 640x240 -pixel_format yuv420p -framerate 25 -i奇数.yuv
)
(You'll have to manually set input stream properties for each YUV file e.g. -video_size 640x240 -pixel_format yuv420p -framerate 25 -i odd.yuv
)
任何时候都不会检测到任何流或将其正式标记为隔行扫描.这些只是在逐行流的交替行上执行的操作.
At no time will any stream be detected or formally marked as interlaced. These are just operations being performed on alternate lines of a progressive stream.