Coder Social home page Coder Social logo

split_video's Introduction

split_video

Split and recode an mp4 video into evenly sized chunks.

Usage:

./split_video [--gop-size 30] [--chunk-size 120] [--skip 123]
              [--length 1200] input_file output_template

where

--gop-size   is the size of a group of pictures
--chunk-size is the size of a chunk in frames
--skip       are the number of frames to skip at the
             beginning of the input file
--length     are the number of frames to encode

Example:

./split_video --gop-size 25 --chunk-size 100 myfile.mp4 chunks/%05d.mp4

will split a video into chunks of size 100, with I-frames every 25 frames.

Notes

ffmpeg itself has been adding functionality for chunking video in recent versions.

For an input file at 25 fps, the following command almost produces 120 frame chunks:

ffmpeg -i input.mp4 -f segment -segment_time 4.8 \
    -segment_format_options movflags=+faststart \
    -force_key_frames '"expr:eq(mod(n,30),0)"' \
    -vcodec h264 -pix_fmt yuv420p \
    -crf 18 \
    -flags +global_header \
    chunks/%05d.mp4

However, I found that occasionally, 119 or 121 frame chunks would be produced, and for my needs, I wanted all chunks to be exactly 120 frames. So I wrote this tool.

Caveats

  1. audio information is not preserved
  2. only tested on mp4 files, and makes some mp4 specific assumptions
  3. assumes fixed frame rate encoding
  4. only outputs I and P frames (no B frames)

The code could also use some cleanup, but it works for my use case.

Future Work

I have no plans to extend this right now, but I'll gladly accept pull requests which update the code. Possible extensions

  • include audio
  • generalize to other video codecs, variable rate encoding
  • for mp4, output B frames

Sources

Based on ffmpeg sample code. BSD-style license (see License.txt).

split_video's People

Contributors

kmsquire avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.