473,468 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

c code to open a binary/raw video file

2 New Member
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 :(
Oct 9 '13 #1

✓ answered by weaknessforcats

This code does not work:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1.   buffer = (char*)malloc(s);     
Third, this code:
Expand|Select|Wrap|Line Numbers
  1.  if (fs==NULL)
  2.     {
  3.         fseek(fh, 0L, SEEK_END);
  4.     long s = ftell(fh);
  5.     rewind(fh);
  6. etc...
probably wants to be:
Expand|Select|Wrap|Line Numbers
  1. if (fs!=NULL)
  2.     {
  3.         fseek(fh, 0L, SEEK_END);
  4.     long s = ftell(fh);
  5.     rewind(fh);
  6. etc...
because if fs is zero, your file did not open.

I got everything to compile but did not run the code

3 2335
weaknessforcats
9,208 Recognized Expert Moderator Expert
How about posting your code for opening the file?
Oct 9 '13 #2
Tejaswi Sharma
2 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.   char *buffer ;
  7.   FILE *fh, *fs ;
  8.       fh= fopen("display name.c", "rb");
  9.  
  10.  
  11.   fs= fopen (" loadout.c","w");
  12.  
  13. if (fs==NULL)
  14.     {
  15.         fseek(fh, 0L, SEEK_END);
  16.     long s = ftell(fh);
  17.     rewind(fh);
  18.     buffer == malloc(s);
  19.     if ( buffer != NULL )
  20.     {
  21.       fread(buffer, s, 1, fh);
  22.       // we can now close the file
  23.       fclose(fh); fh = NULL;
  24.  
  25.       // do something, e.g.
  26.       fwrite(buffer, s, 1, stdout);
  27.  
  28.       free(buffer);
  29.     }
  30.     if (fh != NULL) fclose(fh);
  31.     }
  32.  
  33.   return EXIT_SUCCESS;
  34. }
Oct 10 '13 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code does not work:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1.   buffer = (char*)malloc(s);     
Third, this code:
Expand|Select|Wrap|Line Numbers
  1.  if (fs==NULL)
  2.     {
  3.         fseek(fh, 0L, SEEK_END);
  4.     long s = ftell(fh);
  5.     rewind(fh);
  6. etc...
probably wants to be:
Expand|Select|Wrap|Line Numbers
  1. if (fs!=NULL)
  2.     {
  3.         fseek(fh, 0L, SEEK_END);
  4.     long s = ftell(fh);
  5.     rewind(fh);
  6. etc...
because if fs is zero, your file did not open.

I got everything to compile but did not run the code
Oct 10 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bishman | last post by:
Hi, Can someone suggest the best technique / method of opening a Word ( or any other ) Document from an SQL BLOB ? I have the process of saving and retrieveing the file from an SQL Binary...
3
by: rojavenkat81 | last post by:
Hi All, Please help me regarding php program for convert video file to .flv file. I searched in many sites but i got only tool to convert video file to .flv file.But I want convert...
3
by: Pier | last post by:
there is a method to open and decript a *.dat files?
1
by: Uday | last post by:
Hi Everybody, I am building a website in Asp.Net 1.1. I need to play a video file in the site. How to do this. Please help me out. Thanks in Advance Uday Mandava
3
by: aratimane | last post by:
Hi, I have received the video file in chunk and want to join/merge these chunks into one video file. I have used cat command in unix for joining video, but while played that video file it...
1
kirubagari
by: kirubagari | last post by:
I Would Like Ask Ques On How To Open Bonding.bin File In C++ Or In Visual Basic 6.actually The Data In The Binary File Have Been Corrupted And I Would Like To Know The Method How To Open The File...
3
by: mindmaster32 | last post by:
Hi, I am looking for a python tool or module that helps me build a script that can perceive object moves in a video file captured by a (web) camera. My main goal is to be able to count people...
1
by: Amol | last post by:
Hi , I need to grab thumbnails from a video file with extension wmv or dat. I need to write the code in c# has anybody done this before. Any help is appreciated. Thanks
0
by: William Johnston | last post by:
Hi, I get an infinite loop and non-"optimal" results from an MSDN Magazine March 2007 article on creating bitmaps from video files. The infinite loop and non-"optimal" results are from a...
5
by: sonu | last post by:
hey good morning ...... how to convert a video file in .flv format in php for linux hosting......is there any package whis provide this facility . Can i use ffmpeg for linux hosting...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.