Content-type: text/html Manpage of mpgedit

mpgedit

Section: User Commands (1)
Index Return to Main Contents
 

NAME

mpgedit - MPEG 1/2/2.5 audio file editor

 

SYNOPSIS

mpgedit -h | -V | [ -c [inputfile1 [inputfile2...]]]

mpgedit [-s] [-v[v[v]]] [-p] [-e [start[-[end]]]] [-X[0|1]] [-f] input_file [-o [+]outfile_name ]

 

DESCRIPTION

mpgedit is an MPEG 1 layer 1/2/3, MPEG 2, and MPEG 2.5 audio file editor that is capable of processing both Constant Bit Rate (CBR) and Variable Bit Rate (VBR) encoded files. mpgedit can cut an input MPEG file into one or more output files, as well as join one or more input MPEG files into a single output file. When editing VBR files that have a XING header, mpgedit updates the output file's XING header information to reflect the new file size and average bit rate.

When editing a file, mpgedit locates the nearest MPEG frame boundary for the desired start and end times, then copies the frames between these times to the output file. Since no file decoding / encoding occurs during editing, there is no audio quality loss when editing with mpgedit. For each file being edited, a time index file is created that stores the file position, in bytes, for every 1 second of play time. Indexing guarantees correct and fast random access to edit time offsets for VBR-encoded files.

mpgedit file playback allows edit-time auditioning, which insures that desired cut occurs at the correct time offset. This feature is necessary when making edits that demand sub-second accuracy (especially with VBR files). Since most MP3 players display playback run times based on a VBR file's average encoded bit rate, edits based on these players' displayed times can miss the desired start or stop time by many seconds.

It is not necesary to use the playback functionality to make edits when the edit start and stop times are already known. The playback feature is merely an aid for accurately locating the desired edit start and stop times.

mpgedit operates in two modes: a command line and a curses-based, full-screen interactive shell. All editing functionality is available in both modes. The chief advantage of the interactive mode comes when using the playback feature for selection and verification of edit begin and end times, which is more rapidly performed interactively.  

COMMAND LINE OPTIONS

Command line mode has the following options available:
-c [input file] [input file 2] ... [input file N]
Curses edit mode. Enter a full-screen, interactive editing session to play back input files and set begin and end times for each edit. This mode is the default action when no arguments are supplied.
-e start[-[end]]
Perform copy/paste operation on input files. The input MP3 file may be encoded as either CBR or VBR. For quick and accurate random access to VBR-encoded files, an external time index file is created. The index file uses the basename of the input file with the '.idx' extension.
       The output files created by this option are located in the same directory as the input MPEG file. When the input directory is read-only, the output is written to the current working directory. When the -o option is not used, the copy/paste data is written to a file with the same basename as the input file with the '_nn.mp3' extension, where nn is an integer value. When a file named basename_nn.mp3 already exists, the integer nn is incremented until the filename is unique. The input MPEG file is never overwritten by this option.
       When only a start time is specified, the copy/paste operation is performed from that start time through the end of file. When just an end time is specified, the copy/paste operation is performed from the beginning of the file through the specified end time. When both start and end times are specified, the portion of the file bracketed by these times is copy/pasted. Start and end times is specified in seconds, or MM:SS.mmm, where MM is minutes, SS is seconds, and mmm are milliseconds. Although any millisecond value may be specified, it will always be rounded off to the next frame boundary, approximately 26ms.
       Multiple -e options are allowed. Each -e represents a separate edit that will be performed on the named input file. When multiple -f options are present, the -e options immediately preceeding each -f option apply to that input file.

-f input file name
Use the named input file. Multiple -f options are allowed. At least one -e option must be precede each -f option.

If multiple input files are specified, all -e options in a group apply to the -p immediately following a group of -e options. For example:

mpgedit -e 2-12 -f foo1 -e 20-30 -f foo2

-e 2-12 applies to foo1, -e 20-30 applies to foo2.

-o output file
Use the named output file. Prefixing a + to filename causes output from an edit to be appended to the output file. XING headers are automatically updated when using this option.
-h Display help information.
-V Display mpgedit version.
-p Play MPEG file using external player.
-s Silent operation.
All of the normal informational messages are suppressed during indexing and editing.
-v Verbose output. Adding another v increases verbosity.
Up to -vvv is allowed. -v displays the frame count and file offset at one second increments. -vv adds the following information for each frame: time offset, bitrate, frame size, frame count, frame position. -vvv adds to -vv and displays a detailed breakdown of each MPEG frame header.
-X[0|1]
Manipulate XING header. 0 omits the XING header prefix, allowing output to be appended to the end of a previous edit. 1 fixes the XING header after catenating edits. This option is largely obsolete because of the '+' option to -o.

 

INTERACTIVE MODE COMMANDS

Interactive mode uses single key commands to control editing functionality. Command key binding are similar to vi edit commands. Interactive mode has the following edit commands available:

 

CURSOR MOVEMENT

Arrow_Down
Same as j.
Arrow_Left
Same as h.
Arrow_Right
Same as l.
Arrow_Up
Same as k.
k, Arrow_Up
Move the cursor up one line.
j, Arrow_Down
Move the cursor down one line.
l, space, Arrow_Right
Move the cursor right one field on the current line.
h, Arrow_Left
Move the cursor left one field on the current line.
TAB
Toggle between start and end time fields.
H
Move the cursor home to the first line in the editor.
G
Move the cursor to the last line in the editor.

 

EDITING COMMANDS

ESC
Undo any changes to the current line. All changes can be undone until the cursor is moved to another line.
,
Decrease selected time field by one count.
.
Increase selected time field by one count.

For each of the start and end time input fields, the minute, second, and millisecond values can be modified. The desired numeric value can be directly input from the keyboard, or the current value can be modified by incrementing or decrementing the current value up with the . command and down with the , command.

c
Clear currently selected start or end time. All three time components (minutes, seconds and milliseconds) are reset to zero when the c command is entered. Only the currently selected start or end field is cleared with the c command.
P
Paste the previously deleted line above the cursor position.
p
Paste the previously deleted line below the cursor position.
O
Insert a new line above the cursor position.
o
Insert a new line below the cursor position.
D
Delete the line at the cursor position.
n
Specify the output file to save all specified edits to. This name must be specified before the e (perform edit) command will function.
f
Edit the input filename field. Entering a ^U (ctrl-U) key deletes all characters in the field. Entering a Backspace key deletes only the previous character. Arrow_Left and Arrow_Right positions the cursor within the name field. Characters are added in insert mode, and will not over write following characters. ESC will undo changes and exit the field. Enter will accept the current value as the input filename. The named input file will be indexed when the Enter key is pressed, if the index file does not already exist.
s
Play the input file at the time specified in the currently selected start or end time field. Playback will continue until any key is pressed. Playback will pause when the Enter key is pressed, and will resume with another Enter key press. During playback, the current time offset is displayed at the bottom of the screen.

The chief advantage of the s command is the ability to rapidly select a start or end time, begin and end playback, modify the time, and play back again. By repeating these steps, the precise time can be located.
S
Play the input file up to the time specified in the currently selected start or end time field. Playback will begin at 5 seconds before the selected time, and will stop at the selected time.

This feature is useful when searching for a break between two music selections, where the previous piece ends loudly and the next piece begins softly. Playing back a few seconds before the edit end time enables precisely locating breaks between pieces of music.
L
Load edit files and times from a previous mpgedit session. All edit file names and times are saved when exiting an interactive session with the e, E and q commands. The L command loads these saved edit specifications for subsequent modification.
Q
Quit all edits and discard changes. All work performed during the current interactive session is discarded with this command, so use it with caution.
q
Quit an interactive edit session and save the current edit files and times. This saved information can be loaded with the L command to resume the edit session at a later time. None of the MPEG file edits occur when using this command. mpgedit prompts for the name of the file to save the edit specifications to. When this file already exists, mpgedit prompts for whether to over write the file. To save to a different file answer no, then q again and modify the save filename.
e
Perform MPEG file edits using current input file and time specifications. The edits are saved to the output filename specified by the last n command. An output name must be specified with n before e will perform any edits. All input file names and edit times are saved, as with the q command, before the MPEG file edits are performed.
E
Perform MPEG file edits using current input file and time specifications. The edits are saved to default output filenames. The default output filenames are the same basename as the input file, with the '_nn.mp3' extension appended, where nn is a unique integer value. All input file names and edit times are saved, as with the q command, before the MPEG file edits are performed.
 

EXAMPLES

mpgedit -e-6.500 -e6.500-12.500 -e12.500-19 -e19- test1.mp3

Cut the file test1.mp3 into 4 pieces. The first cut starts at the beginning of test1.mp3, and ends at 6 1/2 seconds; cut 2 begins at 6 1/2 seconds, and ends at 12 1/2 seconds; cut 3 begins at 12 1/2 seconds and ends at 19 seconds; cut 4 begins at 19 seconds and includes the remainder of test1.mp3.

mpgedit -o output.mp3 -e- test1_1.mp3 test1_2.mp3 test1_3.mp3 test1_4.mp3

Join four MP3 files together into a single output file. The edit time specification -e- means start from the beginning of the file and run through to the end of the file. In this example, only one edit time specification is needed, and is applied to all input file names that follow. Note the -f option can be omitted when the remainder of the command line is input file names. each file.

mpgedit -e19- -f output.mp3 -e-6.500 -f test1.mp3

This example joins cuts from two different files. The first cut is from output.mp3, start at 19 seconds and ending at the end of file. The second is from from test1.mp3, starting at the beginning of the file and ending at 6 1/2 seconds. The default output filename is used (output_1.mp3). The cuts from both input files are stored in output_1.mp3 because the first cut ends at the end of file and the second cut starts at the beginning of file.

mpgedit -e-6.500 -e12.500-19 -f test1.mp3 -e2.500-6 -f test2.mp3

Create 3 cuts, two from test1.mp3, one from test2.mp3. In this case, the default output file names are created, resulting in the three cuts stored in test1_1.mp3, test1_2.mp3, and test2_1.mp3, respectively.

mpgedit -o edits.mp3 -e-6.500 -e12.500-19 -f test1.mp3 -e2.500-6 -f test2.mp3

Performs the same edits as the previous example, but saves the edit results in one output file, named edits.mp3.

mpgedit -e19- -p test1.mp3

Begin sound playback from the file song1.mp3 beginning 5 minutes 55 seconds in the file.

mpgedit -vvv elgar.mp3

Parse MPEG audio file frames, and display frame information. This example demonstrates the output displayed when -vvv is used. For the purposes of this discussion, lines tagged with (1), (2) and (3) correspond to -v, -vv and -vvv respectively; the (1), (2) and (3) do not appear in the actual output.


Found xing header
h_id      = 1
h_layer   = 3
h_protect = 0
samprate  = 44100
flags     = 15
frames    = 18146
bytes     = 9238103
vbr_scale = 44

             ...


(1)   *** t=1s fr=39 pos=22232 (0x56d8)
(2) MPEG header t=1.044s  br=192  sz=626  fr=40     pos=22232      pos=0x56d8
(3) File position:  0      (0x0)
(3) Frame size:     626    (0x272)
(3) MPEG version:   3      (MPEG Version 1)
(3) MPEG layer:     1      (Layer III)
(3) Protection:     0      (no)
(3) bitrate:        11     (192)
(3) sample_rate:    0      (44100)
(3) Pad:            0      (no)
(3) Private:        0      (no)
(3) channel_mode:   1      (Joint stereo)
(3) joint_ext_mode: 0      (Intensity stereo off; Mid-side stereo off)
(3) Copyright:      0      (no)
(3) Original:       1      (yes)
(3) Emphasis:       0      (None)


             ...

File name:    elgar.mp3
VBR Min:      80
VBR Max:      192
VBR Average:  150
Total frames: 15584
File size:    7623958
Track length: 6:47.85 (407s)

Variable Bit Rate frame statistics
Bit Rate      Frame Count
-------------------------
 80 kbps:          1 (<1%)
 96 kbps:         27 (<1%)
112 kbps:        733 (4%)
128 kbps:       4169 (26%)
160 kbps:      10196 (65%)
192 kbps:        458 (2%)

The message Found xing header indicates the input file is a VBR encoded files with a XING ancellary data header. The only two fields updated by mpgedit are the frames (number of frames in encoding) and bytes (total encoding size in bytes) fields. h_id indicates the MPEG version; only 1=MPEG-1 is recognized. h_layer indicates the MPEG layer; valid values are 1, 2 and 3. h_protect is 1 when the copyright protection is enabled, and 0 when not enabled. samprate is the audio sample rate for the encoding, in hertz (Hz). Both flags and vbr_scale are values internal to the header.

When the -v option is used, only lines with the (1) tag in the example above are displayed. These lines are displayed for each one second of input file play time. t= is the time offset into the input file. fr= is the frame number for this time offset. The file position in bytes (in both decimal and hexidecimal formats) follows pos=.

When the -vv option is used, lines with the (2) tag are displayed in addition to the (1) tag. One (2) line is displayed for each frame present in the MPEG input file. t= is the time offset into the input file, and is displayed with 1 millisecond resolution. br= is the frame encoding bitrate, in kb/s. sz= is the frame size, in bytes. fr= is the frame number for this time offset. pos= is the file position in bytes,displayed in both decimal and hexidecimal formats.

When the -vvv option is used, lines with the (3) tag are displayed in addition to the (1) and (2) tags. These additional lines display all information contained within an MPEG frame, and are displayed for each frame present in the file. Each value is identified by name, followed by the un-interpreted value, followed by the interpreted value, appearing within parentheses.

For all -v options listed above, a summary is printed after the entire file is read. For CBR encoded files, the file name, frame count, file size and play time are displayed. For VBR encoded files, the frame minimum, maximum, and average encoding bitrate is displayed, in addition to the CBR summary. Furthermore, for VBR encoded files, a summary of the total number of frames encoded for each bitrate present in the input file is displayed.

 

PLAYBACK CONFIGURATION

mpgedit requires configuration for the sound playback feature to work. As root, run make install. For Linux as part of the installation, the shared library loader is configured to search the directory where mpgedit was installed. These are the actions performed by the install process to configure the shared library loader:

    echo /usr/local/lib >> /etc/ld.so.conf
    /sbin/ldconfig

Sound playback is implemented using two mechanisms: 1) an external command line MP3 player capable of standard input file playback, and 2) the MPGLIB decoder library that ships with the LAME project. The default playback configuration uses the MPGLIB-based decoder plugin libdecoder_mpg123.so.

Two decoder plugin implementations ship with mpgedit: libdecoder_popen.so and libdecoder_mpg123.so. libdecoder_popen.so will execute the mp3decoder.sh script for file playback. libdecoder_mpg123.so is implemented using the MPGLIB decoder library present in LAME. This implementation also serves as a sample implementation of a single process playback plugin that could be ported to the Microsoft Windows(R) operating systems, and other operating systems that do not support the popen() system call.

mpgedit attempts to load the playback plugin libmpgedit_decoder.so when file playback is specified. When the decoder plugin is loaded, it is used for file playback. When the decoder plugin cannot be loaded, the default action is to execute the mp3decoder.sh script.

libmpgedit_decoder.so is installed as a symbolic link pointing to one of the playback plugins, libdecoder_mpg123.so or libdecoder_popen.so. make install installs the libdecoder_mpg123.so playback plugin. libdecoder_popen.so can be installed manually when use of a command line MP3 player is desired.

To use a different command line MP3 player, configure libdecoder_popen.so as the playback plugin, then edit the mp3decoder.sh file to call the desired MP3 player. This shell script is then loaded by mpgedit when performing file playback, and provides the flexibility to specify any MP3 player that can play files from standard input.  

IMPLEMENTATION LIMITATIONS AND ANOMALIES

The editing functionality has been tested with MPEG 1 layer 2 and 3 files, and MPEG 2 files. Since MPEG 1 layer 1 and MPEG 2.5 files have the same frame header structure, it is assumed this program will function properly with such files, although no testing on files encoded with this format has occurred.

While it is possible with mpgedit to join together files that consist of differing encoding versions (MPEG-1 and MPEG-2, for example) and sample rates (44.1KHz and 22.05KHz, for example), caution must be used. Although such a file is technically a legal encoding, it is doubtful that all (or any, for that matter) MP3 players will be able to correctly render such a file.

Any ID3 tags present in input files are not present in the output from an edit. Output files must be tagged to restore ID3 information.

mpgedit implements an MPEG audio frame header parser that is tolerant of many encoder errors, corrupted data, and files with formats that are not strictly MPEG audio files. When such an encoding error is encountered, all data between the last correctly encoded frame and the next recognized frame are silently skipped. Other programs, such as mp3_check, perform a more detailed validity check and report where errors occur, and are likely to be more robust when handling corrupted data files.

The biggest known limitation of mpgedit is with file play back. Some MPEG files encoded with sample rates other than 44.1KHz and 22.050KHz do not properly play back, if at all. This is a limitation of mpg123, or the version of the MPGLIB decoder library currently available. The same files do properly playback with XMMS. Since the vast majority of MPEG audio files are encoded at 44.1KHz and some at 22.050KHz, this limitation is not a major concern.

During development, the previous name of the program was mp3edit. The final name mpgedit was settled on after much development occurred. Because of this, many source files and function names are called mp3_. You will also see mpeg_ instead of mpg_ in some cases.

 

ACKNOWLEDGEMENTS AND HISTORY

The first prototype implementation of MP3 file editing was based upon the mp3_check program, written by Eric Bullen, http://sourceforge.net/projects/mp3check. Because the project goals of mp3_check are different than mpgedit, the idea of integrating editing functionality into mp3_check was abandoned. Many of the current command line options for mpgedit can be traced to the early prototype work done with mp3_check.

mpgedit is a completely independent implementation from the early mp3_check editing prototype. While some of the early ideas from this prototype still exist in mpgedit, everything has been re-implemented.

Finding reference material sufficiently complete to implement mpgedit was difficult. The O'Reilly & Associates book "MP3: The Definitive Guide" by Scot Hacker http://www.oreilly.com/catalog/mp3/, while accurate in its description of the MPEG audio file frame header structure, did not contain sufficient detail to fully implement the MPEG file parsing functionality. The document that proved invaluable for completing the MPEG audio frame header parsing code was written by Predrag Supurovic, http://www.dv.co.yu/mpgscript/mpeghdr.htm.

The MPGLIB decoding engine comes from the MPG123 package, written by Michael Hipp (www.mpg123.de). MPGLIB is released under the GPL. The version of MPGLIB used for building the libdecoder_mpg123.so decoder plugin comes from the 3.90 alpha 7 version of LAME http://sourceforge.net/projects/lame. Earlier versions of LAME do not include a shared library build of MPGLIB, which is needed when building the decoder plugin. The MPGLIB that comes with mpg123-0.59r can also be used when linking the libdecoder_mpg123.so plugin. However, LAME appears to have fixed some bugs that mpg123 has not.

 

SEE ALSO

mp3decoder.sh(1), decoder.so(1), decoder_popen.so(1), decoder_mpg123.so(1)


 

Index

NAME
SYNOPSIS
DESCRIPTION
COMMAND LINE OPTIONS
INTERACTIVE MODE COMMANDS
CURSOR MOVEMENT
EDITING COMMANDS
EXAMPLES
PLAYBACK CONFIGURATION
IMPLEMENTATION LIMITATIONS AND ANOMALIES
ACKNOWLEDGEMENTS AND HISTORY
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 07:45:32 GMT, May 15, 2002