Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#3107 closed defect (fixed)

Problem using muxing example

Reported by: a Owned by: Anshul
Priority: minor Component: documentation
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: yes

Description

Summary of the bug:
I am having issues using muxing example provided with the ffpmeg version ffmpeg-20131026-git-c78a416-win32-dev

When i use it to generate

  1. .mpg i get following error

muxing.exe test.mpg

[mp2 @ 004462a0] Specified sample format fltp is invalid or not supported
Could not open audio codec: Error number -22 occurred

  1. mp4 i get following error

muxing.exe test.mp4

[libx264 @ 00613280] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 00613280] profile High, level 1.3
[libx264 @ 00613280] 264 - core 138 r2358 9e941d1 - H.264/MPEG-4 AVC codec - Cop
yleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
ma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 i
nterlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1
b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=12 keyint_min=1 scenecut
=40 intra_refresh=0 rc_lookahead=12 rc=abr mbtree=1 bitrate=400 ratetol=1.0 qcom
p=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[libvo_aacenc @ 00614040] Specified sample format fltp is invalid or not support
ed
Could not open audio codec: Error number -22 occurred

It seems like error is coming from avcodec_open2() in open_audio()

Please let me know if i am missing something or i need to set something else to make it work

How to reproduce:

% muxing.exe test.mpg

ffmpeg version
ffmpeg-20131026-git-c78a416-win32-dev

built on Windows using MSVC 2012

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (17)

comment:1 by a, 10 years ago

I was wondering if anybody get a chance to review this issue # 3107

Please let me know

  1. if I am not setting somthing for the proper functioning of the mux sample code
  2. if there is a work around for this issue

Appriciate your help

comment:2 by Yisheng Zhao, 10 years ago

Hi, ahsan
Um, I came across the same problem, too. It seemed that the ffmpeg I was using didn't support the AV_SAMPLE_FMT_FLTP (I used the windows version though), which is planar float. I changed my mux example in open_audio function, by assigning c->sample_fmt = AV_SAMPLE_FMT_S16; you can always change the sample format I bet~

comment:3 by a, 10 years ago

Thx Easonic!

In my case audio_codec->sample_fmt is already set to AV_SAMPLE_FMT_S16 and i get this error

in reply to:  3 comment:4 by Yisheng Zhao, 10 years ago

I guess you need to modify the /* create resampler context */ one to get the resampler context; I made the if (c->sample_fmt == AV_SAMPLE_FMT_S16) change for the audio~

Replying to ahsan:

Thx Easonic!

In my case audio_codec->sample_fmt is already set to AV_SAMPLE_FMT_S16 and i get this error

comment:5 by a, 10 years ago

I made two changes

  1. add_stream() changed c->sample_fmt from AV_SAMPLE_FMT_FLTP to AV_SAMPLE_FMT_S16
  2. open_audio() changed if(c->sample_fmt != AV_SAMPLE_FMT_S16) to if(c->sample_fmt == AV_SAMPLE_FMT_S16)

it is not failing any more in open_audio,

I will try it out and see if the change can work

Thanks

in reply to:  5 comment:6 by Yisheng Zhao, 10 years ago

That's exactly the two changes, good luck~

Replying to ahsan:

I made two changes

  1. add_stream() changed c->sample_fmt from AV_SAMPLE_FMT_FLTP to AV_SAMPLE_FMT_S16
  2. open_audio() changed if(c->sample_fmt != AV_SAMPLE_FMT_S16) to if(c->sample_fmt == AV_SAMPLE_FMT_S16)

it is not failing any more in open_audio,

I will try it out and see if the change can work

Thanks

comment:7 by a, 10 years ago

Above solution seems to get synthetic audio in the stream from muxing application,
thx for your help

I am still having an issue where i am trying to

  1. demux the .mp4 using demuxing example and then
  2. mux it using muxing application

in the demux i have decoded data in
frame->extended_data buffer with the size of
unpadded_linesize = frame->nb_symbols*frame->format where
nb_symbols=1024, format=8, it is 8k of data

in the muxing example the audio buffer is filled up using
nb_symbols=1024 and nb_channel=2

I am not sure how to map 8k data into the muxing buffer, i have couple of questions

  1. how can i map this decoded buffer [demuxing example] to the emcoder buffer [muxing example]
  2. Is it possible to not decode the audio samples and just mux the audio sample after getting it from the demux

Please let me know if there is a sample example for that available

Really appriciate your help

comment:8 by a, 10 years ago

i did an experiment where i used

orig_pkt from demuxing example when it is audio packet
interleaved it bypassing the encoding of the decoded audio in muxing example

I can now hear the correct sound during the playback but it is not sync at all, i guess some kind of a/v sync logic is needed, any ideas?

in reply to:  8 comment:9 by Yisheng Zhao, 10 years ago

I'm also doing the remuxing stuff now; let's keep in touch.
I will do that part during weekend, now I'm handling the video part by extracting the AVPacket.data and encapsulate into NALUs...lol

Replying to ahsan:

i did an experiment where i used

orig_pkt from demuxing example when it is audio packet
interleaved it bypassing the encoding of the decoded audio in muxing example

I can now hear the correct sound during the playback but it is not sync at all, i guess some kind of a/v sync logic is needed, any ideas?

comment:10 by a, 10 years ago

I merged, demux and mux example codes so that i can take in any .mp4/.avi/mpg files and then re-encode them in the same format

I am having following issues

  1. MUX example code uses avformat_alloc_output_context2() to create the output context for example for .mpg it will choose MPEG1 encoder, the .mpg file i used is encoded using MPEG2 encoder.

I was wondering how can i select different encoders, is there any API call which i can use to re-set the encoder name in the context encoder fails

  1. I uses the fmt_ctx from decoder to set the encoder parameters, i try to memcpy the context (decoder to encoder for the codec) but it fails by setting the different parameters from fmt_ctx to the c

c->width = fmt_ctx->streams[video_stream_idx]->codec->width;
c->height = fmt_ctx->streams[video_stream_idx]->codec->height;
c->coded_width = fmt_ctx->streams[video_stream_idx]->codec>coded_width;

........................

c->gop_size = fmt_ctx->streams[video_stream_idx]->codec->gop_size;

/* emit one intra frame every twelve frames at most */

c->bit_rate = (fmt_ctx->streams[video_stream_idx]->codec->bit_rate == 0) ? 400000 :
fmt_ctx->streams[video_stream_idx]->codec->bit_rate;

/* i am seting it to 400kbps in case it is set to 0 as i am seeing it for some stream */


........................

I am seeing different issue

  1. GOP Size fmt_ctx most of the time has gop_size = 12 which does not seems like the case for the original/input stream


  1. bit-rate i am getting in the output .mp4 is way higher then the one i see from the fmt_ctx, it seems like encoded bit-stream is in 50Mbits/sec where as input .mp4 was 300kbps or 400kbps bit-rate


I am wondering what is the best way to set the encoder context using the input bitstream
[.mp4, .avi, .mpg etc] files

Please let me know if you are able to figure it out

in reply to:  10 comment:11 by Yisheng Zhao, 10 years ago

Replying to ahsan:

I merged, demux and mux example codes so that i can take in any .mp4/.avi/mpg files and then re-encode them in the same format

I am having following issues

  1. MUX example code uses avformat_alloc_output_context2() to create the output context for example for .mpg it will choose MPEG1 encoder, the .mpg file i used is encoded using MPEG2 encoder.

I was wondering how can i select different encoders, is there any API call which i can use to re-set the encoder name in the context encoder fails

  1. I uses the fmt_ctx from decoder to set the encoder parameters, i try to memcpy the context (decoder to encoder for the codec) but it fails by setting the different parameters from fmt_ctx to the c

c->width = fmt_ctx->streams[video_stream_idx]->codec->width;
c->height = fmt_ctx->streams[video_stream_idx]->codec->height;
c->coded_width = fmt_ctx->streams[video_stream_idx]->codec>coded_width;

........................

c->gop_size = fmt_ctx->streams[video_stream_idx]->codec->gop_size;

/* emit one intra frame every twelve frames at most */

c->bit_rate = (fmt_ctx->streams[video_stream_idx]->codec->bit_rate == 0) ? 400000 :
fmt_ctx->streams[video_stream_idx]->codec->bit_rate;

/* i am seting it to 400kbps in case it is set to 0 as i am seeing it for some stream */


........................

I am seeing different issue

  1. GOP Size fmt_ctx most of the time has gop_size = 12 which does not seems like the case for the original/input stream


  1. bit-rate i am getting in the output .mp4 is way higher then the one i see from the fmt_ctx, it seems like encoded bit-stream is in 50Mbits/sec where as input .mp4 was 300kbps or 400kbps bit-rate


I am wondering what is the best way to set the encoder context using the input bitstream
[.mp4, .avi, .mpg etc] files

Please let me know if you are able to figure it out

Hi, ahsan

Sorry for the delay, really busy for the project. Um, do you resolve that issue? I met maybe the same problem here, what I did was just:
avcodec_copy_context(vStream->codec, inFormatCtx->streams[video_idx]->codec);
but found that the output avformatcontext complains about the codec_tag.
Thus, I traced the problem, found that after avformat_write_header(outFmtCtx, NULL);, some parameter in the output avformatcontext->streams[video]->codec will change; thus I set the parameter to zero before avformat_write_header(outFmtCtx, NULL); and that works.
For my experiment, I found that to get the correct duration and time_base (you can treat it as after parsing the codeccontext parameter), I need to set videostream's codec to:
/*

  • IMPORTANT!!! Set the stream->codec information:
  • Copy all the CodecFormat info except the time_base and codec_tag
  • video_stream->codec->time_base: set to inputFmtCtx->vStream->time_base
  • video only!
  • video_stream->codec->codec_tag: calculate by av_write_header
  • video_stream->codec->flags : set global if the output format need
  • global /

Um, and for audio, just skip the time_base part, and it works for me, too.

If you need my code (what I was doing was to remux files without reencoding.), I will email to you later~

comment:12 by a, 10 years ago

Hi easonic,

I am still having the issues where output frame rate, bit rate, codec fields has issues, Please see if you can send me you remux - re encoding sample code

I will appreciate that

Regards
Ahsan

comment:13 by Anshul, 10 years ago

Cc: Anshul added
Component: undeterminedavcodec
Owner: set to Anshul
Reproduced by developer: set
Status: newopen
Version: unspecifiedgit-master

comment:14 by Carl Eugen Hoyos, 10 years ago

Component: avcodecundetermined
Reproduced by developer: unset
Resolution: invalid
Status: openclosed

Please move this discussion to the libav-user mailing list, this is a bug tracker, not a support forum.

Last edited 10 years ago by Carl Eugen Hoyos (previous) (diff)

in reply to:  1 comment:15 by Stefano Sabatini, 10 years ago

Analyzed by developer: set
Component: undetermineddocumentation

Replying to ahsan:

I was wondering if anybody get a chance to review this issue # 3107

Please let me know

  1. if I am not setting somthing for the proper functioning of the mux sample code
  2. if there is a work around for this issue

Appriciate your help

This was fixed in:

commit 2aa2b4ac6555bb4af3f3542c88e7710eca1a57c0
Author: Stefano Sabatini <stefasab@gmail.com>
Date:   Tue Jul 2 16:28:47 2013 +0200

    examples/muxing: add support to audio resampling
    
    Allows to encode to output in case the destination sample format is
    different from AV_SAMPLE_FMT_S16.

and in the following commits. Also the error message you got was pretty explicit in my opinion.

comment:16 by Carl Eugen Hoyos, 10 years ago

Priority: normalminor
Resolution: invalidfixed

comment:17 by Anshul, 10 years ago

Cc: Anshul removed
Note: See TracTickets for help on using tickets.