ffmpeg
-
Guten Tag!
Falls hier jemand Erfahrung mit ffmpeg hat wäre ich ihm sehr verbunden wenn er mir ein kurzes Codebeispiel für
1. Die Dekodierung von AAC
2. Die Kodierung in AAC
posten könnte. Meine bisherigen versuche sind Fehlgeschlagen und alle mir bekannten Tutorials offensichtlich hoffnungslos veraltet.Falls es jemanden interessiert - hieran scheitert das ganze gerade:
int main(int argc, char **argv) { int retval = 0; AVFormatContext *format_context; int i, audio_stream_index = -1; AVCodecContext *codec_context; AVCodec *codec; FILE *infile, *outfile; AVPacket av_packet; unsigned char inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; unsigned char *outbuf; int out_size, len; av_register_all(); if (argc <= 2) ErrorExit("need more args"); for (i = 0; i < argc; ++i) printf("%i: %s\n", i + 1, argv[i]); if (av_open_input_file(&format_context, argv[1], 0, 0, 0) != 0) ErrorExit("av_open_input_file()"); if (av_find_stream_info(format_context) < 0) ErrorExit("av_find_stream_info()"); dump_format(format_context, 0, argv[1], 0); for (i = 0; i < format_context->nb_streams; ++i) { if (format_context->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) { audio_stream_index = i; break; } } if (audio_stream_index == -1) ErrorExit("could not find audio stream"); codec_context = format_context->streams[audio_stream_index]->codec; codec = avcodec_find_decoder(codec_context->codec_id); if (!codec) ErrorExit("could not find codec"); if (avcodec_open(codec_context, codec) < 0) ErrorExit("could not open avcodec"); outfile = fopen(argv[2], "wb"); if (!outfile) ErrorExit("could not open outfile"); outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); if (!outbuf) ErrorExit("malloc() failed"); while (av_read_frame(format_context, &av_packet) >= 0) { if (av_packet.stream_index == audio_stream_index) { out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; // --> Hier kracht es <-------------------------------------------- avcodec_decode_audio3(codec_context, (short*)outbuf, &out_size, &av_packet); if(out_size > 0) { fwrite(outbuf, 1, out_size, outfile); } } av_free_packet(&av_packet); } fclose(outfile); fclose(infile); free(outbuf); avcodec_close(codec_context); printf("Success!"); return 0; }
-
Vielleicht hilft dir der Link ein bisschen: http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html FFmpeg ist nicht das best dokumentierte Projekt.
Im Notfall ruf halt das Kommandozeilenprogramm ffmpeg aus deinem Code auf.
-
Erstmal vielen Dank für die schnelle Antwort.
Den Link kenne ich leider schon - hilft nicht wirklich weiterDas Kommandozeilenprogramm aufzurufen ginge natürlich, allerdings wäre das wirklich nur eine Notlösung für mich..
Um hier noch mal das praktische Problem zu beschreiben:
Es geht darum aus .flv Containern (H264 Bild - AAC Ton) entweder einfach die reine AAC Spur zu rippen oder eine MP3 Datei zu basteln. (Oder kleiner Zusatz wäre noch .ogg)Aufgabengebiete wären also: AAC Dekodieren, MP3 Kodieren, OGG Kodieren. (Vielleicht noch AAC "Re"-Kodieren ;))
Falls jemand eine andere gute .lib kennt (am besten Plattformunabhängig, sonst Windows) die das leisten kann - immer her damit!