/*
* Copyright (c) 2012 Stefano Sabatini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file
* libavformat demuxing API use example.
*
* Show how to use the libavformat and libavcodec API to demux and
* decode audio and video data.
* @example doc/examples/demuxing.c
*/
{
int ret = 0;
/* decode video frame */
if (ret < 0) {
fprintf(stderr, "Error decoding video frame\n");
return ret;
}
if (*got_frame) {
printf("video_frame%s n:%d coded_n:%d pts:%s\n",
cached ? "(cached)" : "",
/* copy decoded frame to destination buffer:
* this is required since rawvideo expects non aligned data */
/* write to rawvideo file */
}
/* decode audio frame */
if (ret < 0) {
fprintf(stderr, "Error decoding audio frame\n");
return ret;
}
if (*got_frame) {
printf("audio_frame%s n:%d nb_samples:%d pts:%s\n",
cached ? "(cached)" : "",
if (ret < 0) {
fprintf(stderr, "Could not allocate audio buffer\n");
}
/* TODO: extend return code of the av_samples_* functions so that this call is not needed */
/* copy audio data to destination buffer:
* this is required since rawaudio expects non aligned data */
/* write to rawaudio file */
}
}
return ret;
}
{
int ret;
if (ret < 0) {
fprintf(stderr, "Could not find %s stream in input file '%s'\n",
return ret;
} else {
*stream_idx = ret;
st = fmt_ctx->
streams[*stream_idx];
/* find decoder for the stream */
if (!dec) {
fprintf(stderr, "Failed to find %s codec\n",
return ret;
}
fprintf(stderr, "Failed to open %s codec\n",
return ret;
}
}
return 0;
}
{
int i;
struct sample_fmt_entry {
} sample_fmt_entries[] = {
};
struct sample_fmt_entry *entry = &sample_fmt_entries[i];
if (sample_fmt == entry->sample_fmt) {
*fmt =
AV_NE(entry->fmt_be, entry->fmt_le);
return 0;
}
}
fprintf(stderr,
"sample format %s is not supported as output format\n",
return -1;
}
int main (
int argc,
char **argv)
{
int ret = 0, got_frame;
if (argc != 4) {
fprintf(stderr, "usage: %s input_file video_output_file audio_output_file\n"
"API example program to show how to read frames from an input file.\n"
"This program reads frames from a file, decodes them, and writes decoded\n"
"video frames to a rawvideo file named video_output_file, and decoded\n"
"audio frames to a rawaudio file named audio_output_file.\n"
"\n", argv[0]);
exit(1);
}
/* register all formats and codecs */
/* open input file, and allocate format context */
fprintf(stderr,
"Could not open source file %s\n",
src_filename);
exit(1);
}
/* retrieve stream information */
fprintf(stderr, "Could not find stream information\n");
exit(1);
}
video_dec_ctx = video_stream->
codec;
ret = 1;
}
/* allocate image where the decoded image will be put */
if (ret < 0) {
fprintf(stderr, "Could not allocate raw video buffer\n");
}
}
int nb_planes;
ret = 1;
}
fprintf(stderr, "Could not allocate audio data buffers\n");
}
}
/* dump input information to stderr */
fprintf(stderr, "Could not find audio or video stream in the input, aborting\n");
ret = 1;
}
if (!frame) {
fprintf(stderr, "Could not allocate frame\n");
}
/* initialize packet, set data to NULL, let the demuxer fill it */
if (video_stream)
/* read frames from the file */
/* flush cached frames */
do {
} while (got_frame);
printf("Demuxing succeeded.\n");
if (video_stream) {
printf("Play the output video file with the command:\n"
"ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %s\n",
}
printf("Play the output audio file with the command:\n"
"ffplay -f %s -ac %d -ar %d %s\n",
}
if (video_dec_ctx)
return ret < 0;
}