MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / main

Function main

doc/examples/qsv_transcode.c:341–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341int main(int argc, char **argv)
342{
343 const AVCodec *enc_codec;
344 int ret = 0;
345 AVPacket *dec_pkt = NULL;
346
347 if (argc < 5 || (argc - 5) % 2) {
348 av_log(NULL, AV_LOG_ERROR, "Usage: %s <input file> <encoder> <output file>"
349 " <\"encoding option set 0\"> [<frame_number> <\"encoding options set 1\">]...\n", argv[0]);
350 return 1;
351 }
352 setting_number = (argc - 5) / 2;
353 dynamic_setting = av_malloc(setting_number * sizeof(*dynamic_setting));
354 if (!dynamic_setting) {
355 ret = AVERROR(ENOMEM);
356 goto end;
357 }
358 current_setting_number = 0;
359 for (int i = 0; i < setting_number; i++) {
360 dynamic_setting[i].frame_number = atoi(argv[i*2 + 5]);
361 dynamic_setting[i].optstr = argv[i*2 + 6];
362 }
363
364 ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV, NULL, NULL, 0);
365 if (ret < 0) {
366 fprintf(stderr, "Failed to create a QSV device. Error code: %s\n", av_err2str(ret));
367 goto end;
368 }
369
370 dec_pkt = av_packet_alloc();
371 if (!dec_pkt) {
372 fprintf(stderr, "Failed to allocate decode packet\n");
373 goto end;
374 }
375
376 if ((ret = open_input_file(argv[1])) < 0)
377 goto end;
378
379 if (!(enc_codec = avcodec_find_encoder_by_name(argv[2]))) {
380 fprintf(stderr, "Could not find encoder '%s'\n", argv[2]);
381 ret = -1;
382 goto end;
383 }
384
385 if ((ret = (avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, argv[3]))) < 0) {
386 fprintf(stderr, "Failed to deduce output format from file extension. Error code: "
387 "%s\n", av_err2str(ret));
388 goto end;
389 }
390
391 if (!(encoder_ctx = avcodec_alloc_context3(enc_codec))) {
392 ret = AVERROR(ENOMEM);
393 goto end;
394 }
395
396 ret = avio_open(&ofmt_ctx->pb, argv[3], AVIO_FLAG_WRITE);
397 if (ret < 0) {
398 fprintf(stderr, "Cannot open output file. "

Callers

nothing calls this directly

Calls 15

av_logFunction · 0.85
av_hwdevice_ctx_createFunction · 0.85
av_packet_allocFunction · 0.85
avcodec_alloc_context3Function · 0.85
avio_openFunction · 0.85
av_read_frameFunction · 0.85
av_packet_unrefFunction · 0.85
av_write_trailerFunction · 0.85
avformat_close_inputFunction · 0.85
avcodec_free_contextFunction · 0.85

Tested by

no test coverage detected