Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
how to play mp3 using ffmpeg
5 novembre 2013, par AriI'm trying to play audio mp3 file using ffmpeg in android but I'm facing a problem in the below mentioned code
how to play mp3 using ffmpeg
void JNICALL Java_com_music_MainActivity_loadFile(JNIEnv* env, jobject obj,jstring file,jbyteArray array) { jboolean isfilenameCopy; const char * filename = (*env)->GetStringUTFChars(env, file, &isfilenameCopy); AVCodec *codec; AVCodecContext *c= NULL; int out_size, len; FILE *f, *outfile; uint8_t *outbuf; uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; AVPacket avpkt; jclass cls = (*env)->GetObjectClass(env, obj); jmethodID play = (*env)->GetMethodID(env, cls, "playSound", "([BI)V");//At the begining of your main function av_init_packet(&avpkt); printf("Audio decoding\n"); __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, "inside load file"); /* find the mpeg audio decoder */ codec = avcodec_find_decoder(CODEC_ID_MP3); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } c= avcodec_alloc_context(); /* open it */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, "open avcode"); outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, "open %s",outbuf); f = fopen(filename, "rb"); if (!f) { fprintf(stderr, "could not open %s\n", filename); exit(1); } /* decode until eof */ avpkt.data = inbuf; avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, "data =%s and size %d",avpkt.data,avpkt.size); while (avpkt.size > 0) { out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt); __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, "length =%d",len); if (len < 0) { fprintf(stderr, "Error while decoding\n"); __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, " failed length =%d",errno); exit(1); } if (out_size > 0) { /* if a frame has been decoded, output it */ jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL); memcpy(bytes, outbuf, out_size); // (*env)->ReleaseByteArrayElements(env, array, bytes, 0); (*env)->CallVoidMethod(env, obj, play, array, out_size); } avpkt.size -= len; avpkt.data += len; if (avpkt.size < AUDIO_REFILL_THRESH) { /* Refill the input buffer, to avoid trying to decode * incomplete frames. Instead of this, one could also use * a parser, or use a proper container format through * libavformat. */ memmove(inbuf, avpkt.data, avpkt.size); avpkt.data = inbuf; len = fread(avpkt.data + avpkt.size, 1, AUDIO_INBUF_SIZE - avpkt.size, f); if (len > 0) avpkt.size += len; } } fclose(f); free(outbuf); avcodec_close(c); av_free(c); }
i am getting the len = - 1 in
len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);
what am i doing wrong??
please help
-
compile FFmpeg error on windows when run ./configure
5 novembre 2013, par user1325717I want to use FFmpeg to decode mp3 and acc on android, I use android-ndk-r7 and the newest cygwin.
I wrote a shell config.sh, which content is:
TMPDIR=/cygdrive/c/temp PREBUILT=/cygdrive/c/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows PLATFORM=/cygdrive/c/android-ndk-r7/platforms/android-8/arch-arm ./configure --target-os=linux --arch=arm --enable-version3 --enable-gpl --enable-nonfree --disable-stripping --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-ffprobe --disable-encoders --disable-muxers --disable-devices --disable-protocols --enable-protocol=file --enable-avfilter --disable-network --disable-mpegaudio-hp --disable-avdevice --enable-cross-compile --cc=$PREBUILT/bin/arm-linux-androideabi-gcc --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- --nm=$PREBUILT/bin/arm-linux-androideabi-nm --extra-cflags="-fPIC -DANDROID" --disable-asm --enable-neon --enable-armv5te --extra-ldflags="-Wl,-T,$PREBUILT/arm-eabi/lib/ldscripts/armelf_linux_eabi.x -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtbegin.o $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtend.o -lc -lm -ldl"
I open cmd and do bash to open cygwin shell, then do ./config, the problem is appeared: "/cygdrive/c/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc is unable to create an executable file..."
the config.log is:
check_ld check_cc BEGIN /cygdrive/c/temp/ffconf.SFJc3t92.c 1 int main(void){ return 0; } END /cygdrive/c/temp/ffconf.SFJc3t92.c gcc -fPIC -DANDROID -std=c99 -c -o /cygdrive/c/temp/ffconf.YKRv5TSp.o /cygdrive/c/temp/ffconf.SFJc3t92.c /cygdrive/c/temp/ffconf.SFJc3t92.c:1:0: warning: -fPIC ignored for target (all code is position independent) gcc -Wl,-rpath-link=/cygdrive/c/android-ndk-r7/platforms/android-4/arch-arm/usr/lib -L/cygdrive/c/android-ndk-r7/platforms/android-4/arch-arm/usr/lib -nostdlib /cygdrive/c/android-ndk-r7/platforms/android-4/arch-arm/usr/lib/crtbegin_static.o /cygdrive/c/android-ndk-r7/platforms/android-4/arch-arm/usr/lib/crtend_android.o -lc -lm -ldl -o /cygdrive/c/temp/ffconf.Yf1Ftjmo /cygdrive/c/temp/ffconf.YKRv5TSp.o /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: /cygdrive/c/android-ndk-r7/platforms/android-4/arch-arm/usr/lib/crtbegin_static.o: Relocations in generic ELF (EM: 40) /cygdrive/c/android-ndk-r7/platforms/android-4/arch-arm/usr/lib/crtbegin_static.o: could not read symbols: File in wrong format collect2: ld returned 1 exit status C compiler test failed.
I don't know what is happened, is there someone who know what is happened, thanks.
-
ffmpeg fastest way to convert videos avi to mp4 [migrated]
5 novembre 2013, par user2938660I have server which has:
- 8x3,4 (sandy bridge cpu)
- 10gb ram
i tried different combinations to convert vvideos i mean avi to mp4 but it takes so long: - ~20mins=~200mb
maybe there is some ffmpeg command which does this much faster?
EDIT WITH ULTRAFAST:
root@1tb:~/test# ffmpeg -i video.avi -c:v libx264 -preset ultrafast out.mp4 ffmpeg version git-2013-10-28-f1f0b01 Copyright (c) 2000-2013 the FFmpeg developers built on Oct 29 2013 02:05:45 with gcc 4.4.5 (Debian 4.4.5-8) configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab libavutil 52. 48.100 / 52. 48.100 libavcodec 55. 39.100 / 55. 39.100 libavformat 55. 19.104 / 55. 19.104 libavdevice 55. 5.100 / 55. 5.100 libavfilter 3. 90.100 / 3. 90.100 libswscale 2. 5.101 / 2. 5.101 libswresample 0. 17.104 / 0. 17.104 libpostproc 52. 3.100 / 52. 3.100 Input #0, avi, from 'video.avi': Duration: 00:29:00.28, start: 0.000000, bitrate: 1120 kb/s Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 23.98 tbr, 23.98 tbn, 23.98 tbc Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 128 kb/s Metadata: title : Hello.Ladies.S01E06.HDTV.XviD-AFG_360p.audio [libx264 @ 0x2e08e40] using SAR=1/1 [libx264 @ 0x2e08e40] using cpu capabilities: none! [libx264 @ 0x2e08e40] profile Constrained Baseline, level 3.0 [libx264 @ 0x2e08e40] 264 - core 138 r2358 9e941d1 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=23 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0 Output #0, mp4, to 'out.mp4': Metadata: encoder : Lavf55.19.104 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 10000k tbn, 23.98 tbc Stream #0:1: Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 128 kb/s Metadata: title : Hello.Ladies.S01E06.HDTV.XviD-AFG_360p.audio Stream mapping: Stream #0:0 -> #0:0 (mpeg4 -> libx264) Stream #0:1 -> #0:1 (mp3 -> libfaac) Press [q] to stop, [?] for help frame=41726 fps=326 q=-1.0 Lsize= 312916kB time=00:29:00.32 bitrate=1473.0kbits/s dup=1 drop=0 video:284876kB audio:27186kB subtitle:0 global headers:0kB muxing overhead 0.273494% [libx264 @ 0x2e08e40] frame I:167 Avg QP:18.69 size: 30492 [libx264 @ 0x2e08e40] frame P:41559 Avg QP:21.68 size: 6897 [libx264 @ 0x2e08e40] mb I I16..4: 100.0% 0.0% 0.0% [libx264 @ 0x2e08e40] mb P I16..4: 6.3% 0.0% 0.0% P16..4: 51.2% 0.0% 0.0% 0.0% 0.0% skip:42.5% [libx264 @ 0x2e08e40] coded y,uvDC,uvAC intra: 44.9% 54.5% 19.0% inter: 28.1% 20.3% 2.2% [libx264 @ 0x2e08e40] i16 v,h,dc,p: 43% 23% 21% 13% [libx264 @ 0x2e08e40] i8c dc,h,v,p: 36% 22% 32% 11% [libx264 @ 0x2e08e40] kb/s:1340.96 root@1tb:~/test# qt-faststart out.mp4 labas1.mp4 ftyp 0 32 free 32 8 mdat 40 319552104 moov 319552144 873943 patching stco atom... patching stco atom... writing ftyp atom... writing moov atom... copying rest of file... root@1tb:~/test#
-
FFmpeg detecting the first frame after a commercial
5 novembre 2013, par William Joe BaldwinI've been searching for a way to detect the very first frame after a commercial in FFmpeg. My recorder records TV shows, approximately 1 second before the sequence. Therefore the video file starts with few frames of the commercial.
By checking the page below, it seems there is a way to detect scene changes:
Extract Thumbnails of Every Camera Change on a Video File
Does anyone know a way to rewrite the code from the link to get the first scene change as frame count?
Thanks!
-
x264 parameters configuration
5 novembre 2013, par user1558688I need to configure x264 to reproduce the below parameters.
The configuration was extracted using Elecard Stream Analyzer from the first keyframe received from a legacy SIP phone h264 encoder. It is mission critical to reproduce it in software to keep compatibility with other sip clients.
All the information I have are the parameters below.
Is it possible at least to get close to the original ?
Thanks a lot.
0x00000000 H264 Sequence Parameter Set profile_idc = 66 (PROFILE_IDC_Baseline) constraint_set0_flag = 1 constraint_set1_flag = 0 constraint_set2_flag = 0 constraint_set3_flag = 0 constraint_set4_flag = 0 constraint_set5_flag = 0 reserved_zero_2bits = 0 level_idc = 12 seq_parameter_set_id = 4 log2_max_frame_num_minus4 = 4 pic_order_cnt_type = 2 num_ref_frames = 1 gaps_in_frame_num_value_allowed_flag = 0 pic_width_in_mbs_minus1 = 19 (320) pic_height_in_map_units_minus1 = 14 (240) frame_mbs_only_flag = 1 direct_8x8_inference_flag = 1 frame_cropping_flag = 0 vui_parameters_present_flag = 0 0x0000000C H264 Picture Parameter Set pic_parameter_set_id = 4 seq_parameter_set_id = 4 entropy_coding_mode_flag = 0 pic_order_present_flag = 0 num_slice_groups_minus1 = 0 num_ref_idx_L0_active_minus1 = 0 num_ref_idx_L1_active_minus1 = 0 weighted_pred_flag = 0 weighted_bipred_idc = 0 pic_init_qp_minus26 = 2 pic_init_qs_minus26 = 0 chroma_qp_index_offset = 0 deblocking_filter_control_present_flag = 1 constrained_intra_pred_flag = 0 redundant_pic_cnt_present_flag = 0 0x00000014 H264 I slice #1 { frame_num = 0 } first_mb_in_slice = 0 slice_type = 2 pic_parameter_set_id = 4 frame_num = 0 idr_pic_id = 4 dec_ref_pic_marking(): if(IdrPicFlag) no_output_of_prior_pics_flag = 0 long_term_reference_flag = 0 slice_qp_delta = 0 disable_deblocking_filter_idc = 0 slice_alpha_c0_offset_div2 = 0 slice_beta_offset_div2 = 0 0x00000591 H264 I slice #1 { frame_num = 0 } first_mb_in_slice = 126 slice_type = 2 pic_parameter_set_id = 4 frame_num = 0 idr_pic_id = 4 dec_ref_pic_marking(): if(IdrPicFlag) no_output_of_prior_pics_flag = 0 long_term_reference_flag = 0 slice_qp_delta = 0 disable_deblocking_filter_idc = 0 slice_alpha_c0_offset_div2 = 0 slice_beta_offset_div2 = 0 0x00000B34 H264 I slice #1 { frame_num = 0 } first_mb_in_slice = 201 slice_type = 2 pic_parameter_set_id = 4 frame_num = 0 idr_pic_id = 4 dec_ref_pic_marking(): if(IdrPicFlag) no_output_of_prior_pics_flag = 0 long_term_reference_flag = 0 slice_qp_delta = 0 disable_deblocking_filter_idc = 0 slice_alpha_c0_offset_div2 = 0 slice_beta_offset_div2 = 0