项目作者: jakubvalenta

项目描述 :
Batch cut and compose video clips
高级语言: Python
项目地址: git://github.com/jakubvalenta/video-composer.git
创建时间: 2016-04-21T14:47:22Z
项目社区:https://github.com/jakubvalenta/video-composer

开源协议:Apache License 2.0

下载


Video Composer

Batch cut and compose video clips.

Reads information about which video files to cut and at which timestamps from a
CSV spreadsheet.

Writes the cut clips either as separate files or joined in one video.

Uses MoviePy under the hood.

Installation

  1. Install Python >= 3.9.

  2. Install Video Composer as a pip package:

    1. $ pip install -e . # byexample: +pass

    This will make the executable video-composer available globally.

Usage

Input CSV spreadsheet

Video Composer takes a semicolon-separated CSV spreadsheet as its input. It
must have at least three columns:

  • video file path
  • timestamp where to start the cut; format:
    <hours>:<minutes>:<seconds>.<milliseconds>
  • timestamp where to end the cut; format:
    <hours>:<minutes>:<seconds>.<milliseconds>

Optionally, a fourth column can be present:

  • intertitle text

Empty lines and lines starting with # will be ignored.

Example:

  1. # my_composition.csv
  2. foo.avi;00:12:24.677;00:12:40.860
  3. bar/spam.mp4;01:00:03.000;01:05:00.000;"Intertitle text"

Testing videos

Before going on with the usage examples, let’s first generate two testing videos
and an input CSV spreadsheet.

  1. $ mkdir -p test # byexample: +pass
  2. $ cd test
  3. $ [ -f testsrc.mpg ] || ffmpeg -f lavfi -i testsrc=duration=50:size=768x480:rate=25 testsrc.mpg # byexample: +pass
  4. $ [ -f smptebars.mp4 ] || ffmpeg -f lavfi -i smptebars=duration=50:size=768x480:rate=25 smptebars.mp4 # byexample: +pass
  5. $ cat > input.csv <<EOF
  6. > testsrc.mpg;00:00:05,200;00:00:08,900;"Foo!"
  7. > smptebars.mp4;00:00:40,000;00:00:42,500;"Bar, spam..."
  8. > EOF

Basic usage

Cut each source video specified in the input CSV and render each output video as
a separate file:

  1. $ video-composer -v input.csv --output clips # byexample: +pass
  2. $ ls clips # byexample: +norm-ws
  3. smptebars-00_00_40_000-00_00_42_500.mp4
  4. testsrc-00_00_05_200-00_00_08_900.mp4

Cut each source video specified in the input CSV and join all output videos as
one file:

  1. $ video-composer -v input.csv --join output.mp4 # byexample: +pass
  2. $ ls output.mp4
  3. output.mp4

If your source video files are in a different directory, use the option
--clips to specify their location:

  1. $ pushd .. > /dev/null
  2. $ video-composer -v test/input.csv --join test/output2.mp4 --clips test # byexample: +pass
  3. $ popd > /dev/null
  4. $ ls output2.mp4
  5. output2.mp4

Specifying video format

Use the --video-ext option to set the file extension of the file. Video
Composer will then choose the right video codec automatically.

  1. $ video-composer -v input.csv --video-ext webm --output clips_video_format # byexample: +pass
  2. $ ls clips_video_format # byexample: +norm-ws
  3. smptebars-00_00_40_000-00_00_42_500.webm
  4. testsrc-00_00_05_200-00_00_08_900.webm

There are also more options to set the output video FPS, to set the video codec
explicitly and to pass additional parameters to FFmpeg.

  1. $ video-composer -v input.csv \
  2. > --video-fps 10 \
  3. > --video-ext foo.webm \
  4. > --video-codec vp8 \
  5. > --video-params="-vf eq=gamma=1.5" \
  6. > --output clips_video_format_advanced # byexample: +pass
  7. $ ls clips_video_format_advanced # byexample: +norm-ws
  8. smptebars-00_00_40_000-00_00_42_500.foo.webm
  9. testsrc-00_00_05_200-00_00_08_900.foo.webm

Posprocessing

Use the options --resize, --speed and --fadeout to postprocess the video.

When resizing the video, the video will be resized to cover the specified
frame. Anything part of the video that doesn’t fit the frame due to difference
in aspect ratio will be cropped.

  1. $ video-composer -v input.csv \
  2. > --resize 300x300 \
  3. > --speed 0.5 \
  4. > --fadeout 5 \
  5. > --join output_postprocessed.mp4 # byexample: +pass
  6. $ ls output_postprocessed.mp4
  7. output_postprocessed.mp4

Intertitles

Use the option --intertitles to prepend a intertitle clip to each output
video. The default is 5s black video with a white centered text in Arial.

The text is read from the fourth column of the input CSV spreadsheet.

  1. $ video-composer -v input.csv --intertitles --join output_intertitles.mp4 # byexample: +pass
  2. $ ls output_intertitles.mp4
  3. output_intertitles.mp4

You can also specify custom intertitle text color, font, font size, position and
duration.

  1. $ video-composer -v input.csv \
  2. > --intertitles \
  3. > --intertitle-color "#ff0000" \
  4. > --intertitle-font "DejaVu-Serif-Condensed" \
  5. > --intertitle-fontsize 96 \
  6. > --intertitle-position 'top' \
  7. > --intertitle-duration 5 \
  8. > --join output_intertitles_custom.mp4 # byexample: +pass
  9. $ ls output_intertitles_custom.mp4
  10. output_intertitles_custom.mp4

More

See the full list of available options:

  1. $ video-composer -h # byexample: +norm-ws +rm=~
  2. usage: Video Composer [-h] [-i INPUT] [-c CLIPS]
  3. (-o OUTPUT_DIR | -j OUTPUT_FILE) [-vf VIDEO_FPS]
  4. [-ve VIDEO_EXT] [-vc VIDEO_CODEC] [-vp FFMPEG_PARAMS]
  5. [-r RESIZE] [-rw RESIZE_WIDTH] [-rh RESIZE_HEIGHT]
  6. [-sp SPEED] [-fd FADEOUT] [-sb SUBTITLES] [-it]
  7. [-ic INTERTITLE_COLOR] [-if INTERTITLE_FONT]
  8. [-is INTERTITLE_FONTSIZE] [-ip INTERTITLE_POSITION]
  9. [-id INTERTITLE_DURATION] [-v] [-l LIMIT]
  10. [csv]
  11. ~
  12. positional arguments:
  13. csv CSV file with the list of source video paths and
  14. timestamps where to cut them
  15. ~
  16. optional arguments:
  17. -h, --help show this help message and exit
  18. -i INPUT, --input INPUT
  19. [DEPRECATED] Same as the positional argument CSV
  20. -c CLIPS, --clips CLIPS
  21. Directory where to look for the source video files;
  22. defaults to the current directory
  23. -o OUTPUT_DIR, --output OUTPUT_DIR
  24. Write each output video as a separate file in this
  25. directory; Either --output or --join must be
  26. specified.
  27. -j OUTPUT_FILE, --join OUTPUT_FILE
  28. Join all output videos into this one video file;
  29. Either --output or --join must be specified.
  30. ~
  31. video format:
  32. -vf VIDEO_FPS, --video-fps VIDEO_FPS
  33. Output video FPS; defaults to 24
  34. -ve VIDEO_EXT, --video-ext VIDEO_EXT
  35. Output video file extension; defaults to .mp4
  36. -vc VIDEO_CODEC, --video-codec VIDEO_CODEC
  37. Output video codec; defaults to not set, which means
  38. that moviepy will choose the codec automatically
  39. -vp FFMPEG_PARAMS, --video-params FFMPEG_PARAMS
  40. Additional FFmpeg parameters; example: --video-
  41. params="-vf eq=gamma=1.5"
  42. ~
  43. post-processing:
  44. -r RESIZE, --resize RESIZE
  45. Resize output video to passed size in format
  46. WIDTHxHEIGHT; example: --resize 1200x675
  47. -rw RESIZE_WIDTH, --resize-width RESIZE_WIDTH
  48. [DEPRECATED] Use --resize WIDTHxHEIGHT instead
  49. -rh RESIZE_HEIGHT, --resize-height RESIZE_HEIGHT
  50. [DEPRECATED] Use --resize WIDTHxHEIGHT instead
  51. -sp SPEED, --speed SPEED
  52. Change speed of the output video by factor; example:
  53. --speed 1: no change, --speed 0.5: half the normal
  54. speed, --speed 3: three times the normal speed
  55. -fd FADEOUT, --fadeout FADEOUT
  56. Duration of a fade-to-black effect at the end of each
  57. output video; defaults to 0 which means no fade-out
  58. ~
  59. subtitles:
  60. -sb SUBTITLES, --subtitles SUBTITLES
  61. [NOT IMPLEMENTED] Burn subtitles in the video
  62. ~
  63. intertitles:
  64. -it, --intertitles Prepend an intertitle to each output video
  65. -ic INTERTITLE_COLOR, --intertitle-color INTERTITLE_COLOR
  66. Intertitle text color; defaults to white
  67. -if INTERTITLE_FONT, --intertitle-font INTERTITLE_FONT
  68. Intertitle font; defaults to Arial
  69. -is INTERTITLE_FONTSIZE, --intertitle-fontsize INTERTITLE_FONTSIZE
  70. Intertitle font size in px; defaults to 48
  71. -ip INTERTITLE_POSITION, --intertitle-position INTERTITLE_POSITION
  72. Intertitle position; defaults to center
  73. -id INTERTITLE_DURATION, --intertitle-duration INTERTITLE_DURATION
  74. Intertitle duration in seconds; defaults to 3
  75. ~
  76. debugging:
  77. -v, --verbose Enable verbose logging
  78. -l LIMIT, --limit LIMIT
  79. Process maximum this number of clips; defaults to -1
  80. which means to process all clips

Deprecated options

These options are deprecated but available for compatibility with previous
version of Video Composer:

  1. $ video-composer -v -i input.csv -rw 300 -rh 300 --join output_deprecated_options.mp4 # byexample: +pass

Not implemented yet

These options are not implemented yet:

  1. $ video-composer -v input.csv --subtitles test_subtitles.srt --join output_subtitles.mp4 || true # byexample: +pass

Development

Installation

  1. $ make setup-dev # byexample: +skip

Testing and linting

  1. $ make test # byexample: +skip
  2. $ make lint # byexample: +skip
  3. $ make byexample # byexample: +skip

Help

  1. $ make help # byexample: +skip

Contributing

Feel free to remix this piece of software. See NOTICE and
LICENSE for license information.