Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
FFMPEG and SDL : No available audio device [closed]
5 mars 2013, par user948620I have a sample audio program. compiled using gcc
#include
avcodec.h> #include avformat.h> #include SDL.h> #include SDL_thread.h> #define FILENAME "/Desktop/sample.mp3" #define SDL_AUDIO_BUFFER_SIZE 1024 #define SDL_AUDIO_DRIVER_COREAUDIO 1 typedef struct PacketQueue { AVPacketList *first_pkt, *last_pkt; int nb_packets; int size; SDL_mutex *mutex; SDL_cond *cond; } PacketQueue; PacketQueue audioq; void audio_callback(void *userdata, Uint8 *stream, int len) { AVCodecContext *aCodecCtx = (AVCodecContext *)userdata; int len1, audio_size; static uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; static unsigned int audio_buf_size = 0; static unsigned int audio_buf_index = 0; while(len > 0) { if(audio_buf_index >= audio_buf_size) { /* We have already sent all our data; get more */ audio_size = audio_decode_frame(aCodecCtx, audio_buf, sizeof(audio_buf)); if(audio_size < 0) { /* If error, output silence */ audio_buf_size = 1024; // arbitrary? memset(audio_buf, 0, audio_buf_size); } else { audio_buf_size = audio_size; } audio_buf_index = 0; } len1 = audio_buf_size - audio_buf_index; if(len1 > len) len1 = len; memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1); len -= len1; stream += len1; audio_buf_index += len1; } } void packet_queue_init(PacketQueue *q) { // initialize packet que memset(q, 0, sizeof(PacketQueue)); q->mutex = SDL_CreateMutex(); q->cond = SDL_CreateCond(); } int packet_queue_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; if(av_dup_packet(pkt) < 0) { return -1; } pkt1 = av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; SDL_LockMutex(q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; SDL_CondSignal(q->cond); SDL_UnlockMutex(q->mutex); return 0; } int quit = 0; static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) { // get packet AVPacketList *pkt1; int ret; SDL_LockMutex(q->mutex); for(;;) { if(quit) { ret = -1; break; } pkt1 = q->first_pkt; if (pkt1) { q->first_pkt = pkt1->next; if (!q->first_pkt) q->last_pkt = NULL; q->nb_packets--; q->size -= pkt1->pkt.size; *pkt = pkt1->pkt; av_free(pkt1); ret = 1; break; } else if (!block) { ret = 0; break; } else { SDL_CondWait(q->cond, q->mutex); } } SDL_UnlockMutex(q->mutex); return ret; } int audio_decode_frame(AVCodecContext *aCodecCtx, uint8_t *audio_buf, int buf_size) { // decode audio static AVPacket pkt; static uint8_t *audio_pkt_data = NULL; static int audio_pkt_size = 0; int len1, data_size; for(;;) { while(audio_pkt_size > 0) { data_size = buf_size; //len1 = avcodec_decode_audio3(aCodecCtx, (int16_t *)audio_buf, &data_size, audio_pkt_data, audio_pkt_size); len1 = avcodec_decode_audio3(aCodecCtx, (int16_t *)audio_buf, &data_size, audio_pkt_data); if(len1 < 0) { /* if error, skip frame */ audio_pkt_size = 0; break; } audio_pkt_data += len1; audio_pkt_size -= len1; if(data_size <= 0) { /* No data yet, get more frames */ continue; } /* We have data, return it and come back for more later */ return data_size; } if(pkt.data) av_free_packet(&pkt); if(quit) { return -1; } if(packet_queue_get(&audioq, &pkt, 1) < 0) { return -1; } audio_pkt_data = pkt.data; audio_pkt_size = pkt.size; } } int main() // main { // starts here AVFormatContext *pFormatCtx; AVCodecContext *pCodecCtx; AVCodec *pCodec; SDL_AudioSpec wanted_spec, spec; int res; int audioStream; av_register_all(); avdevice_register_all(); res = av_open_input_file(&pFormatCtx,FILENAME,NULL,0,NULL); // input mp3 file printf("%i\n",res); res = av_find_stream_info(pFormatCtx); // find stream info printf("%i\n",res); //dump_format(pFormatCtx,0,FILENAME,0); int i; for(i=0;inb_streams;i++) { // get codec index if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { audioStream = i; } } if(audioStream == -1) { printf("WALANG CODEC %i",audioStream); return audioStream; } else { printf("May Codec %i\n",audioStream); } pCodecCtx = pFormatCtx->streams[audioStream]->codec; /* pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if(pCodec == NULL) { fprintf(stderr, "Unsupported codec!\n"); return -1; } if(avcodec_open(pCodecCtx,pCodec) < 0) { fprintf(stderr, "Ayaw buksan ang codec!\n"); return -1; } */ wanted_spec.freq = pCodecCtx->sample_rate; wanted_spec.format = AUDIO_S16SYS; wanted_spec.channels = pCodecCtx->channels; wanted_spec.silence = 0; wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; wanted_spec.callback = audio_callback; wanted_spec.userdata = pCodecCtx; if(SDL_OpenAudio(&wanted_spec, &spec) < 0) { fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError()); return -1; } pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if(!pCodec) { fprintf(stderr, "Walang Codec, Unsupported"); return -1; } avcodec_open(pCodecCtx,pCodec); packet_queue_init(&audioq); SDL_PauseAudio(0); return 0; } It compiles successfully. but when i run the program it says
SDL_OpenAudio: No available audio device
I am using SDL Dev library and FFMpeg on Ubuntu 11.10
How to solve this problem?
-
AR Drone 2 and ffserver + ffmpeg streaming
5 mars 2013, par BjarkeHSI want to be able to restream the video feed of the AR Drone 2 from a Debian Server to Flash.
I am aware that the AR Drone uses the codec p264. I'm totally green when it comes to video codecs, so I don't know what will be suitable for the goal I want to achieve?
I have been able to stream the video feed from the AR Drone but with very high latency and extremely low quality, compared to when I directly connect to the AR Drone using ffplay.
I currently use the .swf example in the standard ffserver.conf:
Feed feed1.ffm Format swf VideoFrameRate 30 VideoIntraOnly NoAudio And the settings for the .ffm Feed are as follows:
File /tmp/feed1.ffm FileMaxSize 17K ACL allow 127.0.0.1 NoAudio The command I use for giving input to the ffserver feed:
ffmpeg -i http://192.168.1.1:5555 http://localhost:8090/feed1.ffm
How am I able to achieve lower latency and higher quality, since the stream is currently unwatchable?
-
Use ffmpeg to create the wmv progressive download
5 mars 2013, par AmolI want to create the WMV files for Progressive download and internet streaming using the ffmpeg. How can I use the ffmpeg commands for this?
Any help will be appreciated...
-
Crash on ffmpeg avcodec_encode_video in a Console app
5 mars 2013, par Robel sharmaI want make an encoder which encode a raw image into h263 format.But after loading and initializing ffmpeg library I got crash on avcodec_encode_video for a demo image.
int _tmain(int argc, _TCHAR* argv[]) { avcodec_register_all(); AVCodec *codec; AVCodecContext *c= NULL; int i, ret, x, y, got_output; FILE *f; AVFrame *frame; AVPacket pkt; int out_size, size, outbuf_size; AVFrame *picture; uint8_t *outbuf, *picture_buf; AVRational rp; rp.den = 1; rp.num = 25; uint8_t endcode[] = { 0, 0, 1, 0xb7 }; codec = avcodec_find_encoder(CODEC_ID_H263); c = avcodec_alloc_context3(codec); picture= avcodec_alloc_frame(); c->bit_rate = 400000; /* resolution must be a multiple of two */ c->width = 352; c->height = 288; /* frames per second */ //c->time_base= (AVRational){1,25}; c->time_base = rp; c->gop_size = 10; /* emit one intra frame every ten frames */ c->max_b_frames=1; c->pix_fmt = PIX_FMT_YUV420P; avcodec_open(c, codec); outbuf_size = 100000; outbuf = (uint8_t*)malloc(outbuf_size); size = c->width * c->height; picture_buf = (uint8_t*)malloc((size * 3) / 2); /* size for YUV 420 */ picture->data[0] = picture_buf; picture->data[1] = picture->data[0] + size; picture->data[2] = picture->data[1] + size / 4; picture->linesize[0] = c->width; picture->linesize[1] = c->width / 2; picture->linesize[2] = c->width / 2; /* encode 1 second of video */ for(i=0;i<25;i++) { fflush(stdout); /* prepare a dummy image */ /* Y */ for(y=0;yheight;y++) { for(x=0;xwidth;x++) { picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3; } } /* Cb and Cr */ for(y=0;yheight/2;y++) { for(x=0;xwidth/2;x++) { picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2; picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5; } } /* encode the image */ **Crash is here** ---> /////////////////////////////////////////////////// out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture); printf("encoding frame %3d (size=%5d)\n", i, out_size); fwrite(outbuf, 1, out_size, f); } /* get the delayed frames */ for(; out_size; i++) { fflush(stdout); out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); printf("write frame %3d (size=%5d)\n", i, out_size); fwrite(outbuf, 1, out_size, f); } /* add sequence end code to have a real mpeg file */ outbuf[0] = 0x00; outbuf[1] = 0x00; outbuf[2] = 0x01; outbuf[3] = 0xb7; fwrite(outbuf, 1, 4, f); fclose(f); free(picture_buf); free(outbuf); avcodec_close(c); av_free(c); av_free(picture); printf("\n"); return 0; }
-
To change the audio of the running live video
5 mars 2013, par Tushar SharmaI want to change the audio of the running video in my application. For example, when I open my application it contain camera screen. Now I want that I can see the video that I am watching from the camera but the audio get changed.