Skip to content

在原仓库基础上增加了转mp4和重新合并为单个文件的逻辑。单个大视频转码拆分到不同机器上执行的demo

License

Notifications You must be signed in to change notification settings

onlyeat3/video-splitter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

说明

使用map-reduce机制提升转码效率和资源利用率 按照分割文件 -> 拆分任务到不同机器 -> 合并转码后的分片文件的方式,充分利用集群资源提升转码速度 栗子: 原文件input.mxf 需要转码成 output.mp4

//按60秒一个文件分割
python video-splitter/ffmpeg-split.py -f input.mxf -s 60

分片后的文件

input-1-of-4.mxf
input-2-of-4.mxf
input-3-of-4.mxf
input-4-of-4.mxf

转码后的文件

output-1-of-4.mp4
output-2-of-4.mp4
output-3-of-4.mp4
output-4-of-4.mp4

合并后的文件

output.mp4

注意,因为单机资源限制,拆分成多进程执行不能减少转码耗时

Command Line Video Splitter

Simple command line Python script that splits video into multi chunks. Under the hood script uses FFMpeg so you will need to have that installed. No transcoding or modification of video happens, it just get's split properly.

Run python ffmpeg-split.py -h to see the options. Here are few samples of how it could be used:

Spliting video into equal chunks

python ffmpeg-split.py -f big_video_file.mp4 -s 10

This splits big_video_file.mp4 into chunks, and the size of chunk is 10 seconds. Each chunk will be suffixed with numeric index, for example big_video_file-0.mp4, big_video_file-1.mp4, etc.

Spliting video into equal chunks with some extra options

python ffmpeg-split.py -f input.mp4 -s 600 -v libx264 -e '-vf "scale=320:240" -threads 8'

This splits input.mp4 into chunks, and the size of chunk is 600 seconds. With extra option to scale output to 320:240 and use 8 threads to speed up.

Splitting videos into unequal chunks

In order to create unequal chunks of a video, you'll need to create manifest.json.

manifest.json

[
    {
        "start_time": 0,
        "length": 34,
        "rename_to": "video1"
    },
    {
        "start_time": 35,
        "length": 22,
        "rename_to": "video2.mp4"
    }
]

Afterwards run:

python ffmpeg-split.py -f big_video_file.mp4 -m manifest.json

This splits big_video_file.mp4 into 2 video files, video1.mp4 and video2.mp4. The video1.mp4 is a 34 seconds clip, starting from 0:00 to 0:34 of the big_video_file.mp4.

Alternatively, you can use a manifest.csv file to accomplish the task above.

manifest.csv:


start_time,length,rename_to
0,34,video1
35,22,video2

Manifest Options

  • start_time - number of seconds into the video or start time
  • length - length of the video in seconds. The end time of the video is calculated by the start_time plus the length of the video.
  • rename_to - name of the video clip to be saved
  • end_time - end time of the video

Additional Arguments

  • -v or --vcodec ffmpeg video codec to be used.
  • -a or --acodec ffmpeg audio codec to be used.
  • -m or --manifest manifest file to control the splitting of videos.
  • -f or --file video file to split.
  • -s or --split-size seconds to evenly split the videos
  • -e or --extra extra optional options for ffmpeg, e.g. '-e -threads 8' to use 8 threads to speed up.

Notes:

The -s and -m options should not be used together. If they are, -m option takes precedent over the -s option

Known Issues with ffmpeg

  • There might be some videos that aren't showing properly after splitting the source video with ffmpeg. To resolve this, use the -v option and pass in the associated video codec for the source video or video format. For example, mp4 videos use h264 video codec. Therefore, running the command python ffmpeg-split.py -f example.mp4 -s -v h264, may resolve this issue.

Installing ffmpeg

See FFmpeg installation guide for details.

About

在原仓库基础上增加了转mp4和重新合并为单个文件的逻辑。单个大视频转码拆分到不同机器上执行的demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%