Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: MP4Box: -splitx or -splitz for extracting? (Read 13190 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

MP4Box: -splitx or -splitz for extracting?

I want to extract losslessly subfiles from MP4 videos with MP4Box.

Two switches I could use for this purpose:

Quote
-splitx StartTime:EndTime: extracts a subfile from the input file.
StartTime and EndTime are specified in seconds.
Depending on random access distribution in the file (sync samples), the startTime will be adjusted to the previous random access time in the file.

-splitz StartTime:EndTime : extracts a subfile from the input file.
StartTime and EndTime are specified in seconds.
Depending on random access distribution in the file (sync samples), the startTime will be adjusted to the previous random access time in the file, and the endTime will be adjusted to the last sample before the last RAP in the extracted chunk.

So -splitz is the same as -splitx, only that -splitz adjusts the end time to be before the last RAP sample.

I am new to video editing. I don't understand the importance of adjusting the end time to be or not to be before this last random access point.

What I would like to get are mp4 files which comply with the mp4 file format specification, so that common video player software will play them trouble-free. 

So which of these two switches should I use, -splitx or -splitz?

Re: MP4Box: -splitx or -splitz for extracting?

Reply #1
When I looked into this I found that MP4Box didn't accurately cut/split files (keyframes issue?).

So I used ffmpeg and found it be accurate. I wrote a script to do this for Windows.
To note: it's been written to process all .mp4 files in the directory/folder.

Code: [Select]
:: Name:     mp4-split-ffmpeg.cmd
:: Purpose:  Configures ffmpeg to losslessly split/crop an mp4 file
:: Author:   jaybeee @ themixingbowl.org
:: Revision: Nov 2015 - v0.1

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:: variables begin with v

:: set name of this script without file extension
SET vMe=%~n0

:: set name of the parent directory where this script resides
SET vParent=%~dp0

:: set location of ffmpeg ** CHANGE ME **
SET vffmpeg="C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe"


:: Ask for the user to enter the Start & End times in hours, minutes, seconds
echo ** Enter Start Time of where to begin split in hh mm ss.mmm format when prompted **
SET /p vShh="Start Time (hh): "
SET /p vSmm="Start Time (mm): "
SET /p vSss="Start Time (ss.mmm): "

echo ** Enter End Time of where to end split in hh mm ss.mmm format when prompted **
SET /p vEhh="End Time (hh): "
SET /p vEmm="End Time (mm): "
SET /p vEss="End Time (ss.mmm): "

:: convert Start & End input time to seconds
SET /A vStart=(%vShh%*3600)+(%vSmm%*60)+(%vSss)
SET /A vEnd=(%vEhh%*3600)+(%vEmm%*60)+(%vEss)

:: set this variable to Start Time minus 1 second for the fastest seek time
SET /A vFastSeekStart=%vStart%-1

ECHO ffmpeg will now split the file starting at %vStart% seconds and ending at %vEnd% seconds...
ECHO %vFastSeekStart%

:: call ffmpeg to split/crop (copy) out the audio using -ss (start time) & -to (end time) (-t [duration time]) 
:: time can be: [HH:MM:SS.mmm] eg 01:59:58.123 OR in seconds: [S+.mmm] eg 7198.123
:: Please note: -hide_banner will suppress printing the banner info. Ensure you are running an up to date ffmpeg version
MKDIR split-mp4
FOR %%f IN ("*.mp4") DO %vffmpeg% -i "%%f" -ss %vStart% -to %vEnd% -codec copy -movflags faststart -hide_banner "split-mp4\%%~nf-split.mp4"

:: Finish
ECHO Finished mp4 split

:: pause can be used to view the extraction details
PAUSE

:END
ENDLOCAL
ECHO ON
@EXIT /B 0

I've also just had a test with the latest MP4Box and on the files I tested on it resulted in the same split file, so maybe I've not found a good test file or they've resolve any issues they had. To answer your question I use -splitx. Anyway, here's the MP4Box Windows script I created :

Code: [Select]
:: Name:     mp4-split.cmd
:: Purpose:  Configures mp4box to extract a new mp4 file using the user entered Start & End time values
:: Author:   jaybeee @ themixingbowl.org
:: Revision: Aug 2016 - v0.1

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:: variables begin with v

:: set name of this script without file extension
SET vMe=%~n0

:: set name of the parent directory where this script resides
SET vParent=%~dp0

:: set location of mp4box ** CHANGE ME **
SET vmp4box="C:\Program Files\GPAC\mp4box.exe"

:: Ask for the user to enter the Start & End times in hours, minutes, seconds
echo ** Enter Start Time of where to begin split in hh mm ss format when prompted **
SET /p vShh="Start Time (hh): "
SET /p vSmm="Start Time (mm): "
SET /p vSss="Start Time (ss): "

echo ** Enter End Time of where to end split in hh mm ss format when prompted **
SET /p vEhh="End Time (hh): "
SET /p vEmm="End Time (mm): "
SET /p vEss="End Time (ss): "

:: convert Start & End input time to seconds
SET /A vStart=(%vShh%*3600)+(%vSmm%*60)+(%vSss)
SET /A vEnd=(%vEhh%*3600)+(%vEmm%*60)+(%vEss)

ECHO MP4Box will now split the file starting at %vStart% seconds and ending at %vEnd% seconds...

:: call mp4box to extract a new file using -splitx from Start to End in seconds
MKDIR split-mp4
FOR %%f IN ("*.mp4") DO %vmp4box% -splitx %vStart%:%vEnd% "%%f" -out "split-mp4/%%~nf.mp4" -new

:: Finish
ECHO Finished splitting mp4

:: pause can be used to view the extraction details
PAUSE

:END
ENDLOCAL
ECHO ON
@EXIT /B 0