+/**
+ * @example examples/am7xxx-play.c
+ * am7xxx-play uses libavdevice, libavformat, libavcodec and libswscale to
+ * decode the input, encode it to jpeg and display it with libam7xxx.
+ */
+
/* get information on the input stream (e.g. format, bitrate, framerate) */
ret = avformat_find_stream_info(input_format_ctx, NULL);
if (ret < 0) {
/* get information on the input stream (e.g. format, bitrate, framerate) */
ret = avformat_find_stream_info(input_format_ctx, NULL);
if (ret < 0) {
/* find the decoder for the video stream */
input_codec = avcodec_find_decoder(input_codec_ctx->codec_id);
if (input_codec == NULL) {
/* find the decoder for the video stream */
input_codec = avcodec_find_decoder(input_codec_ctx->codec_id);
if (input_codec == NULL) {
/* create the encoder context */
output_codec_ctx = avcodec_alloc_context3(NULL);
if (output_codec_ctx == NULL) {
/* create the encoder context */
output_codec_ctx = avcodec_alloc_context3(NULL);
if (output_codec_ctx == NULL) {
output_codec_ctx->bit_rate = (input_ctx->codec_ctx)->bit_rate;
output_codec_ctx->width = new_output_width;
output_codec_ctx->height = new_output_height;
output_codec_ctx->bit_rate = (input_ctx->codec_ctx)->bit_rate;
output_codec_ctx->width = new_output_width;
output_codec_ctx->height = new_output_height;
- output_codec_ctx->time_base.num = (input_ctx->codec_ctx)->time_base.num;
- output_codec_ctx->time_base.den = (input_ctx->codec_ctx)->time_base.den;
+ output_codec_ctx->time_base.num =
+ (input_ctx->format_ctx)->streams[input_ctx->video_stream_index]->time_base.num;
+ output_codec_ctx->time_base.den =
+ (input_ctx->format_ctx)->streams[input_ctx->video_stream_index]->time_base.den;
/* allocate an input frame */
picture_raw = avcodec_alloc_frame();
if (picture_raw == NULL) {
/* allocate an input frame */
picture_raw = avcodec_alloc_frame();
if (picture_raw == NULL) {
picture_scaled = avcodec_alloc_frame();
if (picture_scaled == NULL) {
fprintf(stderr, "cannot allocate the scaled picture!\n");
picture_scaled = avcodec_alloc_frame();
if (picture_scaled == NULL) {
fprintf(stderr, "cannot allocate the scaled picture!\n");
out_buf = av_malloc(out_buf_size * sizeof(uint8_t));
if (out_buf == NULL) {
fprintf(stderr, "cannot allocate output data buffer!\n");
out_buf = av_malloc(out_buf_size * sizeof(uint8_t));
if (out_buf == NULL) {
fprintf(stderr, "cannot allocate output data buffer!\n");
NULL, NULL, NULL);
if (sw_scale_ctx == NULL) {
fprintf(stderr, "cannot set up the rescaling context!\n");
NULL, NULL, NULL);
if (sw_scale_ctx == NULL) {
fprintf(stderr, "cannot set up the rescaling context!\n");
printf("\t-o <options>\t\ta comma separated list of input format options\n");
printf("\t\t\t\tEXAMPLE:\n");
printf("\t\t\t\t\t-o draw_mouse=1,framerate=100,video_size=800x480\n");
printf("\t-o <options>\t\ta comma separated list of input format options\n");
printf("\t\t\t\tEXAMPLE:\n");
printf("\t\t\t\t\t-o draw_mouse=1,framerate=100,video_size=800x480\n");
printf("\t-u \t\t\tupscale the image if smaller than the display dimensions\n");
printf("\t-F <format>\t\tthe image format to use (default is JPEG)\n");
printf("\t\t\t\tSUPPORTED FORMATS:\n");
printf("\t\t\t\t\t1 - JPEG\n");
printf("\t\t\t\t\t2 - NV12\n");
printf("\t-u \t\t\tupscale the image if smaller than the display dimensions\n");
printf("\t-F <format>\t\tthe image format to use (default is JPEG)\n");
printf("\t\t\t\tSUPPORTED FORMATS:\n");
printf("\t\t\t\t\t1 - JPEG\n");
printf("\t\t\t\t\t2 - NV12\n");
- printf("\t-q \t\t\tquality of jpeg sent to the device, between 1 and 100\n");
+ printf("\t-q <quality>\t\tquality of jpeg sent to the device, between 1 and 100\n");
+ printf("\t-l <log level>\t\tthe verbosity level of libam7xxx output (0-5)\n");
printf("\t-p <power level>\tpower level of device, between %x (off) and %x (maximum)\n", AM7XXX_POWER_OFF, AM7XXX_POWER_TURBO);
printf("\t\t\t\tWARNING: Level 2 and greater require the master AND\n\t\t\t\t\t the slave connector to be plugged in.\n");
printf("\t-h \t\t\tthis help message\n");
printf("\t-p <power level>\tpower level of device, between %x (off) and %x (maximum)\n", AM7XXX_POWER_OFF, AM7XXX_POWER_TURBO);
printf("\t\t\t\tWARNING: Level 2 and greater require the master AND\n\t\t\t\t\t the slave connector to be plugged in.\n");
printf("\t-h \t\t\tthis help message\n");
unsigned int rescale_method = SWS_BICUBIC;
unsigned int upscale = 0;
unsigned int quality = 95;
unsigned int rescale_method = SWS_BICUBIC;
unsigned int upscale = 0;
unsigned int quality = 95;
av_dict_set(&options, subopt_name, subopt_value, 0);
}
free(subopts_saved);
av_dict_set(&options, subopt_name, subopt_value, 0);
}
free(subopts_saved);
if (quality < 1 || quality > 100) {
fprintf(stderr, "Invalid quality value, must be between 1 and 100\n");
ret = -EINVAL;
if (quality < 1 || quality > 100) {
fprintf(stderr, "Invalid quality value, must be between 1 and 100\n");
ret = -EINVAL;
- case 'h':
- usage(argv[0]);
- ret = 0;
- goto out;
+ case 'l':
+ log_level = atoi(optarg);
+ if (log_level < AM7XXX_LOG_FATAL || log_level > AM7XXX_LOG_TRACE) {
+ fprintf(stderr, "Unsupported log level, falling back to AM7XXX_LOG_ERROR\n");
+ log_level = AM7XXX_LOG_ERROR;
+ }
ret = am7xxx_open_device(ctx, &dev, 0);
if (ret < 0) {
perror("am7xxx_open_device");
ret = am7xxx_open_device(ctx, &dev, 0);
if (ret < 0) {
perror("am7xxx_open_device");