Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Programming IT Technology

Tools for Manipulating MPEG Headers? 21

mattjarvis asks: "Does anyone out there know of a software solution for batch manipulating MPEG file headers, ie. stripping the header and replacing it with another header, or editing the existing header. I've searched the usual places, and have come up with a few libraries that look like they are capable of doing this but I don't seem to be able to find anything already written to do this. Basically I have a client using a hardware MPEG audio recorder, who wishes to change one of the bits in the header ( the original/home bit ) which is causing some problems with other software they are using. Surely this should be relatively simple to achieve and it's possible that I am missing the obvious but there doesn't seem to be anything available open source or not to easily edit the header without reconverting the actual audio stream."
This discussion has been archived. No new comments can be posted.

Tools for Manipulating MPEG Headers?

Comments Filter:
  • If they know the exact bit to twiddle, it shouldn't be too hard to write a program which opens the file, flips the bit, and closes the file again (a one-liner, if you start sufficiently far to the left :-) ). Or am I missing something?
    • what you're missing is that there's an mpeg header for every mpeg frame in the file. you have to scan to find the first frame (sometimes at the beginning of the file, sometimes after some cruft like id3 tags) then go through, and for each frame, flip the bit, then read the headers to see where the frame ends and the next frame starts.
  • Use the power of C! (Score:4, Informative)

    by theCoder ( 23772 ) on Thursday November 14, 2002 @08:33AM (#4667286) Homepage Journal
    You just want to do a simple operation on a whole bunch of files. Normally, you'd probably want a shell script, but since what you're doing (changing a bit) is fairly low level, you should probably consider a quick C program. I'll even block it out for you:
    int main(int argc, char** argv)
    {
    // for each argument (that's a file)
    {
    // mmap the file
    // flip the bit (you know the offset, right?)
    // sync and un map the file
    }
    printf("Done!\n");
    return 0;
    }
    Now, that wasn't that hard, was it? You don't ALWAYS have to find third party tools to do your job for you.

    • by Anonymous Coward
      The mpeg audio format has a header for each frame. To do it right, you have to step through the file frame by frame and flip the bit in each frame's header. That's a fairly easy operation on a correct standards compliant file, but when you're dealing with corrupted or otherwise incorrect data (unspecified tags in the stream for example), you have to resync the stream, which sounds easier than it is. Simply looking for the $fff sync sequence isn't always the best method.
    • by sarabob ( 544622 ) on Thursday November 14, 2002 @09:18AM (#4667433)
      erm... no.

      MPEG headers aren't just at the beginning of the file. You'd have to watch the transport stream for video packets, watch for video headers, and *then* flip the bit. For each one throughout the stream.

      Most available software will want you to strip the transport stream into video/audio elementary streams before doing anything further. You would then work on the video stream and finally remux.
      • by sarabob ( 544622 )
        Hnnng. thought we were dealing with a/v streams, not just audio...
        • it still applies. you'd have to flip the bit in every audio frame header. i looked at doing this sort of thing a while ago, but decided that i didn't have time to do one with all the features i wanted to put in. now that i'm out of school i just might, though.
    • I'll help you out (Score:5, Informative)

      by Chris Pimlott ( 16212 ) on Thursday November 14, 2002 @09:39AM (#4667528)
      here is all the information you should need. [mpgedit.org] I used it myself when making a mp3-inspecting program.
  • by Gothmolly ( 148874 ) on Thursday November 14, 2002 @09:59AM (#4667612)
    man dd
    find the bits you're looking for and swap them around, done.

    Bonus Karma for people who know where the subject is quoted from.
  • by Tom7 ( 102298 ) on Thursday November 14, 2002 @11:42AM (#4668519) Homepage Journal

    Is this a "copyright" bit? (Like the bit set when you make a digital copy of a minidisc?) If so, be careful if you release this program, or you might run into problems similar to my own bit-flipping software [cmu.edu] !

Math is like love -- a simple idea but it can get complicated. -- R. Drabek

Working...