Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
3abf2c27
Commit
3abf2c27
authored
23 years ago
by
Fabrice Bellard
Browse files
Options
Downloads
Patches
Plain Diff
added jpeg image read/write
Originally committed as revision 88 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
79ba6118
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libav/jpeg.c
+245
-0
245 additions, 0 deletions
libav/jpeg.c
with
245 additions
and
0 deletions
libav/jpeg
enc
.c
→
libav/jpeg.c
+
245
−
0
View file @
3abf2c27
...
@@ -65,14 +65,15 @@ AVFormat mpjpeg_format = {
...
@@ -65,14 +65,15 @@ AVFormat mpjpeg_format = {
};
};
/*************************************/
/* single frame JPEG */
/* single frame JPEG */
static
int
jpeg_write_header
(
AVFormatContext
*
s
)
static
int
single_
jpeg_write_header
(
AVFormatContext
*
s
)
{
{
return
0
;
return
0
;
}
}
static
int
jpeg_write_packet
(
AVFormatContext
*
s
,
int
stream_index
,
static
int
single_
jpeg_write_packet
(
AVFormatContext
*
s
,
int
stream_index
,
UINT8
*
buf
,
int
size
)
UINT8
*
buf
,
int
size
)
{
{
put_buffer
(
&
s
->
pb
,
buf
,
size
);
put_buffer
(
&
s
->
pb
,
buf
,
size
);
...
@@ -80,11 +81,151 @@ static int jpeg_write_packet(AVFormatContext *s, int stream_index,
...
@@ -80,11 +81,151 @@ static int jpeg_write_packet(AVFormatContext *s, int stream_index,
return
1
;
/* no more data can be sent */
return
1
;
/* no more data can be sent */
}
}
static
int
jpeg_write_trailer
(
AVFormatContext
*
s
)
static
int
single_
jpeg_write_trailer
(
AVFormatContext
*
s
)
{
{
return
0
;
return
0
;
}
}
AVFormat
single_jpeg_format
=
{
"singlejpeg"
,
"single JPEG image"
,
"image/jpeg"
,
"jpg,jpeg"
,
CODEC_ID_NONE
,
CODEC_ID_MJPEG
,
single_jpeg_write_header
,
single_jpeg_write_packet
,
single_jpeg_write_trailer
,
};
/*************************************/
/* multiple jpeg images */
typedef
struct
JpegContext
{
char
path
[
1024
];
int
img_number
;
}
JpegContext
;
static
int
jpeg_write_header
(
AVFormatContext
*
s1
)
{
JpegContext
*
s
;
s
=
av_mallocz
(
sizeof
(
JpegContext
));
if
(
!
s
)
return
-
1
;
s1
->
priv_data
=
s
;
nstrcpy
(
s
->
path
,
sizeof
(
s
->
path
),
s1
->
filename
);
s
->
img_number
=
1
;
return
0
;
}
static
int
jpeg_write_packet
(
AVFormatContext
*
s1
,
int
stream_index
,
UINT8
*
buf
,
int
size
)
{
JpegContext
*
s
=
s1
->
priv_data
;
char
filename
[
1024
];
ByteIOContext
f1
,
*
pb
=
&
f1
;
snprintf
(
filename
,
sizeof
(
filename
),
s
->
path
,
s
->
img_number
);
if
(
url_fopen
(
pb
,
filename
,
URL_WRONLY
)
<
0
)
return
-
EIO
;
put_buffer
(
pb
,
buf
,
size
);
put_flush_packet
(
pb
);
url_fclose
(
pb
);
s
->
img_number
++
;
return
0
;
}
static
int
jpeg_write_trailer
(
AVFormatContext
*
s1
)
{
JpegContext
*
s
=
s1
->
priv_data
;
free
(
s
);
return
0
;
}
/***/
static
int
jpeg_read_header
(
AVFormatContext
*
s1
,
AVFormatParameters
*
ap
)
{
JpegContext
*
s
;
int
i
;
char
buf
[
1024
];
ByteIOContext
pb1
,
*
f
=
&
pb1
;
AVStream
*
st
;
s
=
av_mallocz
(
sizeof
(
JpegContext
));
if
(
!
s
)
return
-
1
;
s1
->
priv_data
=
s
;
nstrcpy
(
s
->
path
,
sizeof
(
s
->
path
),
s1
->
filename
);
s1
->
nb_streams
=
1
;
st
=
av_mallocz
(
sizeof
(
AVStream
));
if
(
!
st
)
{
free
(
s
);
return
-
ENOMEM
;
}
s1
->
streams
[
0
]
=
st
;
s
->
img_number
=
0
;
/* try to find the first image */
for
(
i
=
0
;
i
<
5
;
i
++
)
{
snprintf
(
buf
,
sizeof
(
buf
),
s
->
path
,
s
->
img_number
);
if
(
url_fopen
(
f
,
buf
,
URL_RDONLY
)
>=
0
)
break
;
s
->
img_number
++
;
}
if
(
i
==
5
)
goto
fail
;
url_fclose
(
f
);
st
->
codec
.
codec_type
=
CODEC_TYPE_VIDEO
;
st
->
codec
.
codec_id
=
CODEC_ID_MJPEG
;
if
(
!
ap
||
!
ap
->
frame_rate
)
st
->
codec
.
frame_rate
=
25
*
FRAME_RATE_BASE
;
else
st
->
codec
.
frame_rate
=
ap
->
frame_rate
;
return
0
;
fail:
free
(
s
);
return
-
EIO
;
}
static
int
jpeg_read_packet
(
AVFormatContext
*
s1
,
AVPacket
*
pkt
)
{
JpegContext
*
s
=
s1
->
priv_data
;
char
filename
[
1024
];
int
size
;
ByteIOContext
f1
,
*
f
=
&
f1
;
snprintf
(
filename
,
sizeof
(
filename
),
s
->
path
,
s
->
img_number
);
f
=
&
f1
;
if
(
url_fopen
(
f
,
filename
,
URL_RDONLY
)
<
0
)
return
-
EIO
;
size
=
url_seek
(
url_fileno
(
f
),
0
,
SEEK_END
);
url_seek
(
url_fileno
(
f
),
0
,
SEEK_SET
);
av_new_packet
(
pkt
,
size
);
pkt
->
stream_index
=
0
;
get_buffer
(
f
,
pkt
->
data
,
size
);
url_fclose
(
f
);
s
->
img_number
++
;
return
0
;
}
static
int
jpeg_read_close
(
AVFormatContext
*
s1
)
{
JpegContext
*
s
=
s1
->
priv_data
;
free
(
s
);
return
0
;
}
AVFormat
jpeg_format
=
{
AVFormat
jpeg_format
=
{
"jpeg"
,
"jpeg"
,
"JPEG image"
,
"JPEG image"
,
...
@@ -95,4 +236,10 @@ AVFormat jpeg_format = {
...
@@ -95,4 +236,10 @@ AVFormat jpeg_format = {
jpeg_write_header
,
jpeg_write_header
,
jpeg_write_packet
,
jpeg_write_packet
,
jpeg_write_trailer
,
jpeg_write_trailer
,
jpeg_read_header
,
jpeg_read_packet
,
jpeg_read_close
,
NULL
,
AVFMT_NOFILE
,
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment