Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [Programmazione C] Problema di lettura di file video
Pages (2): [1] 2 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[Programmazione C] Problema di lettura di file video

Ciao, devo realizzare un programma in C che legga e successivamente modifichi dei file video che hanno una struttura simile al formato AVI.
Conosco la struttura interna del file, gli header e le informazioni che contiene, ma ho un problema quando tento di leggere i vari frame, infatti in molti casi la lettura di un frame si interrompe a metà e non riesco più a proseguire nella lettura del file.

Facendo varie prove ho capito che probabilmente il problema nasce dalla presenza di una sequenza di "zeri" all'interno del file, che viene interpretata dalla funzione read() come un carattere NULL, e quindi "fine del file". Il file però non è affatto terminato, ma se provo a fare altre read() mi viene restituito sempre 0.

Come posso leggere (e memorizare) il contenuto del file così com'è, senza che la lettura si blocchi a metà?
Grazie mille per qualsiasi aiuto... :)

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 09:58
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Hai provato byte a byte con fgetc()?

__________________
?

30-08-2005 19:31
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Oppure, se conosci le dimensioni del file, dovresti poter usare fread() (che fra l'altro è ANSI/POSIX compliant, al contrario della read())

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

30-08-2005 19:50
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by yeah
Hai provato byte a byte con fgetc()?


No... domani provo, grazie! :)

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 21:45
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by DeepBlue
Oppure, se conosci le dimensioni del file, dovresti poter usare fread() (che fra l'altro è ANSI/POSIX compliant, al contrario della read())


Perchè devo conoscere le dimensioni del file per usarla?

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 21:46
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Mi sa che con l'idea di DeepBlue fai prima, puoi recuperare tutti i byte con una sola chiamata, invece che con n chiamate.


#include <stdio.h>

size_t fread(void *buffer, size_t size, size_t number, FILE *file);


Metti size a 1 e number alla dimensione del file e sei a posto :)

__________________
?

30-08-2005 21:51
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by yeah
Mi sa che con l'idea di DeepBlue fai prima, puoi recuperare tutti i byte con una sola chiamata, invece che con n chiamate.



Metti size a 1 e number alla dimensione del file e sei a posto :)


Aspetta... ma così leggo tutto il file in una volta sola, giusto?
Io devo leggere i vari frame uno alla volta, perchè devo modificarli e sbatterli (ad uno ad uno) in un nuovo file che sto creando.

Leggendo tutto insieme, dopo dovrei scandire il buffer di memoria per trovare i vari frame... e mi servirebbe un buffer enorme, il filmato potrebbe essere di 100 MB per esempio. Leggendo invece un frame per volta posso allocare solo pochi KB...

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 22:31
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by DarkGod
Aspetta... ma così leggo tutto il file in una volta sola, giusto?
Io devo leggere i vari frame uno alla volta, perchè devo modificarli e sbatterli (ad uno ad uno) in un nuovo file che sto creando.


Ok: tu sai quanto è grande un frame a priori? Se sì, allora puoi vedere un po' cosa riesci a combinare con fseek().

Se no, probabilmente visto che conosci le intestazioni dei frame, forse puoi calcolarne le dimensioni ed utilizzare fseek().

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

30-08-2005 22:36
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by DeepBlue
Ok: tu sai quanto è grande un frame a priori? Se sì, allora puoi vedere un po' cosa riesci a combinare con fseek().


Sì sì, la struttura dei frame la conosco perfettamente, campo per campo. Ogni frame ha un header che contiene anche la dimensione del frame stesso.
Il problema è che, per esempio, se ho un frame di 200 byte, faccendo:

read (file_descriptor, buffer, 200)

in alcuni frame invece di ritornarmi il valore 200, me ne ritorna uno minore. A questo punto, se faccio altre read per proseguire nella lettura, mi restituisce sempre e solo 0 (quindi non legge più nulla), come se il file fosse finito (ma ovviamente non lo è).
Da quello che ho capito, questo succede quando c'è una sequenza di zeri all'interno di un frame, che probabilmente viene interpretato dalla read() come un EOF.

Cmq, fseek() server per scorrere il puntatore in un file... ma in questo modo salto dei pezzi, no?

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 22:49
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged


Aspetta... ma così leggo tutto il file in una volta sola, giusto?
Io devo leggere i vari frame uno alla volta, perchè devo modificarli e sbatterli (ad uno ad uno) in un nuovo file che sto creando.

In quel caso sì, ma se al posto della dimensione del file metti la dimensione del frame ti leggi solo il frame :)

__________________
?

30-08-2005 22:49
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by yeah
In quel caso sì, ma se al posto della dimensione del file metti la dimensione del frame ti leggi solo il frame :)


Ma scusa... non è quello che sto già tentandio di fare? O__o
Oppure la fread() non si blocca come la read() ?

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 22:51
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Scusa, deve essere l'ora :) e abbiamo anche postato contemporaneamente, non me ne ero accorto :)

Cmq non ho mai usato read(),però è strano che ti si 'blocchi'... in sè dovrebbe (come vedo dalle man pages) leggere un tot di byte, come la fread(), la differenza è che fread() fa parte della libreria standard del C, mentre read() è, come ha detto Deep, POSIX, quindi la sua disponibilità dipende dall'ambiente e dal compilatore.

Se vuoi prova con fread() o con fgetc(), ma secondo me il problema è un altro... mi sembra strano che si fermi per una sequenza di zeri... le man non dicono nulla a riguardo

__________________
?

Last edited by yeah on 30-08-2005 at 23:07

30-08-2005 23:02
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by yeah
Scusa, deve essere l'ora :) e abbiamo anche postato contemporaneamente, non me ne ero accorto :)


Come ti capisco... io ho pure la febbre e raffreddore, eh eh... :(
infatti mi sa che fra un attimo vado a nanna :)

Cmq non ho mai usato read(),però è strano che ti si 'blocchi'... in sè dovrebbe (come vedo dalle man pages) leggere un tot di byte, come la fread(), la differenza è che fread() fa parte della libreria standard del C, mentre read() è, come ha detto Deep, POSIX, quindi la sua disponibilità dipende dall'ambiente e dal compilatore.

Se vuoi prova con fread() o con fgetc(), ma secondo me il problema è un altro... mi sembra strano che si fermi per una sequenza di zeri... le man non dicono nulla


Sì, anche secondo me è strano, però i manuali dicono che la read restituisce meno byte di quanti ne dovrebbe leggere solo nel caso in cui abbia raggiunto la fine del file... Ma naturalmente un filmato di 60MB non può certo finire dopo il quarto frame! ;)
Eppure lì si blocca e non va più avanti. In ogni file si blocca in un punto diverso naturalmente.
Indagando un po' all'interno del file, ho notato che dove si blocca c'è una lunga sequenza di zeri... e dato che se non erro il carattere NULL è formato da zeri e identifica la fine di un file........

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 23:08
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.20 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged


e dato che se non erro il carattere NULL è formato da zeri e identifica la fine di un file........

No, in genere indica la fine delle stringhe ;)

Puoi postare del codice? Se trovo un avi provo a darci una occhiata

__________________
?

30-08-2005 23:12
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkGod
superfallito

User info:
Registered: Sep 2001
Posts: 627 (0.07 al dì)
Location: Milano
Corso: Informatica
Anno: SuperDottore
Time Online: 3 Days, 0:10:52 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by yeah
No, in genere indica la fine delle stringhe ;)

Puoi postare del codice? Se trovo un avi provo a darci una occhiata


Certo!
Ma ora non ho qui il codice... posto domani.
Ciauz! E grazie! :)

__________________
Chiamatemi Darky ^_^

_____ -+- ANTINOMY -+- __________ -+- Inside Human Cruelty -+- _____

30-08-2005 23:18
Click Here to See the Profile for DarkGod Click Here to See the Blog of DarkGod Click here to Send DarkGod a Private Message Find more posts by DarkGod Add DarkGod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 08:41.    Post New Thread    Post A Reply
Pages (2): [1] 2 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.102 seconds (43.87% PHP - 56.13% MySQL) con 24 query.