VideoHelp Forum

Try DVDFab and download streaming video, copy, convert or make Blu-rays,DVDs! Download free trial !
+ Reply to Thread
Results 1 to 16 of 16
Thread
  1. Is there any software that can losslessly crop video? I did a Google search but was surprised not to find anything at all.

    Incidentally, I've read a lot of people saying it's "impossible" to losslessly crop videos. What absolute nonsense! It may be difficult to write the software to do it, but it's certainly not impossible. In theory it's quite simple. Cropping I-frames losslessly is just like cropping a JPEG losslessly. And then for the B- and P- frames, it's simply a matter of adding the missing data back in, so they're no longer dependent on the missing parts of the picture. Far from impossible.
    Quote Quote  
  2. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    You can certainly play a crop of a file on the computer using Avisynth to crop and play back in mpc-hc.
    All you really need is a way to write out the file, but it would be uncompressed (massive). Perhaps there's
    a way with VLC?
    EDIT use Vdub2 and just write the file using a lossless code
    Last edited by davexnet; 13th Jun 2019 at 13:48.
    Quote Quote  
  3. I'm a Super Moderator johns0's Avatar
    Join Date
    Jun 2002
    Location
    canada
    Search Comp PM
    Any video that needs to be cropped has to be re-encoded,if it's nonsense to you that a program should be able to crop it lossless then you should write a program to do this.
    I think,therefore i am a hamster.
    Quote Quote  
  4. Member DB83's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Search Comp PM
    Maybe the OP should expand on his terminology.

    'Lossless' could mean the codec employed and then any vid that does not already have a lossless codec will have to be totally re-encoded.

    He may also mean that the existing video just retains all the current characteristics, codec, bitrate etc so then surely avidemux (if it supports the characteristics) can write the ctopped video back to disks using the 'copy' settings. Yes it is, in a fashion, re-encoded, but not as much as the 'total' example.
    Quote Quote  
  5. I'm a Super Moderator johns0's Avatar
    Join Date
    Jun 2002
    Location
    canada
    Search Comp PM
    The op wants to crop videos with no quality loss such as in muxing and cutting terms,can't be done.
    I think,therefore i am a hamster.
    Quote Quote  
  6. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Originally Posted by johns0 View Post
    The op wants to crop videos with no quality loss such as in muxing and cutting terms,can't be done.
    Wouldn't Avisynth provide no loss of quality, since it provides uncompressed frames to the host program.
    Just crop the vid in the script and encode it to a lossless type such as Lagarith in Vdub2?
    Quote Quote  
  7. Originally Posted by davexnet View Post
    Wouldn't Avisynth provide no loss of quality, since it provides uncompressed frames to the host program.
    Just crop the vid in the script and encode it to a lossless type such as Lagarith in Vdub2?
    Yes, but I doubt he wants to increase the filesize by a factor of 10 or whatever it is.

    He could crop it in an AviSynth script (as mentioned) or in the player, but that's just for playback, and to make a permanent copy at a reasonable size requires reencoding to a lossy codec. I think I remember jagabo mentioning cropping in the video headers or something, but that many (if not most) players wouldn't honor those crops.
    Quote Quote  
  8. Member
    Join Date
    Aug 2006
    Location
    United States
    Search Comp PM
    In this section of a post made in 2010, which I quoted below, jagabo explained why it still isn't possible to find editing software which can losslessly crop any video, even video that uses lossy codecs with interframe compression and motion vectors. It really is too difficult to crop such video without re-encoding it, even now.

    Originally Posted by jagabo View Post
    Originally Posted by live View Post
    It is possible for some lossy compression format to have lossless transform, for instance on JPEG it is possible to do certain crop or 90° rotate in a lossless way, viz without re-encoding. See http://jpegclub.org/losslessapps.html
    Yes, that's possible because a JPG image is a single entity. The compressed data encodes the entire picture. High compression video codecs start with similar compression techniques but on top of that frames can reference other frames. This makes the job much more difficult.

    For example, say a ball was at the very edge of the picture in one frame and at the middle of the picture in the next. The compressed video might recognize the ball is the same and simply say "copy this block of pixels (that contains the ball) from that X,Y coordinate in the last frame to this X',Y' coordinate in this frame." If you crop away the edge of the frame there's no ball in the prior frame anymore. How's the decoder going to know what to put in the middle of the picture? The use of "motion vectors" like this are a large part of video compression. x264 and MPEG2 use it all the time.
    In a section of another post in the same thread jagabo states that in theory, it should be possible to create editing software that is able to losslessly crop MJPEG.

    Originally Posted by jagabo View Post
    Cropping the frame is possible with MJPEG (at least in theory, I don't know of any app that actually does it)...
    [Edit]Re-encoding to crop = A bird in the hand, something that one definitely has access to now. Theoretical lossless cropping = A bird in the bush, something that might be obtainable at some date in the future, possibly the distant future.
    Last edited by usually_quiet; 13th Jun 2019 at 16:25.
    Ignore list: hello_hello, tried, TechLord
    Quote Quote  
  9. As the others have said above - not unless you stay uncompressed or losslessly compressed . You cannot regain the original lossy compression if you started with something lossy .

    Besides temporal compression, Unlike jpeg, typical modern video compression such as AVC, HEVC also have Intra spatial prediction . This prevents you from cropping while still in the lossy compressed state

    Also DCT codecs like AVC, HEVC have are different block sizes , sort of like a jigsaw puzzle. They are not arranged nicely in rows and columns like a rectangle. You can't arbitrarily crop some value without the possibility of cropping inbetween a block .
    Quote Quote  
  10. OK when I said "lossless cropping", I thought that was fairly self-explanatory, but let me just clarify…

    What I mean is to take a lossy video, crop it, and output a new lossy video, without re-encoding it.

    Sure, it will be "re-encoded" in the sense that the software is re-building a new file, with some changes. But it won't be "re-encoded" in the sense of there being any further compression, quality loss, or relative change in the file size.

    The vast bulk of the picture data will be effectively untouched and identical, the only changes being to those blocks which straddle or reference the cropped area, which would obviously have to be adjusted, or split into smaller blocks. That goes without saying.

    There are programs which can losslessly crop lossy files such as JPEGs and mp3s. I assumed there must be some program that can do it with videos - I guess not.

    But I don't see any reason why it's "impossible" as many people claim. "Impossible" is such an absolute statement. It may be difficult to program, but how can anyone say it's impossible?
    Quote Quote  
  11. Originally Posted by Gameshow Host View Post
    The vast bulk of the picture data will be effectively untouched and identical, the only changes being to those blocks which straddle or reference the cropped area, which would obviously have to be adjusted, or split into smaller blocks. That goes without saying.
    That makes it lossy when you use a lossy codec. That goes without saying.

    Let's assume for discussion purposes that you can live with that loss:


    Potentially for AVC that could be 32 pixels if you include the dependent neighbor (max block size is 16x16 for AVC) . HEVC can have 64x64 CTU's , but HEVC extends it 2 rows, so it's 192 pixels potentially affected at the borders .

    Also you're thinking 1 dimensionally . It's a lot more complicated than that. It's a cascading problem

    Inter prediction means other frames can rely on adjacent frames, and not just the frame border edges. Consider sequence where a car goes in an out of the frame left to right. Lets say it's 50% represented on the I frame (half in the frame, but coming farter into the frame the next frame). If you crop that car, it will affect those later frames in the central portion or the frame . So no, not just the borders and the perpheral adjacent area are affected

    Also, modern codecs can use P and B frame references . They don't have to derive everything from the IDR frame . You might have a large residual in a nearby P or B frame used as reference


    But I don't see any reason why it's "impossible" as many people claim. "Impossible" is such an absolute statement. It may be difficult to program, but how can anyone say it's impossible?
    Next to impossible. About as possible as Teleportation or Warp Factor 13
    Quote Quote  
  12. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    We understood you fairly well.

    What you are wanting could be 1: Crop "meta-data" which apply cropping during runtime (or "play"-time). Very few file formats support this. Of those, the only ones that easily support it are MPEG2, MP4 (w h264, h265 encoding), and possibly QT MOV (from which MP4 is based). And probably MKV.
    But, as was mentioned already, finding a player app that HONORS those crop meta-data is what is virtually, if not truly, impossible. Go ahead searching for one that does, but I've been around for a long time here and I don't know of any (certainly not any that do it consistently).

    An alternate option 2: would be what some above were referring to: actual re-encoding but without recompression. This would have to be done in the DCT domain and be based on blocks (so probably would have to be MOD2, MOD4, etc depending on the codec). However, there is currently NO software that I know of (single exception might be some old mpeg2 DCT reencode apps like ReMPEG, but those would ONLY work with MPEG2 of a certain type). It's not "impossible" but unless you want to write it yourself, or commission someone to write it for you, or drum up interest in others for you, there is NOTHING of this sort to help you.

    JPEG does work in the DCT domain in a similar way, but in comparison in terms of complexity of format and complexity of application to modify, it is child's play, plus it has been around for at least 5-7 years longer than good old MPEG2, so has had more time to develop particular edit tools. MP3 has a similar function, and a similar history and a similar (relative) simplicity compared to modern codecs.

    Face it, you can crop & encode, or not crop.

    Scott
    Quote Quote  
  13. metadata method does work consistently for software players - if it's done at the bitstream level , at least for AVC and HEVC (you can use ffmpeg -bsf for example)

    For AVC it works on all typical software players VLC, MPCHC, Potplayer, etc... Browsers like firefox, chrome direct play ok too . HEVC isn't as well supported in browser

    I think some hardware decoders choke on it e.g. some standalone portable players with cheap chipsets . And video editors won't like it, since it's a playback VUI flag. They might crash or show black borders where your crop area is

    So if it's just for playback / viewing pleasure, metadata method is definitely an option
    Quote Quote  
  14. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    I stand corrected. Didn't know they'd improved that much.
    Hope the OP is using software players, then.

    Scott
    Quote Quote  
  15. There are some very common croppings for AVC/HEVC that should work on almost any player. E.g. "1080p" AVC video is really 1088p with crop metadata because AVC works with 16x16 blocks.
    Quote Quote  
  16. Originally Posted by Gameshow Host View Post
    OK when I said "lossless cropping", I thought that was fairly self-explanatory, but let me just clarify…

    What I mean is to take a lossy video, crop it, and output a new lossy video, without re-encoding it.
    ...
    I’m in the same boat, that is, looking for a software that can take a video file, crop it and save to a new file without re-encoding it. That is, saving a new file with the same codec and wrapper as the original one, only a shorter video, or file. (Please ignore the debate of lossy vs. lossless).

    Also, a software that can take few video files of the same resolution, codec and wrapper and join them to a new file without re-encoding it.

    Doing it in the player or browser doesn’t answer my needs. Also, Avisynth without a proper GUI doesn’t work for me, for I’m not into scripting.

    Is there any such solution?
    Quote Quote  



Similar Threads