Hi, there is a possible SIMPLE example that do a SIMPLE transcode from
h264/mlaw to mpeg4/aac?

I still have not yet found one that works (ffmpeg/transcode.c not work)

I post my code: there is a problem on avcodec_encode_audio2 
-22 Invalid Argument (Input contains NaN)

I want to make code very simple, so I don’t want to use fifo_queue and more,
because the video type is only in one format (webcam)

Dump is correct:
Input #0, avi, from 
'/Users/Shinnok/Library/Developer/Xcode/DerivedData/RainBlack-bamexxbsnwvvoqfegnzeexphynmr/Build/Products/Debug/camera.avi':
  Duration: 00:00:11.60, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Baseline) (h264 / 0x34363268), yuv420p(tv), 
1280x720, 1003 kb/s, 15 fps, 15 tbr, 15 tbn, 30 tbc
    Stream #0:1: Audio: pcm_mulaw ([7][0][0][0] / 0x0007), 8000 Hz, 1 channels, 
s16, 64 kb/s
Output #0, mp4, to 
'/Users/Shinnok/Library/Developer/Xcode/DerivedData/RainBlack-bamexxbsnwvvoqfegnzeexphynmr/Build/Products/Debug/output.mp4':
  Metadata:
    encoder         : Lavf56.25.101
    Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1280x720, q=2-31, 
1200 kb/s, 15360 tbn, 15 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, fltp, 16 
kb/s

(It’s in Objc)
Thanks,
Gabriele



__block struct AVFormatContext *inputCtx = NULL;
        __block struct AVFormatContext *outputCtx = NULL;
        __block int ret = 0;
        
        __block void (^mainProcess)() = ^{
                __block struct AVPacket packet;
                __block struct AVFrame *frame;
                
                while (true) {

                        if ((ret = av_read_frame(inputCtx, &packet)) < 0) {
                                break;
                        }

                        frame = av_frame_alloc();
                        unsigned int streamIdx = packet.stream_index;
                        int got_packet = 0;
                        av_packet_rescale_ts(&packet,
                                                                 
inputCtx->streams[streamIdx]->time_base,
                                                                 
inputCtx->streams[streamIdx]->codec->time_base);
                        enum AVMediaType type = 
inputCtx->streams[streamIdx]->codec->codec_type;
                        int len = 0;
                        if (type ==  AVMEDIA_TYPE_VIDEO) {
                                NSLog(@"Decoded video");
                                len = 
avcodec_decode_video2(inputCtx->streams[streamIdx]->codec, frame, &got_packet, 
&packet);
                        } else if (type ==  AVMEDIA_TYPE_AUDIO) {
                                NSLog(@"Decoded audio");
                                len = 
avcodec_decode_audio4(inputCtx->streams[streamIdx]->codec, frame, &got_packet, 
&packet);
                        }
                        
                        if (len < 0) {
                                av_frame_free(&frame);
                                av_log(NULL, AV_LOG_ERROR, "Decoding failed\n");
                                exit(1);
                        }
                        
                        while (got_packet) {
                                NSLog(@"Encoding...");
                                AVPacket enc_pkt;
                                
                                /* encode filtered frame */
                                enc_pkt.data = NULL;
                                enc_pkt.size = 0;
                                
                                av_init_packet(&enc_pkt);
                                
                                if (type == AVMEDIA_TYPE_VIDEO) {
                                        NSLog(@"Encoding video");
                                        if ((ret = 
avcodec_encode_video2(outputCtx->streams[streamIdx]->codec, &enc_pkt, frame, 
&got_packet)) < 0) {
                                                av_frame_free(&frame);
                                                exit(1);
                                        }
                                } else {
                                        NSLog(@"Encoding audio");
                                        frame->pts = 
av_frame_get_best_effort_timestamp(frame);
                                        if ((ret = 
avcodec_encode_audio2(outputCtx->streams[streamIdx]->codec, &enc_pkt, frame, 
&got_packet)) < 0) {
                                                NSLog(@"avcodec_encode_audio2 
%s", av_err2str(ret));
                                                av_frame_free(&frame);
                                                exit(1);
                                        }
                                }

                                while (got_packet) {
                                        NSLog(@"Write packet");
                                        /* prepare packet for muxing */
                                        enc_pkt.stream_index = streamIdx;
                                        av_packet_rescale_ts(&enc_pkt,
                                                                                
 outputCtx->streams[streamIdx]->codec->time_base,
                                                                                
 outputCtx->streams[streamIdx]->time_base);
                                        
                                        av_log(NULL, AV_LOG_DEBUG, "Muxing 
frame\n");
                                        /* mux encoded frame */
                                        ret = 
av_interleaved_write_frame(outputCtx, &enc_pkt);
                                }
                        }
                        packet.data += len;
                        packet.size -= len;
                        
                        av_frame_free(&frame);
                }
                
                av_write_trailer(outputCtx);
                dispatch_async(callbackQueue, ^{
                        NSLog(@"FINISH");
                });
                

 

 

 --

 ZE-Light e ZE-Pro: servizi zimbra per caselle con dominio email.it, per tutti 
i dettagli 

Clicca qui 
http://posta.email.it/caselle-di-posta-z-email-it/?utm_campaign=email_Zimbra_102014=main_footer/f

 

 Sponsor:

 Soluzioni di email hosting per tutte le esigenze: dalle caselle gratuite a 
quelle professionali su piattaforma Zimbra, da quelle su proprio dominio a 
quelle certificate PEC. Confronta le soluzioni

 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13326&d=1-4

_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to