0

Okay guys copying and pasting video file with hex editor or with notepad++ hex editor plugin works totally fine.Now,i want to find the number of lines in a video file-

first)I opened the video file in notepad++ and the number of total lines is 1876(the left most column).

Second)I view the file in hex mode the total number of lines is 39240;

Thirdly)I built a c++ program for reading the number of lines from the same video file.My code is:

  char c;
  int total_line=0;
  ifstream file("vid.avi",ios::binary | ios::in)
  while(!file.eof())
  {
     c=file.get();
     if(c=='\n')
     {
        total_line++;
     }

  }
  file.close();
  cout<<"Total line "<<total_line<<endl;

This gives total line of 1313.Which one is correct and whichone is false anyone help.

  • 1
    A video file is a binary format and has no concept of "lines". What are you trying to accomplish? – heavyd Mar 24 '14 at 19:15
  • I thought i will read the character in video file line by line because i am trying to build a compresser for video files and have been reading LZ algorithm and they mainly work with charaters so breaking up the characters line by line and studying it would make it easier.Thanks anyway. – user3319758 Mar 24 '14 at 19:26
  • Most video files are already highly compressed. You're probably not going to get much better compression than what you already have. If you are wanting to read in the file you should do it byte by byte, or in fixed length chunks (1024 bytes for example). – heavyd Mar 24 '14 at 19:31
  • "Most video files are already highly compressed.",pleas tell me how are video files compressed already or give a link which explains it?.I know this question is not part of my main question but,i have been wanting to know more about it. – user3319758 Mar 24 '14 at 19:35
  • Most video formats are containers for compressed video streams - very few are raw, uncompressed video. Have a look at this for starters and links to a few compressed video formats en.wikipedia.org/wiki/Video_compression_format – willh Mar 24 '14 at 19:40
1

There are no "characters" or "lines" in a video file. That is because, data in a video file is not text but video! :)

So, to make sense of a file containing anything other than text, you need to open it in binary mode and treat the file as a big blob of binary data containing several bytes. Now, to process this kind of file, you can read bytes from that file in chunks (for example 1024 bytes at a time)

Now, to process this file and extract the data in meaningful way, you need to know the format of that file and how data is laid out in binary for that particular file format.

Lets take a look at simple image file format for example, BMP format. http://en.wikipedia.org/wiki/BMP_file_format

There you can see how bitmap file is divided into various fixed and variable length chunks. For example, the first 14 bytes of BMP file is a bitmap header and tell you some general information about the file. Other headers will tell you about pixel format, width, height etc of the image. You can use this data in headers to make sense of the rest of the image data stored in the file.

| improve this answer | |
  • "Now, to process this file and extract the data in meaningful way, you need to know the format of that file. How the data is laid out in binary for that particular file format." can you please tell me moe about this part? By 'process' do you mean editting or modifying. – user3319758 Mar 24 '14 at 19:39
  • Edited the answer to explain this a bit. By processing I mean doing anything you want with the data in the file. You can modify the video data, you can compress it, add effects, track objects etc. But, to do anything like that, you first need to know the format and how to parse those bytes into meaningful video frames. – Punit Soni Mar 24 '14 at 19:54
0

There is no useful concept of a "line" in a video file. Why are you looking for the number of "lines"?

Regarding the difference in the reported numbers: Notepad++ probably detects more line breaks than just "\n" (see for example http://en.wikipedia.org/wiki/Newline). When you view the file in hex mode, it is displayed with 2 characters per byte with a fixed width of bytes per line, so

hex > notepad++ > your code

sounds reasonable.

| improve this answer | |
  • Do you mean to say there is no such thing as line in a video file and all the characters are joined.But if characters are presented line by line then tell me how to find it. – user3319758 Mar 24 '14 at 19:20
  • If you open a video file (or any other binary file: picture, music, office documents, zip archieve) with notepad, it tries to display something useful, some bytes of the file can be printed as letters, while others can't. "tell me how to find it" -- find what? – Jasper Mar 24 '14 at 19:24
  • Well i thought if charaters are presented line by line in video file as in text mode than i was asking for a way to find it but,since @heavyd has pointed out that there is no concept of lines in video file or binary format so it doesn't matter anymore.Anyway thanks. – user3319758 Mar 24 '14 at 19:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.