Editing a video requires re-encoding it, which leads to degradation and quality loss. However there are tools to manipulate video in a lossless manner, and without re-encoding it.
Editing video with MP4Box
The video manipulation program MP4Box is a feature packed command line mp4 video file manipulation program. Some useful features include:
Clipping
You can extract a segment of a video with the -split-chunk option:
mp4box -split-chunk start:end inputfile.mp4 -out outputfile.mp4
where start and end are the integer values in seconds of when to start and end the segment to split.
You can also clip using FFmpeg
ffmpeg -ss hh:mm:ss.s -i inputfile.mp4 -c copy -t hh:mm:ss.s outputfile.mp4
Where hh:mm:ss.s is the start time for -ss
and the duration for -t
. You can also use the option -to
to specify the end of the clip, instead of the duration.
Splitting tracks
You can extract video or audio tracks from a mp4 file using the -raw option. First examine the tracks with
mp4box -info file.mp4
choose a track to split, and use for example
mp4box -raw 1 file.mp4
to split the first track. You can also extract the audio track with FFmpeg, with the command
ffmpeg -i input.mp4 -vn -acodec copy output.aac
Combining tracks
If on the other hand you want to re-combine tracks you can use the -add
option to add a track to a video. You could for example split an audio track, enhance it using an audio editor such as Audacity, save it and add it back to the video track.
There are many other options to MP4Box, so you should definitely check the documentation.
Replace a video's audio
Using FFmpeg you can substitute a video audio track with another file, without re-encoding.
ffmpeg -i input.mp4 -i input_audio.m4a -acodec copy -vcodec copy -map 0:v:0 -map 1:a:0 output.mp4
Explained here.
Mirroring a video
If a video is filmed using the front camera of a cell phone the video it will have the left and right hand side mirrored. You can restore the proper orientation flipping the video horizontally with FFmpeg, using the command
ffmpeg -i input.mp4 -vf hflip -c:a copy output.mp4
FFmpeg can work with most video file formats, but note that it will often re-encode the output, so the result won't be lossless.