c code to open a binary/raw video file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tejaswi Sharma
    New Member
    • Oct 2013
    • 2

    c code to open a binary/raw video file

    hello, i m working on H.264 encoder, i m new to dis and if anyone can suggest me how to code using c code then i m more thankful to them... plz let me know how to open a binary file using c, i have tried and have got zero errors but end result its not opening :(
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    How about posting your code for opening the file?

    Comment

    • Tejaswi Sharma
      New Member
      • Oct 2013
      • 2

      #3
      Code:
      #include <stdio.h>
      #include <stdlib.h>
       
      int main()
      {
        char *buffer ;
        FILE *fh, *fs ;
      	  fh= fopen("display name.c", "rb");
       
       
        fs= fopen (" loadout.c","w");
      
      if (fs==NULL)
      	{
      		fseek(fh, 0L, SEEK_END);
          long s = ftell(fh);
          rewind(fh);
          buffer == malloc(s);
          if ( buffer != NULL )
          {
            fread(buffer, s, 1, fh);
            // we can now close the file
            fclose(fh); fh = NULL;
       
            // do something, e.g.
            fwrite(buffer, s, 1, stdout);
       
            free(buffer);
          }
          if (fh != NULL) fclose(fh);
      	}
      
        return EXIT_SUCCESS;
      }
      Last edited by Rabbit; Oct 10 '13, 06:01 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This code does not work:

        Code:
        buffer == malloc(s);
        First, you meant the assignment operator.

        Second, malloc returns void* and this cannot be assigned to a char* uness you use a cast:

        Code:
          buffer = (char*)malloc(s);
        Third, this code:
        Code:
         if (fs==NULL)
        	{
        		fseek(fh, 0L, SEEK_END);
            long s = ftell(fh);
            rewind(fh);
        etc...
        probably wants to be:
        Code:
        if (fs!=NULL)
        	{
        		fseek(fh, 0L, SEEK_END);
            long s = ftell(fh);
            rewind(fh);
        etc...
        because if fs is zero, your file did not open.

        I got everything to compile but did not run the code

        Comment

        Working...