You are not logged in.

#1 2016-02-02 20:21:37

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,729
Website

Split mp4 video into smaller individual mp4 videos on chapter marks

I have some mp4 videos I created with handbrake which adds chapter marks automatically.  I would like to break the large file into smaller ones based on the chapter marks.  I found this one-liner but it doesn't work as expected.  The sed line is a bit complex for me to understand.  Does anyone have a little script or a URL that will accomplish this?  I'd be happy using ffmpeg or whatever to do it so long as it's lossless.  Thanks!

Some output from the code on that link:

./split_along_chapter_marks.sh 
ffmpeg version 2.8.6 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libdcadec --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-shared --enable-version3 --enable-x11grab
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[NULL @ 0x559af8a247c0] Unable to find a suitable output format for 'Chapter'
Chapter: Invalid argument
ffmpeg version 2.8.6 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libdcadec --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-shared --enable-version3 --enable-x11grab
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[NULL @ 0x56084b8ff7c0] Unable to find a suitable output format for 'start'
start: Invalid argument
ffmpeg version 2.8.6 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libdcadec --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-shared --enable-version3 --enable-x11grab
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[NULL @ 0x55b46ce277c0] Unable to find a suitable output format for 'end'
end: Invalid argument
...

Just running the query command:

% ffmpeg -i "test.mp4" 2>&1 | grep Chapter                                               
    Chapter #0:0: start 0.000000, end 47.000000
      title           : Chapter1
    Chapter #0:1: start 47.000000, end 296.000000
      title           : Chapter2
    Chapter #0:2: start 296.000000, end 547.000000
      title           : Chapter3
    Chapter #0:3: start 547.000000, end 788.000000
      title           : Chapter4
    Chapter #0:4: start 788.000000, end 788.000000
...

I'd like to not reinvent the wheel here but am surprised just how few hits I found on some google searches...

Last edited by graysky (2016-02-02 20:25:34)

Offline

#2 2016-02-02 21:07:58

satanselbow
Member
Registered: 2011-06-15
Posts: 538

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

Grab handrbrake-cli version from the repos and throw this one liner into an incremental loop

HandBrakeCLI -c <chapter#> -i input.mp4 -o <chapter#>.mp4

Note unnecessary capitalisation of binary name - I've got it symlinked to lowercase wink

Last edited by satanselbow (2016-02-02 21:09:58)

Offline

#3 2016-02-02 22:29:21

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,729
Website

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

That rocks, thanks!  I'll not mark it solved just yet to invite other ideas.

Offline

#4 2016-02-03 15:23:55

satanselbow
Member
Registered: 2011-06-15
Posts: 538

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

graysky wrote:

That rocks, thanks!  I'll not mark it solved just yet to invite other ideas.

Not a problem - had to do something similar myself a while back... I kinda guessed that you could look after the loop/counter yourself tongue

Offline

#5 2016-02-03 16:00:13

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,729
Website

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

satanselbow wrote:

Not a problem - had to do something similar myself a while back... I kinda guessed that you could look after the loop/counter yourself tongue

Yeah, for others finding this thread using zsh or bash, just know how many chapters you have (see the command linked in my first post), then:

for i in {1..27}; do HandBrakeCLI -c $i -i test.mp4 -o chapter-$i.mp4; done

Offline

#6 2016-02-03 17:05:42

brontosaurusrex
Member
Registered: 2016-01-11
Posts: 20
Website

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

p.s. To figure out why is ffmpeg complaining is usually a good start to find the exact command line that was passed to it (perhaps throwing in -report switch, which should log stuff > including full command line received).

With other words: separate the script from ffmpeg.

p.s.2. Also the name of the switches change over time, so whatever you find on the internets may not work today anymore.

Last edited by brontosaurusrex (2016-02-03 17:07:53)

Offline

#7 2016-02-03 18:45:42

DrZaius
Member
Registered: 2008-01-02
Posts: 193

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

brontosaurusrex wrote:

p.s. To figure out why is ffmpeg complaining is usually a good start to find the exact command line that was passed to it (perhaps throwing in -report switch, which should log stuff > including full command line received).

-report is too verbose. The default log level is usually sufficient.

Offline

#8 2016-02-03 20:04:34

brontosaurusrex
Member
Registered: 2016-01-11
Posts: 20
Website

Re: Split mp4 video into smaller individual mp4 videos on chapter marks

DrZaius wrote:
brontosaurusrex wrote:

p.s. To figure out why is ffmpeg complaining is usually a good start to find the exact command line that was passed to it (perhaps throwing in -report switch, which should log stuff > including full command line received).

-report is too verbose. The default log level is usually sufficient.

You mean like running complex bash script with set -X?  -report is still better from my experience.  Ffmpeg docs also say that -report verbosity is controlable.

Offline

Board footer

Powered by FluxBB