OLD | NEW |
1 /* | 1 /* |
2 * FFmpeg main | 2 * FFmpeg main |
3 * Copyright (c) 2000-2003 Fabrice Bellard | 3 * Copyright (c) 2000-2003 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "libavcodec/opt.h" | 37 #include "libavcodec/opt.h" |
38 #include "libavcodec/audioconvert.h" | 38 #include "libavcodec/audioconvert.h" |
39 #include "libavcodec/colorspace.h" | 39 #include "libavcodec/colorspace.h" |
40 #include "libavutil/fifo.h" | 40 #include "libavutil/fifo.h" |
41 #include "libavutil/pixdesc.h" | 41 #include "libavutil/pixdesc.h" |
42 #include "libavutil/avstring.h" | 42 #include "libavutil/avstring.h" |
43 #include "libavformat/os_support.h" | 43 #include "libavformat/os_support.h" |
44 | 44 |
45 #if HAVE_SYS_RESOURCE_H | 45 #if HAVE_SYS_RESOURCE_H |
46 #include <sys/types.h> | 46 #include <sys/types.h> |
| 47 #include <sys/time.h> |
47 #include <sys/resource.h> | 48 #include <sys/resource.h> |
48 #elif HAVE_GETPROCESSTIMES | 49 #elif HAVE_GETPROCESSTIMES |
49 #include <windows.h> | 50 #include <windows.h> |
50 #endif | 51 #endif |
| 52 #if HAVE_GETPROCESSMEMORYINFO |
| 53 #include <windows.h> |
| 54 #include <psapi.h> |
| 55 #endif |
51 | 56 |
52 #if HAVE_SYS_SELECT_H | 57 #if HAVE_SYS_SELECT_H |
53 #include <sys/select.h> | 58 #include <sys/select.h> |
54 #endif | 59 #endif |
55 | 60 |
56 #if HAVE_TERMIOS_H | 61 #if HAVE_TERMIOS_H |
57 #include <fcntl.h> | 62 #include <fcntl.h> |
58 #include <sys/ioctl.h> | 63 #include <sys/ioctl.h> |
59 #include <sys/time.h> | 64 #include <sys/time.h> |
60 #include <termios.h> | 65 #include <termios.h> |
61 #elif HAVE_CONIO_H | 66 #elif HAVE_CONIO_H |
62 #include <conio.h> | 67 #include <conio.h> |
63 #endif | 68 #endif |
64 #undef time //needed because HAVE_AV_CONFIG_H is defined on top | |
65 #include <time.h> | 69 #include <time.h> |
66 | 70 |
67 #include "cmdutils.h" | 71 #include "cmdutils.h" |
68 | 72 |
69 #undef NDEBUG | 73 #undef NDEBUG |
70 #include <assert.h> | 74 #include <assert.h> |
71 | 75 |
72 #undef exit | |
73 | |
74 const char program_name[] = "FFmpeg"; | 76 const char program_name[] = "FFmpeg"; |
75 const int program_birth_year = 2000; | 77 const int program_birth_year = 2000; |
76 | 78 |
77 /* select an input stream for an output stream */ | 79 /* select an input stream for an output stream */ |
78 typedef struct AVStreamMap { | 80 typedef struct AVStreamMap { |
79 int file_index; | 81 int file_index; |
80 int stream_index; | 82 int stream_index; |
81 int sync_file_index; | 83 int sync_file_index; |
82 int sync_stream_index; | 84 int sync_stream_index; |
83 } AVStreamMap; | 85 } AVStreamMap; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 int discard; /* true if stream data should be discarded */ | 296 int discard; /* true if stream data should be discarded */ |
295 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo
' */ | 297 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo
' */ |
296 int64_t sample_index; /* current sample */ | 298 int64_t sample_index; /* current sample */ |
297 | 299 |
298 int64_t start; /* time when read started */ | 300 int64_t start; /* time when read started */ |
299 int64_t next_pts; /* synthetic pts for cases where pkt.pts | 301 int64_t next_pts; /* synthetic pts for cases where pkt.pts |
300 is not defined */ | 302 is not defined */ |
301 int64_t pts; /* current pts */ | 303 int64_t pts; /* current pts */ |
302 int is_start; /* is 1 at the start and after a discontinuity */ | 304 int is_start; /* is 1 at the start and after a discontinuity */ |
303 int showed_multi_packet_warning; | 305 int showed_multi_packet_warning; |
| 306 int is_past_recording_time; |
304 } AVInputStream; | 307 } AVInputStream; |
305 | 308 |
306 typedef struct AVInputFile { | 309 typedef struct AVInputFile { |
307 int eof_reached; /* true if eof reached */ | 310 int eof_reached; /* true if eof reached */ |
308 int ist_index; /* index of first stream in ist_table */ | 311 int ist_index; /* index of first stream in ist_table */ |
309 int buffer_size; /* current total buffer size */ | 312 int buffer_size; /* current total buffer size */ |
310 int nb_streams; /* nb streams we are aware of */ | 313 int nb_streams; /* nb streams we are aware of */ |
311 } AVInputFile; | 314 } AVInputFile; |
312 | 315 |
313 #if HAVE_TERMIOS_H | 316 #if HAVE_TERMIOS_H |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV
_TIME_BASE_Q); | 1305 ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV
_TIME_BASE_Q); |
1303 | 1306 |
1304 //while we have more to decode or while the decoder did output something on
EOF | 1307 //while we have more to decode or while the decoder did output something on
EOF |
1305 while (avpkt.size > 0 || (!pkt && ist->next_pts != ist->pts)) { | 1308 while (avpkt.size > 0 || (!pkt && ist->next_pts != ist->pts)) { |
1306 uint8_t *data_buf, *decoded_data_buf; | 1309 uint8_t *data_buf, *decoded_data_buf; |
1307 int data_size, decoded_data_size; | 1310 int data_size, decoded_data_size; |
1308 handle_eof: | 1311 handle_eof: |
1309 ist->pts= ist->next_pts; | 1312 ist->pts= ist->next_pts; |
1310 | 1313 |
1311 if(avpkt.size && avpkt.size != pkt->size && | 1314 if(avpkt.size && avpkt.size != pkt->size && |
1312 (!ist->showed_multi_packet_warning && verbose>0 || verbose>1)){ | 1315 ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){ |
1313 fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt-
>stream_index); | 1316 fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt-
>stream_index); |
1314 ist->showed_multi_packet_warning=1; | 1317 ist->showed_multi_packet_warning=1; |
1315 } | 1318 } |
1316 | 1319 |
1317 /* decode the packet if needed */ | 1320 /* decode the packet if needed */ |
1318 decoded_data_buf = NULL; /* fail safe */ | 1321 decoded_data_buf = NULL; /* fail safe */ |
1319 decoded_data_size= 0; | 1322 decoded_data_size= 0; |
1320 data_buf = avpkt.data; | 1323 data_buf = avpkt.data; |
1321 data_size = avpkt.size; | 1324 data_size = avpkt.size; |
1322 subtitle_to_free = NULL; | 1325 subtitle_to_free = NULL; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 if (pkt->dts == AV_NOPTS_VALUE) | 1498 if (pkt->dts == AV_NOPTS_VALUE) |
1496 opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, os
t->st->time_base); | 1499 opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, os
t->st->time_base); |
1497 else | 1500 else |
1498 opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base
, ost->st->time_base); | 1501 opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base
, ost->st->time_base); |
1499 opkt.dts -= ost_tb_start_time; | 1502 opkt.dts -= ost_tb_start_time; |
1500 | 1503 |
1501 opkt.duration = av_rescale_q(pkt->duration, ist->st->tim
e_base, ost->st->time_base); | 1504 opkt.duration = av_rescale_q(pkt->duration, ist->st->tim
e_base, ost->st->time_base); |
1502 opkt.flags= pkt->flags; | 1505 opkt.flags= pkt->flags; |
1503 | 1506 |
1504 //FIXME remove the following 2 lines they shall be repla
ced by the bitstream filters | 1507 //FIXME remove the following 2 lines they shall be repla
ced by the bitstream filters |
1505 if(ost->st->codec->codec_id != CODEC_ID_H264) { | 1508 if( ost->st->codec->codec_id != CODEC_ID_H264 |
| 1509 && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO |
| 1510 && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO |
| 1511 ) { |
1506 if(av_parser_change(ist->st->parser, ost->st->codec,
&opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY)) | 1512 if(av_parser_change(ist->st->parser, ost->st->codec,
&opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY)) |
1507 opkt.destruct= av_destruct_packet; | 1513 opkt.destruct= av_destruct_packet; |
1508 } else { | 1514 } else { |
1509 opkt.data = data_buf; | 1515 opkt.data = data_buf; |
1510 opkt.size = data_size; | 1516 opkt.size = data_size; |
1511 } | 1517 } |
1512 | 1518 |
1513 write_frame(os, &opkt, ost->st->codec, bitstream_filters
[ost->file_index][opkt.stream_index]); | 1519 write_frame(os, &opkt, ost->st->codec, bitstream_filters
[ost->file_index][opkt.stream_index]); |
1514 ost->st->codec->frame_number++; | 1520 ost->st->codec->frame_number++; |
1515 ost->frame_number++; | 1521 ost->frame_number++; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 | 1631 |
1626 static void print_sdp(AVFormatContext **avc, int n) | 1632 static void print_sdp(AVFormatContext **avc, int n) |
1627 { | 1633 { |
1628 char sdp[2048]; | 1634 char sdp[2048]; |
1629 | 1635 |
1630 avf_sdp_create(avc, n, sdp, sizeof(sdp)); | 1636 avf_sdp_create(avc, n, sdp, sizeof(sdp)); |
1631 printf("SDP:\n%s\n", sdp); | 1637 printf("SDP:\n%s\n", sdp); |
1632 fflush(stdout); | 1638 fflush(stdout); |
1633 } | 1639 } |
1634 | 1640 |
1635 static int stream_index_from_inputs(AVFormatContext **input_files, | |
1636 int nb_input_files, | |
1637 AVInputFile *file_table, | |
1638 AVInputStream **ist_table, | |
1639 enum CodecType type, | |
1640 int programid) | |
1641 { | |
1642 int p, q, z; | |
1643 for(z=0; z<nb_input_files; z++) { | |
1644 AVFormatContext *ic = input_files[z]; | |
1645 for(p=0; p<ic->nb_programs; p++) { | |
1646 AVProgram *program = ic->programs[p]; | |
1647 if(program->id != programid) | |
1648 continue; | |
1649 for(q=0; q<program->nb_stream_indexes; q++) { | |
1650 int sidx = program->stream_index[q]; | |
1651 int ris = file_table[z].ist_index + sidx; | |
1652 if(ist_table[ris]->discard && ic->streams[sidx]->codec->codec_ty
pe == type) | |
1653 return ris; | |
1654 } | |
1655 } | |
1656 } | |
1657 | |
1658 return -1; | |
1659 } | |
1660 | |
1661 /* | 1641 /* |
1662 * The following code is the main loop of the file converter | 1642 * The following code is the main loop of the file converter |
1663 */ | 1643 */ |
1664 static int av_encode(AVFormatContext **output_files, | 1644 static int av_encode(AVFormatContext **output_files, |
1665 int nb_output_files, | 1645 int nb_output_files, |
1666 AVFormatContext **input_files, | 1646 AVFormatContext **input_files, |
1667 int nb_input_files, | 1647 int nb_input_files, |
1668 AVStreamMap *stream_maps, int nb_stream_maps) | 1648 AVStreamMap *stream_maps, int nb_stream_maps) |
1669 { | 1649 { |
1670 int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0; | 1650 int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 if (ist_table[ost->source_index]->st->codec->codec_type != ost->
st->codec->codec_type) { | 1762 if (ist_table[ost->source_index]->st->codec->codec_type != ost->
st->codec->codec_type) { |
1783 int i= ost->file_index; | 1763 int i= ost->file_index; |
1784 dump_format(output_files[i], i, output_files[i]->filename, 1
); | 1764 dump_format(output_files[i], i, output_files[i]->filename, 1
); |
1785 fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #
%d.%d\n", | 1765 fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #
%d.%d\n", |
1786 stream_maps[n].file_index, stream_maps[n].stream_index, | 1766 stream_maps[n].file_index, stream_maps[n].stream_index, |
1787 ost->file_index, ost->index); | 1767 ost->file_index, ost->index); |
1788 av_exit(1); | 1768 av_exit(1); |
1789 } | 1769 } |
1790 | 1770 |
1791 } else { | 1771 } else { |
1792 if(opt_programid) { | 1772 int best_nb_frames=-1; |
1793 found = 0; | |
1794 j = stream_index_from_inputs(input_files, nb_input_files, fi
le_table, ist_table, ost->st->codec->codec_type, opt_programid); | |
1795 if(j != -1) { | |
1796 ost->source_index = j; | |
1797 found = 1; | |
1798 } | |
1799 } else { | |
1800 /* get corresponding input stream index : we select the firs
t one with the right type */ | 1773 /* get corresponding input stream index : we select the firs
t one with the right type */ |
1801 found = 0; | 1774 found = 0; |
1802 for(j=0;j<nb_istreams;j++) { | 1775 for(j=0;j<nb_istreams;j++) { |
| 1776 int skip=0; |
1803 ist = ist_table[j]; | 1777 ist = ist_table[j]; |
1804 if (ist->discard && | 1778 if(opt_programid){ |
| 1779 int pi,si; |
| 1780 AVFormatContext *f= input_files[ ist->file_index ]; |
| 1781 skip=1; |
| 1782 for(pi=0; pi<f->nb_programs; pi++){ |
| 1783 AVProgram *p= f->programs[pi]; |
| 1784 if(p->id == opt_programid) |
| 1785 for(si=0; si<p->nb_stream_indexes; si++){ |
| 1786 if(f->streams[ p->stream_index[si] ] ==
ist->st) |
| 1787 skip=0; |
| 1788 } |
| 1789 } |
| 1790 } |
| 1791 if (ist->discard && ist->st->discard != AVDISCARD_ALL &&
!skip && |
1805 ist->st->codec->codec_type == ost->st->codec->codec_
type) { | 1792 ist->st->codec->codec_type == ost->st->codec->codec_
type) { |
1806 ost->source_index = j; | 1793 if(best_nb_frames < ist->st->codec_info_nb_frames){ |
1807 found = 1; | 1794 best_nb_frames= ist->st->codec_info_nb_frames; |
1808 break; | 1795 ost->source_index = j; |
| 1796 found = 1; |
| 1797 } |
1809 } | 1798 } |
1810 } | 1799 } |
1811 } | |
1812 | 1800 |
1813 if (!found) { | 1801 if (!found) { |
1814 if(! opt_programid) { | 1802 if(! opt_programid) { |
1815 /* try again and reuse existing stream */ | 1803 /* try again and reuse existing stream */ |
1816 for(j=0;j<nb_istreams;j++) { | 1804 for(j=0;j<nb_istreams;j++) { |
1817 ist = ist_table[j]; | 1805 ist = ist_table[j]; |
1818 if (ist->st->codec->codec_type == ost->st->codec->co
dec_type) { | 1806 if ( ist->st->codec->codec_type == ost->st->codec-
>codec_type |
| 1807 && ist->st->discard != AVDISCARD_ALL) { |
1819 ost->source_index = j; | 1808 ost->source_index = j; |
1820 found = 1; | 1809 found = 1; |
1821 } | 1810 } |
1822 } | 1811 } |
1823 } | 1812 } |
1824 if (!found) { | 1813 if (!found) { |
1825 int i= ost->file_index; | 1814 int i= ost->file_index; |
1826 dump_format(output_files[i], i, output_files[i]->filenam
e, 1); | 1815 dump_format(output_files[i], i, output_files[i]->filenam
e, 1); |
1827 fprintf(stderr, "Could not find input stream matching ou
tput stream #%d.%d\n", | 1816 fprintf(stderr, "Could not find input stream matching ou
tput stream #%d.%d\n", |
1828 ost->file_index, ost->index); | 1817 ost->file_index, ost->index); |
1829 av_exit(1); | 1818 av_exit(1); |
1830 } | 1819 } |
1831 } | 1820 } |
1832 } | 1821 } |
1833 ist = ist_table[ost->source_index]; | 1822 ist = ist_table[ost->source_index]; |
1834 ist->discard = 0; | 1823 ist->discard = 0; |
1835 ost->sync_ist = (nb_stream_maps > 0) ? | 1824 ost->sync_ist = (nb_stream_maps > 0) ? |
1836 ist_table[file_table[stream_maps[n].sync_file_index].ist_index + | 1825 ist_table[file_table[stream_maps[n].sync_file_index].ist_index + |
1837 stream_maps[n].sync_stream_index] : ist; | 1826 stream_maps[n].sync_stream_index] : ist; |
1838 } | 1827 } |
1839 } | 1828 } |
1840 | 1829 |
1841 /* for each output stream, we compute the right encoding parameters */ | 1830 /* for each output stream, we compute the right encoding parameters */ |
1842 for(i=0;i<nb_ostreams;i++) { | 1831 for(i=0;i<nb_ostreams;i++) { |
1843 AVMetadataTag *lang; | 1832 AVMetadataTag *t = NULL, *lang = NULL; |
1844 ost = ost_table[i]; | 1833 ost = ost_table[i]; |
1845 os = output_files[ost->file_index]; | 1834 os = output_files[ost->file_index]; |
1846 ist = ist_table[ost->source_index]; | 1835 ist = ist_table[ost->source_index]; |
1847 | 1836 |
1848 codec = ost->st->codec; | 1837 codec = ost->st->codec; |
1849 icodec = ist->st->codec; | 1838 icodec = ist->st->codec; |
1850 | 1839 |
1851 if ((lang=av_metadata_get(ist->st->metadata, "language", NULL, 0)) | 1840 if (av_metadata_get(ist->st->metadata, "language", NULL, 0)) |
1852 && !av_metadata_get(ost->st->metadata, "language", NULL, 0)) | 1841 lang = av_metadata_get(ost->st->metadata, "language", NULL, 0); |
1853 av_metadata_set(&ost->st->metadata, "language", lang->value); | 1842 while ((t = av_metadata_get(ist->st->metadata, "", t, AV_METADATA_IGNORE
_SUFFIX))) { |
| 1843 if (lang && !strcmp(t->key, "language")) |
| 1844 continue; |
| 1845 av_metadata_set2(&ost->st->metadata, t->key, t->value, 0); |
| 1846 } |
1854 | 1847 |
1855 ost->st->disposition = ist->st->disposition; | 1848 ost->st->disposition = ist->st->disposition; |
1856 codec->bits_per_raw_sample= icodec->bits_per_raw_sample; | 1849 codec->bits_per_raw_sample= icodec->bits_per_raw_sample; |
1857 codec->chroma_sample_location = icodec->chroma_sample_location; | 1850 codec->chroma_sample_location = icodec->chroma_sample_location; |
1858 | 1851 |
1859 if (ost->st->stream_copy) { | 1852 if (ost->st->stream_copy) { |
1860 /* if stream_copy is selected, no need to decode or encode */ | 1853 /* if stream_copy is selected, no need to decode or encode */ |
1861 codec->codec_id = icodec->codec_id; | 1854 codec->codec_id = icodec->codec_id; |
1862 codec->codec_type = icodec->codec_type; | 1855 codec->codec_type = icodec->codec_type; |
1863 | 1856 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2086 ret = AVERROR(EINVAL); | 2079 ret = AVERROR(EINVAL); |
2087 goto dump_format; | 2080 goto dump_format; |
2088 } | 2081 } |
2089 //if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) | 2082 //if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) |
2090 // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD; | 2083 // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD; |
2091 } | 2084 } |
2092 } | 2085 } |
2093 | 2086 |
2094 /* init pts */ | 2087 /* init pts */ |
2095 for(i=0;i<nb_istreams;i++) { | 2088 for(i=0;i<nb_istreams;i++) { |
| 2089 AVStream *st; |
2096 ist = ist_table[i]; | 2090 ist = ist_table[i]; |
2097 ist->pts = 0; | 2091 st= ist->st; |
| 2092 ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BA
SE / av_q2d(st->avg_frame_rate) : 0; |
2098 ist->next_pts = AV_NOPTS_VALUE; | 2093 ist->next_pts = AV_NOPTS_VALUE; |
2099 ist->is_start = 1; | 2094 ist->is_start = 1; |
2100 } | 2095 } |
2101 | 2096 |
2102 /* set the duration of the output to the duration of the input | |
2103 * if the output ends up being different, it'll be corrected later */ | |
2104 for (i=0;i<nb_output_files;i++) { | |
2105 AVFormatContext *out_file = output_files[i]; | |
2106 AVFormatContext *in_file = input_files[i]; | |
2107 | |
2108 if (recording_time != INT64_MAX) { | |
2109 out_file->duration = recording_time / 1000000 * AV_TIME_BASE; | |
2110 } else { | |
2111 out_file->duration = in_file->duration; | |
2112 } | |
2113 } | |
2114 | |
2115 /* set meta data information from input file if required */ | 2097 /* set meta data information from input file if required */ |
2116 for (i=0;i<nb_meta_data_maps;i++) { | 2098 for (i=0;i<nb_meta_data_maps;i++) { |
2117 AVFormatContext *out_file; | 2099 AVFormatContext *out_file; |
2118 AVFormatContext *in_file; | 2100 AVFormatContext *in_file; |
2119 AVMetadataTag *mtag; | 2101 AVMetadataTag *mtag; |
2120 | 2102 |
2121 int out_file_index = meta_data_maps[i].out_file; | 2103 int out_file_index = meta_data_maps[i].out_file; |
2122 int in_file_index = meta_data_maps[i].in_file; | 2104 int in_file_index = meta_data_maps[i].in_file; |
2123 if (out_file_index < 0 || out_file_index >= nb_output_files) { | 2105 if (out_file_index < 0 || out_file_index >= nb_output_files) { |
2124 snprintf(error, sizeof(error), "Invalid output file index %d map_met
a_data(%d,%d)", | 2106 snprintf(error, sizeof(error), "Invalid output file index %d map_met
a_data(%d,%d)", |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 } | 2201 } |
2220 | 2202 |
2221 /* select the stream that we must read now by looking at the | 2203 /* select the stream that we must read now by looking at the |
2222 smallest output pts */ | 2204 smallest output pts */ |
2223 file_index = -1; | 2205 file_index = -1; |
2224 for(i=0;i<nb_ostreams;i++) { | 2206 for(i=0;i<nb_ostreams;i++) { |
2225 double ipts, opts; | 2207 double ipts, opts; |
2226 ost = ost_table[i]; | 2208 ost = ost_table[i]; |
2227 os = output_files[ost->file_index]; | 2209 os = output_files[ost->file_index]; |
2228 ist = ist_table[ost->source_index]; | 2210 ist = ist_table[ost->source_index]; |
2229 if(no_packet[ist->file_index]) | 2211 if(ist->is_past_recording_time || no_packet[ist->file_index]) |
2230 continue; | 2212 continue; |
2231 if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO) | |
2232 opts = ost->sync_opts * av_q2d(ost->st->codec->time_base); | |
2233 else | |
2234 opts = ost->st->pts.val * av_q2d(ost->st->time_base); | 2213 opts = ost->st->pts.val * av_q2d(ost->st->time_base); |
2235 ipts = (double)ist->pts; | 2214 ipts = (double)ist->pts; |
2236 if (!file_table[ist->file_index].eof_reached){ | 2215 if (!file_table[ist->file_index].eof_reached){ |
2237 if(ipts < ipts_min) { | 2216 if(ipts < ipts_min) { |
2238 ipts_min = ipts; | 2217 ipts_min = ipts; |
2239 if(input_sync ) file_index = ist->file_index; | 2218 if(input_sync ) file_index = ist->file_index; |
2240 } | 2219 } |
2241 if(opts < opts_min) { | 2220 if(opts < opts_min) { |
2242 opts_min = opts; | 2221 opts_min = opts; |
2243 if(!input_sync) file_index = ist->file_index; | 2222 if(!input_sync) file_index = ist->file_index; |
2244 } | 2223 } |
2245 } | 2224 } |
2246 if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){ | 2225 if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){ |
2247 file_index= -1; | 2226 file_index= -1; |
2248 break; | 2227 break; |
2249 } | 2228 } |
2250 } | 2229 } |
2251 /* if none, if is finished */ | 2230 /* if none, if is finished */ |
2252 if (file_index < 0) { | 2231 if (file_index < 0) { |
2253 if(no_packet_count){ | 2232 if(no_packet_count){ |
2254 no_packet_count=0; | 2233 no_packet_count=0; |
2255 memset(no_packet, 0, sizeof(no_packet)); | 2234 memset(no_packet, 0, sizeof(no_packet)); |
2256 usleep(10000); | 2235 usleep(10000); |
2257 continue; | 2236 continue; |
2258 } | 2237 } |
2259 break; | 2238 break; |
2260 } | 2239 } |
2261 | 2240 |
2262 /* finish if recording time exhausted */ | |
2263 if (opts_min >= (recording_time / 1000000.0)) | |
2264 break; | |
2265 | |
2266 /* finish if limit size exhausted */ | 2241 /* finish if limit size exhausted */ |
2267 if (limit_filesize != 0 && limit_filesize < url_ftell(output_files[0]->p
b)) | 2242 if (limit_filesize != 0 && limit_filesize < url_ftell(output_files[0]->p
b)) |
2268 break; | 2243 break; |
2269 | 2244 |
2270 /* read a frame from it and output it in the fifo */ | 2245 /* read a frame from it and output it in the fifo */ |
2271 is = input_files[file_index]; | 2246 is = input_files[file_index]; |
2272 ret= av_read_frame(is, &pkt); | 2247 ret= av_read_frame(is, &pkt); |
2273 if(ret == AVERROR(EAGAIN)){ | 2248 if(ret == AVERROR(EAGAIN)){ |
2274 no_packet[file_index]=1; | 2249 no_packet[file_index]=1; |
2275 no_packet_count++; | 2250 no_packet_count++; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2319 input_files_ts_offset[ist->file_index]-= delta; | 2294 input_files_ts_offset[ist->file_index]-= delta; |
2320 if (verbose > 2) | 2295 if (verbose > 2) |
2321 fprintf(stderr, "timestamp discontinuity %"PRId64", new offs
et= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]); | 2296 fprintf(stderr, "timestamp discontinuity %"PRId64", new offs
et= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]); |
2322 pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base
); | 2297 pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base
); |
2323 if(pkt.pts != AV_NOPTS_VALUE) | 2298 if(pkt.pts != AV_NOPTS_VALUE) |
2324 pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_
base); | 2299 pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_
base); |
2325 } | 2300 } |
2326 } | 2301 } |
2327 | 2302 |
2328 /* finish if recording time exhausted */ | 2303 /* finish if recording time exhausted */ |
2329 if (pkt.pts * av_q2d(ist->st->time_base) >= (recording_time / 1000000.0)
) | 2304 if (recording_time != INT64_MAX && |
| 2305 av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_ti
me, (AVRational){1, 1000000}) >= 0) { |
| 2306 ist->is_past_recording_time = 1; |
2330 goto discard_packet; | 2307 goto discard_packet; |
| 2308 } |
2331 | 2309 |
2332 //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, p
kt.size); | 2310 //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, p
kt.size); |
2333 if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) { | 2311 if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) { |
2334 | 2312 |
2335 if (verbose >= 0) | 2313 if (verbose >= 0) |
2336 fprintf(stderr, "Error while decoding stream #%d.%d\n", | 2314 fprintf(stderr, "Error while decoding stream #%d.%d\n", |
2337 ist->file_index, ist->index); | 2315 ist->file_index, ist->index); |
2338 if (exit_on_error) | 2316 if (exit_on_error) |
2339 av_exit(1); | 2317 av_exit(1); |
2340 av_free_packet(&pkt); | 2318 av_free_packet(&pkt); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 | 2571 |
2594 static void opt_frame_pix_fmt(const char *arg) | 2572 static void opt_frame_pix_fmt(const char *arg) |
2595 { | 2573 { |
2596 if (strcmp(arg, "list")) { | 2574 if (strcmp(arg, "list")) { |
2597 frame_pix_fmt = av_get_pix_fmt(arg); | 2575 frame_pix_fmt = av_get_pix_fmt(arg); |
2598 if (frame_pix_fmt == PIX_FMT_NONE) { | 2576 if (frame_pix_fmt == PIX_FMT_NONE) { |
2599 fprintf(stderr, "Unknown pixel format requested: %s\n", arg); | 2577 fprintf(stderr, "Unknown pixel format requested: %s\n", arg); |
2600 av_exit(1); | 2578 av_exit(1); |
2601 } | 2579 } |
2602 } else { | 2580 } else { |
2603 list_fmts(avcodec_pix_fmt_string, PIX_FMT_NB); | 2581 show_pix_fmts(); |
2604 av_exit(0); | 2582 av_exit(0); |
2605 } | 2583 } |
2606 } | 2584 } |
2607 | 2585 |
2608 static void opt_frame_aspect_ratio(const char *arg) | 2586 static void opt_frame_aspect_ratio(const char *arg) |
2609 { | 2587 { |
2610 int x = 0, y = 0; | 2588 int x = 0, y = 0; |
2611 double ar = 0; | 2589 double ar = 0; |
2612 const char *p; | 2590 const char *p; |
2613 char *end; | 2591 char *end; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2859 | 2837 |
2860 static void opt_input_file(const char *filename) | 2838 static void opt_input_file(const char *filename) |
2861 { | 2839 { |
2862 AVFormatContext *ic; | 2840 AVFormatContext *ic; |
2863 AVFormatParameters params, *ap = ¶ms; | 2841 AVFormatParameters params, *ap = ¶ms; |
2864 AVInputFormat *file_iformat = NULL; | 2842 AVInputFormat *file_iformat = NULL; |
2865 int err, i, ret, rfps, rfps_base; | 2843 int err, i, ret, rfps, rfps_base; |
2866 int64_t timestamp; | 2844 int64_t timestamp; |
2867 | 2845 |
2868 if (last_asked_format) { | 2846 if (last_asked_format) { |
2869 file_iformat = av_find_input_format(last_asked_format); | 2847 if (!(file_iformat = av_find_input_format(last_asked_format))) { |
| 2848 fprintf(stderr, "Unknown input format: '%s'\n", last_asked_format); |
| 2849 av_exit(1); |
| 2850 } |
2870 last_asked_format = NULL; | 2851 last_asked_format = NULL; |
2871 } | 2852 } |
2872 | 2853 |
2873 if (!strcmp(filename, "-")) | 2854 if (!strcmp(filename, "-")) |
2874 filename = "pipe:"; | 2855 filename = "pipe:"; |
2875 | 2856 |
2876 using_stdin |= !strncmp(filename, "pipe:", 5) || | 2857 using_stdin |= !strncmp(filename, "pipe:", 5) || |
2877 !strcmp(filename, "/dev/stdin"); | 2858 !strcmp(filename, "/dev/stdin"); |
2878 | 2859 |
2879 /* get default parameters from command line */ | 2860 /* get default parameters from command line */ |
(...skipping 26 matching lines...) Expand all Loading... |
2906 if(pgmyuv_compatibility_hack) | 2887 if(pgmyuv_compatibility_hack) |
2907 ic->video_codec_id= CODEC_ID_PGMYUV; | 2888 ic->video_codec_id= CODEC_ID_PGMYUV; |
2908 | 2889 |
2909 /* open the input file with generic libav function */ | 2890 /* open the input file with generic libav function */ |
2910 err = av_open_input_file(&ic, filename, file_iformat, 0, ap); | 2891 err = av_open_input_file(&ic, filename, file_iformat, 0, ap); |
2911 if (err < 0) { | 2892 if (err < 0) { |
2912 print_error(filename, err); | 2893 print_error(filename, err); |
2913 av_exit(1); | 2894 av_exit(1); |
2914 } | 2895 } |
2915 if(opt_programid) { | 2896 if(opt_programid) { |
2916 int i; | 2897 int i, j; |
2917 for(i=0; i<ic->nb_programs; i++) | 2898 int found=0; |
2918 if(ic->programs[i]->id != opt_programid) | 2899 for(i=0; i<ic->nb_streams; i++){ |
2919 ic->programs[i]->discard = AVDISCARD_ALL; | 2900 ic->streams[i]->discard= AVDISCARD_ALL; |
| 2901 } |
| 2902 for(i=0; i<ic->nb_programs; i++){ |
| 2903 AVProgram *p= ic->programs[i]; |
| 2904 if(p->id != opt_programid){ |
| 2905 p->discard = AVDISCARD_ALL; |
| 2906 }else{ |
| 2907 found=1; |
| 2908 for(j=0; j<p->nb_stream_indexes; j++){ |
| 2909 ic->streams[p->stream_index[j]]->discard= 0; |
| 2910 } |
| 2911 } |
| 2912 } |
| 2913 if(!found){ |
| 2914 fprintf(stderr, "Specified program id not found\n"); |
| 2915 av_exit(1); |
| 2916 } |
| 2917 opt_programid=0; |
2920 } | 2918 } |
2921 | 2919 |
2922 ic->loop_input = loop_input; | 2920 ic->loop_input = loop_input; |
2923 | 2921 |
2924 /* If not enough info to get the stream parameters, we decode the | 2922 /* If not enough info to get the stream parameters, we decode the |
2925 first frames to get it. (used in mpeg case for example) */ | 2923 first frames to get it. (used in mpeg case for example) */ |
2926 ret = av_find_stream_info(ic); | 2924 ret = av_find_stream_info(ic); |
2927 if (ret < 0 && verbose >= 0) { | 2925 if (ret < 0 && verbose >= 0) { |
2928 fprintf(stderr, "%s: could not find codec parameters\n", filename); | 2926 fprintf(stderr, "%s: could not find codec parameters\n", filename); |
2929 av_exit(1); | 2927 av_exit(1); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3203 nb_ocodecs++; | 3201 nb_ocodecs++; |
3204 if (video_language) { | 3202 if (video_language) { |
3205 av_metadata_set(&st->metadata, "language", video_language); | 3203 av_metadata_set(&st->metadata, "language", video_language); |
3206 av_freep(&video_language); | 3204 av_freep(&video_language); |
3207 } | 3205 } |
3208 | 3206 |
3209 /* reset some key parameters */ | 3207 /* reset some key parameters */ |
3210 video_disable = 0; | 3208 video_disable = 0; |
3211 av_freep(&video_codec_name); | 3209 av_freep(&video_codec_name); |
3212 video_stream_copy = 0; | 3210 video_stream_copy = 0; |
| 3211 frame_pix_fmt = PIX_FMT_NONE; |
3213 } | 3212 } |
3214 | 3213 |
3215 static void new_audio_stream(AVFormatContext *oc) | 3214 static void new_audio_stream(AVFormatContext *oc) |
3216 { | 3215 { |
3217 AVStream *st; | 3216 AVStream *st; |
3218 AVCodecContext *audio_enc; | 3217 AVCodecContext *audio_enc; |
3219 enum CodecID codec_id; | 3218 enum CodecID codec_id; |
3220 | 3219 |
3221 st = av_new_stream(oc, oc->nb_streams); | 3220 st = av_new_stream(oc, oc->nb_streams); |
3222 if (!st) { | 3221 if (!st) { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3537 HANDLE proc; | 3536 HANDLE proc; |
3538 FILETIME c, e, k, u; | 3537 FILETIME c, e, k, u; |
3539 proc = GetCurrentProcess(); | 3538 proc = GetCurrentProcess(); |
3540 GetProcessTimes(proc, &c, &e, &k, &u); | 3539 GetProcessTimes(proc, &c, &e, &k, &u); |
3541 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10; | 3540 return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10; |
3542 #else | 3541 #else |
3543 return av_gettime(); | 3542 return av_gettime(); |
3544 #endif | 3543 #endif |
3545 } | 3544 } |
3546 | 3545 |
| 3546 static int64_t getmaxrss(void) |
| 3547 { |
| 3548 #if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS |
| 3549 struct rusage rusage; |
| 3550 getrusage(RUSAGE_SELF, &rusage); |
| 3551 return (int64_t)rusage.ru_maxrss * 1024; |
| 3552 #elif HAVE_GETPROCESSMEMORYINFO |
| 3553 HANDLE proc; |
| 3554 PROCESS_MEMORY_COUNTERS memcounters; |
| 3555 proc = GetCurrentProcess(); |
| 3556 memcounters.cb = sizeof(memcounters); |
| 3557 GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters)); |
| 3558 return memcounters.PeakPagefileUsage; |
| 3559 #else |
| 3560 return 0; |
| 3561 #endif |
| 3562 } |
| 3563 |
3547 static void parse_matrix_coeffs(uint16_t *dest, const char *str) | 3564 static void parse_matrix_coeffs(uint16_t *dest, const char *str) |
3548 { | 3565 { |
3549 int i; | 3566 int i; |
3550 const char *p = str; | 3567 const char *p = str; |
3551 for(i = 0;; i++) { | 3568 for(i = 0;; i++) { |
3552 dest[i] = atoi(p); | 3569 dest[i] = atoi(p); |
3553 if(i == 63) | 3570 if(i == 63) |
3554 break; | 3571 break; |
3555 p = strchr(p, ','); | 3572 p = strchr(p, ','); |
3556 if(!p) { | 3573 if(!p) { |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4031 fprintf(stderr, "At least one input file must be specified\n"); | 4048 fprintf(stderr, "At least one input file must be specified\n"); |
4032 av_exit(1); | 4049 av_exit(1); |
4033 } | 4050 } |
4034 | 4051 |
4035 ti = getutime(); | 4052 ti = getutime(); |
4036 if (av_encode(output_files, nb_output_files, input_files, nb_input_files, | 4053 if (av_encode(output_files, nb_output_files, input_files, nb_input_files, |
4037 stream_maps, nb_stream_maps) < 0) | 4054 stream_maps, nb_stream_maps) < 0) |
4038 av_exit(1); | 4055 av_exit(1); |
4039 ti = getutime() - ti; | 4056 ti = getutime() - ti; |
4040 if (do_benchmark) { | 4057 if (do_benchmark) { |
4041 printf("bench: utime=%0.3fs\n", ti / 1000000.0); | 4058 int maxrss = getmaxrss() / 1024; |
| 4059 printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss); |
4042 } | 4060 } |
4043 | 4061 |
4044 return av_exit(0); | 4062 return av_exit(0); |
4045 } | 4063 } |
OLD | NEW |