A command-line tool for surgical I-Frame removal, so-called datamoshing.
Comes with built-in scene cut detection for optimal results.
Aside from the moshpit binary, which can be downloaded from the releases page, you need a copy of FFmpeg installed on your machine.
moshpit [options] <file>
moshpit takes the video file you want to mosh as the last argument.
Option | Description | Default |
---|---|---|
-ffmpeg | Specifies the location of the FFmpeg binary. | ffmpeg |
-log | Specifies the target location of the FFmpeg log file. | no logging |
After starting moshpit, you can use the following commands to create a datamoshed video:
scenes <threshold>
Datamoshing via I-Frame removal yields the best results when applied at scene cuts.
The scenes
command finds scene cuts in the input file, using the threshold parameter
to determine the similarity of each frame with the preceding frame.
A threshold of 0.2
usually gives good results.
mosh <output> <frame> [frame...]
Moshes the input file, writing it to the specified output file.
I-Frame removal is performed at the given frame indices,
with scene cuts previously detected using the scenes
command being suggested.
Using all
as a frame parameter performs I-Frame removal at all previously detected scene cuts.
Exits moshpit.
Moshpit can also be terminated at any time using Ctrl+C
(SIGINT
).
Modern compressed video files have very complex methods of reducing the amount of storage or bandwidth needed to display the video. To do this most formats, such as the AVI format, don't store the entire image for each frame.
Frames which store an entire picture are called I-frames (Intra-coded), and can be displayed without any additional information.
Frames which don’t contain the entire picture require information from other frames in order to be displayed, either previous or subsequent frames, these frames are called P-frames (Predicted) and B-frames (Bi-predictive). Instead of storing full pictures, these P-frames and B-frames contain data describing only the differences in the picture from the preceding frame, and/or from the next frame, this data is much smaller compared to storing the entire picture — especially in videos where there isn’t much movement.
When a video is encoded, or compressed, a combination of these types of frames are used. In most cases this means many P-frames with I-frames interspersed at regular intervals and where drastic visual changes in the video occur. More information on frame types can be found here.
If an I-frame is corrupted, removed or replaced, the data contained in the following P-frames is applied to the wrong picture. In the above video I-frames have been removed and so instead of scenes changing properly you see the motion from a new scene applied to a picture from a previous frame. This process of corrupting, removing or replacing I-frames is the video datamoshing technique that moshpit uses.
When running the mosh
command, moshpit converts the input file into an AVI file,
placing I-Frames only at the frames specified by the user.
This is done because single frames can be very easily identified and changed in the AVI format.
Each of the I-Frames in the resulting AVI file is then replaced with the next P-Frame, which means that the moshed video has the same duration as the original video, as opposed to removing the I-Frames, which would cause the moshed video to be shorter.
Finally, the moshed AVI file is "baked", which means it's converted back into an MP4 file, persisting the artifacts in the AVI file into a stable video file.
go get github.com/CrushedPixel/moshpit/cmd/moshpit