h4tr3d / avcpp

C++ wrapper for FFmpeg
Other
429 stars 78 forks source link

Error when using code from api2-remux.cpp sample. #130

Closed akochkarev closed 2 months ago

akochkarev commented 4 months ago

Hello!

I am trying to adapt this sample (api2-remux.cpp) for truncating audio files to needed duration without reencoding.

But facing next issue: When coping streams

       // copy codec settings
        ocoder.copyContextFrom(icoder);

exception arises: "Codec context invalid" and log says: [NULL @ 0x562aaeddb780] copyContextFrom: Invalid target context

Log:

[wav @ 0x562aaed89fc0] Opening 'test.wav' for reading
[file @ 0x562aaed8b840] Setting default whitelist 'file,crypto,data'
[wav @ 0x562aaed89fc0] Before avformat_find_stream_info() pos: 80 bytes read:32768 seeks:0 nb_streams:1
[wav @ 0x562aaed89fc0] parser not found for codec pcm_f32le, packets or times may be invalid.
[wav @ 0x562aaed89fc0] parser not found for codec pcm_f32le, packets or times may be invalid.
[wav @ 0x562aaed89fc0] max_analyze_duration 5000000 reached at 5120000 microseconds st:0
[wav @ 0x562aaed89fc0] After avformat_find_stream_info() pos: 176208 bytes read:196608 seeks:0 frames:42
Input #0, wav, from 'test.wav':
  Duration: 00:00:14.45, bitrate: 256 kb/s
  Stream #0:0, 42, 1/8000: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 8000 Hz, 1 channels, flt, 256 kb/s
[NULL @ 0x562aaeddb780] copyContextFrom: Invalid target context
terminate called after throwing an instance of 'av::Exception'
  what():  Codec context invalid

Any ideas, what can be wrong here? Thanks!

h4tr3d commented 4 months ago

Will look today

h4tr3d commented 4 months ago

@akochkarev , could you please check latest master code?

akochkarev commented 4 months ago

@h4tr3d , thanks for response!

I've tested api2-remux.cpp example from latest master sources today. And now it works good.

But I see that there some new methods like Stream::codecParameters() was added and this breaks compatibility with v2.2.1 which I use from vcpkg currently.

Waiting for a new release :) Thanks for a cool project!

h4tr3d commented 4 months ago

Oops... vcpkg... I forgot about them.

h4tr3d commented 4 months ago

vcpkg PR: https://github.com/microsoft/vcpkg/pull/37366

Note, I rework the decode/encode functionality for now that breaks back compatibility. It will be released as v3.0.0. New functionality are required for more flexible using of the avcodec_send_XXX/avcode_receive_XXX approach.

mojie126 commented 3 months ago

vcpkg PR: microsoft/vcpkg#37366

Note, I rework the decode/encode functionality for now that breaks back compatibility. It will be released as v3.0.0. New functionality are required for more flexible using of the avcodec_send_XXX/avcode_receive_XXX approach.

Great, does the new version support hardware encoding/decoding such as CUDA?

h4tr3d commented 3 months ago

does the new version support hardware encoding/decoding such as CUDA?

There is no any changes in this direction. But, it is still usable via direct FFmpeg usage (raw() method).

mojie126 commented 3 months ago

I tested version 6.1, and it seems that it is not supported either, for example avcodec_register_all

h4tr3d commented 3 months ago

More details are needed.