7
$\begingroup$

I'd like to produce a video that looks 'corrupted' in some way, ideally like the sorts of MPEG corruptions you see occasionally. See this for examples: https://www.youtube.com/watch?v=i-bz21deEeY

At the moment I'm taking an image and making it look corrupt artistically by randomly flipping sub-images like this:

SubimageApply = ResourceFunction["SubimageApply"];
subflip[img_] := 
 With[{pts = RandomPoint[Rectangle[{0, 0}, ImageDimensions[img]], 2]},
  SubimageApply[
   ImageAdjust[
     ImageReflect[#, RandomChoice[{Top, Bottom, Left, Right}]]] &, 
   img, Rectangle @@ pts]
  ]
img = ExampleData[{"TestImage", "House"}];
Export["corrupted.mp4",
 Table[Nest[subflip, img, 50], 60]
]

random sub-flips

However, I'd like to produce more realistic looking video corruptions that look a bit more like real-life decoder errors. There's some more info here and here about artistic techniques.


I've also tried just adding some rare bit-flips to an existing video file like this:

img = Rasterize[
   Graphics[{Texture[ExampleData[{"TestImage", "Sailboat"}]], 
     FilledCurve[{BezierCurve[{{-1, 0}, {0, 1}, {1, 0}}]}, 
      VertexTextureCoordinates -> {{0, 0}, {1/2, 1}, {1, 0}}]}]];
frames = Table[
   ImageRotate[img, i Degree, Background -> White], {i, 0, 360, 6}];
Export["myvideo.mp4", frames, FrameRate -> 30];
vidData = BinaryReadList["myvideo.mp4"];
SeedRandom[1];
vidData = 
  Mod[vidData + 
    PadLeft[RandomVariate[BernoulliDistribution[.001], 
      Length[vidData] - 1000], Length[vidData]], 256];
file = File["corruptedVideo.mp4"];
BinaryWrite[file, vidData];
Close[file];
Video["myvideo.mp4"]
Video["corruptedVideo.mp4"]

This turns this animation:

clean mp4

... into this corrupted animation:

corrupted mp4

This is a bit ham-fisted and unreliable. Any other ways to tamper with the motion compensation of a video from Mathematica, or other artistic effects that one might consider 'glitchy' would be interesting to see.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.