Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support output mpegts with only audio stream #23

Closed
jalonsoa opened this issue Jan 12, 2015 · 11 comments
Closed

Support output mpegts with only audio stream #23

jalonsoa opened this issue Jan 12, 2015 · 11 comments

Comments

@jalonsoa
Copy link
Contributor

Hi,
android >4.4.3 don't support m3u8 live with aac files. Only support mpegts as fragments on m3u8 playlist.

We can generate an ts file with only the aac stream inside ?

thanks
j

@flavioribeiro
Copy link
Owner

hi @jalonsoa, yes we can do it. If I'm not being betrayed by my memory, all you need to do is change the oformat on output_format_context:

diff --git ngx_http_aac_module.c ngx_http_aac_module.c
index dbff3a7..776de23 100644
--- ngx_http_aac_module.c
+++ ngx_http_aac_module.c
@@ -173,7 +173,7 @@ static int ngx_http_aac_extract_audio(ngx_pool_t *pool, ngx_log_t  *log, ngx_str

     io_context = avio_alloc_context(exchange_area, buffer_size, 1, (void *)destination, NULL, write_packet, NULL);
     output_format_context->pb = io_context;
-    output_format_context->oformat = av_guess_format("adts", NULL, NULL);
+    output_format_context->oformat = input_format_context->oformat;

     avcodec_copy_context(output_audio_stream->codec, input_audio_stream->codec);
     avformat_write_header(output_format_context, NULL);

Don't forget to change the mimetype to video/MP2T and the lua script that generates the audio only m3u8 playlist.

@jalonsoa
Copy link
Contributor Author

Hi Flavio !
thanks for your patch .. but .. don't work .. ;-( ... the nginx crash ..
I'm investigating about it, when have any info I will share.

thanks

j

On Tue, Jan 13, 2015 at 1:16 AM, Flávio Ribeiro notifications@github.com
wrote:

hi @jalonsoa https://github.com/jalonsoa, yes we can do it. If I'm not
being betrayed by my memory, all you need to do is change the oformat
http://ffmpeg.org/doxygen/trunk/structAVFormatContext.html#a20d80ac07e38ff5c268d15aaf2798b98
on output_format_context:

diff --git ngx_http_aac_module.c ngx_http_aac_module.c
index dbff3a7..776de23 100644--- ngx_http_aac_module.c+++ ngx_http_aac_module.c@@ -173,7 +173,7 @@ static int ngx_http_aac_extract_audio(ngx_pool_t *pool, ngx_log_t *log, ngx_str

 io_context = avio_alloc_context(exchange_area, buffer_size, 1, (void *)destination, NULL, write_packet, NULL);
 output_format_context->pb = io_context;-    output_format_context->oformat = av_guess_format("adts", NULL, NULL);+    output_format_context->oformat = input_format_context->oformat;

 avcodec_copy_context(output_audio_stream->codec, input_audio_stream->codec);
 avformat_write_header(output_format_context, NULL);

Don't forget to change the mimetype to video/MP2T and the lua script that
generates the audio only m3u8.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@jalonsoa
Copy link
Contributor Author

Hi Flavio !

this is the gdb stack when the nginx crash.

#0 0x00007fd2f65f2bbd in avformat_write_header () from
/usr/lib/x86_64-linux-gnu/libavformat.so.53
#1 0x00000000004dd06c in ngx_http_aac_extract_audio
(destination=0x24568d0, log=0x2451d40, pool=0x245fc50, source=...)
at
/mnt/filer/personales/root/sysadm/sources/ubuntu-12.04/nginx/nginx-1.7.4/debian/modules/nginx-audio-track-for-hls-module/ngx_http_aac_module.c:180
#2 ngx_http_aac_handler (r=0x245fca0) at
/mnt/filer/personales/root/sysadm/sources/ubuntu-12.04/nginx/nginx-1.7.4/debian/modules/nginx-audio-track-for-hls-module/ngx_http_aac_module.c:27
#3 0x000000000044db02 in ngx_http_core_content_phase (r=0x245fca0,
ph=0x248a180) at src/http/ngx_http_core_module.c:1407
#4 0x00000000004482d5 in ngx_http_core_run_phases (r=0x245fca0) at
src/http/ngx_http_core_module.c:888
#5 0x0000000000454401 in ngx_http_process_request (r=0x245fca0) at
src/http/ngx_http_request.c:1902
#6 0x0000000000455356 in ngx_http_process_request_line (rev=0x24af328) at
src/http/ngx_http_request.c:1012
#7 0x000000000043d6e1 in ngx_epoll_process_events (cycle=0x2452830,
timer=, flags=) at
src/event/modules/ngx_epoll_module.c:691
#8 0x0000000000434087 in ngx_process_events_and_timers (cycle=0x2452830)
at src/event/ngx_event.c:248
#9 0x000000000043b579 in ngx_worker_process_cycle (cycle=0x2452830,
data=) at src/os/unix/ngx_process_cycle.c:822
#10 0x0000000000439ee5 in ngx_spawn_process (cycle=0x2452830, proc=0x43b4c0
<ngx_worker_process_cycle>, data=0x0, name=0x5169fe "worker process",
respawn=0) at src/os/unix/ngx_process.c:198
#11 0x000000000043c972 in ngx_reap_children (cycle=0x2452830) at
src/os/unix/ngx_process_cycle.c:631
#12 ngx_master_process_cycle (cycle=0x2452830) at
src/os/unix/ngx_process_cycle.c:184
#13 0x0000000000419bbd in main (argc=, argv=)
at src/core/nginx.c:407

I have avformat 53 (and all work fine with aac, but with this patch
crash).

thanks
j

On Tue, Jan 13, 2015 at 11:00 AM, Justo Alonso justo.alonso@gmail.com
wrote:

Hi Flavio !
thanks for your patch .. but .. don't work .. ;-( ... the nginx crash
.. I'm investigating about it, when have any info I will share.

thanks

j

On Tue, Jan 13, 2015 at 1:16 AM, Flávio Ribeiro notifications@github.com
wrote:

hi @jalonsoa https://github.com/jalonsoa, yes we can do it. If I'm not
being betrayed by my memory, all you need to do is change the oformat
http://ffmpeg.org/doxygen/trunk/structAVFormatContext.html#a20d80ac07e38ff5c268d15aaf2798b98
on output_format_context:

diff --git ngx_http_aac_module.c ngx_http_aac_module.c
index dbff3a7..776de23 100644--- ngx_http_aac_module.c+++ ngx_http_aac_module.c@@ -173,7 +173,7 @@ static int ngx_http_aac_extract_audio(ngx_pool_t *pool, ngx_log_t *log, ngx_str

 io_context = avio_alloc_context(exchange_area, buffer_size, 1, (void *)destination, NULL, write_packet, NULL);
 output_format_context->pb = io_context;-    output_format_context->oformat = av_guess_format("adts", NULL, NULL);+    output_format_context->oformat = input_format_context->oformat;

 avcodec_copy_context(output_audio_stream->codec, input_audio_stream->codec);
 avformat_write_header(output_format_context, NULL);

Don't forget to change the mimetype to video/MP2T and the lua script
that generates the audio only m3u8.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@jalonsoa
Copy link
Contributor Author

And ... one point. In line 143 ... the "goto exit" line should go after the log, right?

--- ngx_http_aac_module.c   2015-01-13 16:49:29.835110000 +0100
+++ ngx_http_aac_module.c.orig  2015-01-13 16:49:24.090053000 +0100
@@ -140,8 +140,8 @@
     }

     if (avformat_find_stream_info(input_format_context, NULL) < 0) {
-        ngx_log_error(NGX_LOG_ERR, log, 0, "aac module: could not find stream info");
         goto exit;
+        ngx_log_error(NGX_LOG_ERR, log, 0, "aac module: could not find stream info");
     }

     audio_stream_id = av_find_best_stream(input_format_context, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);

@jalonsoa
Copy link
Contributor Author

Sorry,
the patch is opposite ... the correct patch:

--- ngx_http_aac_module.c.orig  2015-01-13 16:49:24.090053000 +0100
+++ ngx_http_aac_module.c   2015-01-13 16:49:29.835110000 +0100
@@ -140,8 +140,8 @@
     }

     if (avformat_find_stream_info(input_format_context, NULL) < 0) {
-        goto exit;
         ngx_log_error(NGX_LOG_ERR, log, 0, "aac module: could not find stream info");
+        goto exit;
     }

     audio_stream_id = av_find_best_stream(input_format_context, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);

@flavioribeiro
Copy link
Owner

hey @jalonsoa, yeah your patch makes sense. Can you send a pull request?

Regarding my patch, I'll try to figure out what's going on, but can you try this approach below first?

diff --git ngx_http_aac_module.c ngx_http_aac_module.c
index dbff3a7..fa87a00 100644
--- ngx_http_aac_module.c
+++ ngx_http_aac_module.c
@@ -123,6 +123,8 @@ static int ngx_http_aac_extract_audio(ngx_pool_t *pool, ngx_log_t  *log, ngx_str

     AVFormatContext *input_format_context = NULL;
     AVFormatContext *output_format_context = NULL;
+    AVOutputFormat *fmt;
     AVStream *input_audio_stream;
     AVStream *output_audio_stream;
     AVPacket packet, new_packet;
@@ -173,7 +175,8 @@ static int ngx_http_aac_extract_audio(ngx_pool_t *pool, ngx_log_t  *log, ngx_str

     io_context = avio_alloc_context(exchange_area, buffer_size, 1, (void *)destination, NULL, write_packet, NULL);
     output_format_context->pb = io_context;
-    output_format_context->oformat = av_guess_format("adts", NULL, NULL);
+    fmt = av_guess_format("mpegts", NULL, NULL);
+    output_format_context->oformat = fmt;

     avcodec_copy_context(output_audio_stream->codec, input_audio_stream->codec);
     avformat_write_header(output_format_context, NULL);

@jalonsoa
Copy link
Contributor Author

Hi Flavio,
I'm trying with this at this moment. I'm preparing a new module option to select the ouput format. Is ok ?

thanks

@flavioribeiro
Copy link
Owner

great, tell me if the last diff works for you 🍻

@jalonsoa
Copy link
Contributor Author

Hi Flavio,
your patch work fine, but I have a new problem. If we want that the user can select the output format (new parameter to select it), we can't suppose that the url get .aac extension to build the source path.

For example, if we select mpegts output format, we expect that the fragments in the new m3u8 audio list be ts files ... so you can't remove aac extension and paste ts to build the source path (ngx_http_aac_module.c, build_source_path function - line 209)

We have many ways

a .- remove the extension in nginx (rewrite), and the module paste the ts extension to get the source
b .- remove the extension in the module (from the last dot to the end of the string) and paste the ts extension to get the source.
c .- the module don't cut and paste any extension. Nginx rewrite the url to convert to source path, so the module open the file directly.

what do you think about ?

j

@flavioribeiro
Copy link
Owner

hi @jalonsoa, I think that the best way to deal with it is by searching for the extension and replacing to .ts in order to get the real file (letter b).

@flavioribeiro
Copy link
Owner

closed by 225babf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants