From 6a838148d6d83decd236b8c355b8b18987cb4cb5 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 16:30:51 +0100 Subject: [PATCH 01/18] util: renamed getPixelSampleFormats to getSupportedPixel/SampleFormats --- src/AvTranscoder/util.cpp | 4 ++-- src/AvTranscoder/util.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 39166989..4d98acae 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -18,7 +18,7 @@ bool matchFormat(const std::string& format, const std::string& filename) return avOutputFormat != NULL; } -std::vector getPixelFormats(const std::string& videoCodecName) +std::vector getSupportedPixelFormats(const std::string& videoCodecName) { std::vector pixelFormats; @@ -63,7 +63,7 @@ std::vector getPixelFormats(const std::string& videoCodecName) return pixelFormats; } -std::vector getSampleFormats(const std::string& audioCodecName) +std::vector getSupportedSampleFormats(const std::string& audioCodecName) { std::vector sampleFormats; diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 97ccd826..3f6a32a7 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -29,14 +29,14 @@ bool AvExport matchFormat(const std::string& format, const std::string& filename * @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video * codecs). */ -std::vector AvExport getPixelFormats(const std::string& videoCodecName = ""); +std::vector AvExport getSupportedPixelFormats(const std::string& videoCodecName = ""); /** * @brief Get sample format supported by an audio codec. * @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio * codecs). */ -std::vector AvExport getSampleFormats(const std::string& audioCodecName = ""); +std::vector AvExport getSupportedSampleFormats(const std::string& audioCodecName = ""); /** * @brief Get the corresponding AVPixelFormat from the pixel format name From 7ef123aa149f84c74d8023211c54f689640b46c8 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 16:33:25 +0100 Subject: [PATCH 02/18] util: renamed getVideo/AudioCodec/FormatOptions to getAvailableOptionsPerVideo/AudioCodec/Format --- src/AvTranscoder/util.cpp | 6 +++--- src/AvTranscoder/util.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 4d98acae..986a9a2e 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -187,7 +187,7 @@ NamesArray getAudioCodecsNames() return audioCodecsNames; } -OptionArrayMap getOutputFormatOptions() +OptionArrayMap getAvailableOptionsPerOutputFormat() { OptionArrayMap optionsPerFormat; @@ -213,7 +213,7 @@ OptionArrayMap getOutputFormatOptions() return optionsPerFormat; } -OptionArrayMap getVideoCodecOptions() +OptionArrayMap getAvailableOptionsPerVideoCodec() { OptionArrayMap videoCodecOptions; @@ -238,7 +238,7 @@ OptionArrayMap getVideoCodecOptions() return videoCodecOptions; } -OptionArrayMap getAudioCodecOptions() +OptionArrayMap getAvailableOptionsPerAudioCodec() { OptionArrayMap audioCodecOptions; diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 3f6a32a7..1e25c25c 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -81,17 +81,17 @@ NamesArray AvExport getAudioCodecsNames(); /** * @brief Get the list of options for each output format */ -OptionArrayMap AvExport getOutputFormatOptions(); +OptionArrayMap AvExport getAvailableOptionsPerOutputFormat(); /** * @brief Get the list of options for each video codec */ -OptionArrayMap AvExport getVideoCodecOptions(); +OptionArrayMap AvExport getAvailableOptionsPerVideoCodec(); /** * @brief Get the list of options for each audio codec */ -OptionArrayMap AvExport getAudioCodecOptions(); +OptionArrayMap AvExport getAvailableOptionsPerAudioCodec(); #endif } From f2ce6ede33fe2e3299b4c7c6e416fac3a4525f1a Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 16:35:08 +0100 Subject: [PATCH 03/18] util: renamed getFormats/Video/AudioNames to getAvailableFormats/Video/AudioCodecsNames --- src/AvTranscoder/util.cpp | 6 +++--- src/AvTranscoder/util.hpp | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 986a9a2e..131c63f2 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -117,7 +117,7 @@ std::string getSampleFormatName(const AVSampleFormat sampleFormat) return formatName ? std::string(formatName) : ""; } -NamesArray getFormatsNames() +NamesArray getAvailableFormatsNames() { NamesArray formatsNames; @@ -137,7 +137,7 @@ NamesArray getFormatsNames() return formatsNames; } -NamesArray getVideoCodecsNames() +NamesArray getAvailableVideoCodecsNames() { NamesArray videoCodecsNames; @@ -162,7 +162,7 @@ NamesArray getVideoCodecsNames() return videoCodecsNames; } -NamesArray getAudioCodecsNames() +NamesArray getAvailableAudioCodecsNames() { NamesArray audioCodecsNames; diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 1e25c25c..87219a2d 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -64,19 +64,19 @@ std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); #ifndef SWIG /** - * @brief Get array of short/long names of all format supported by FFmpeg / libav. + * @brief Get array of short/long names of all format available by FFmpeg / libav. */ -NamesArray AvExport getFormatsNames(); +NamesArray AvExport getAvailableFormatsNames(); /** - * @brief Get array of short/long names of all video codec supported by FFmpeg / libav. + * @brief Get array of short/long names of all video codec available by FFmpeg / libav. */ -NamesArray AvExport getVideoCodecsNames(); +NamesArray AvExport getAvailableVideoCodecsNames(); /** - * @brief Get array of short/long names of all audio codec supported by FFmpeg / libav. + * @brief Get array of short/long names of all audio codec available by FFmpeg / libav. */ -NamesArray AvExport getAudioCodecsNames(); +NamesArray AvExport getAvailableAudioCodecsNames(); /** * @brief Get the list of options for each output format From ab2c4e8ba6ae91a9a8aa5b9e5d81a766803a088e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:05:27 +0100 Subject: [PATCH 04/18] util: get formats without long_name when getAvailableFormatsNames --- src/AvTranscoder/util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 131c63f2..9dc80849 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -128,11 +128,11 @@ NamesArray getAvailableFormatsNames() if(fmt->video_codec == AV_CODEC_ID_NONE) continue; - if(!fmt->name && !fmt->long_name) + if(!fmt->name) continue; formatsNames.push_back( - std::make_pair(std::string(fmt->name ? fmt->name : ""), std::string(fmt->long_name ? fmt->long_name : ""))); + std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); } return formatsNames; } From 645d63d67e60fda9142ab960236613ba8a9a21fd Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:05:59 +0100 Subject: [PATCH 05/18] util: get codecs without long_name when getAvailableVideo/AudioCodecsNames --- src/AvTranscoder/util.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 9dc80849..f00e18bd 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -146,10 +146,10 @@ NamesArray getAvailableVideoCodecsNames() { if(c->type == AVMEDIA_TYPE_VIDEO) { - if(!c->name && !c->long_name) + if(!c->name) continue; - std::pair codecNames(std::string(c->name ? c->name : ""), + std::pair codecNames(std::string(c->name), std::string(c->long_name ? c->long_name : "")); // skip duplicates @@ -171,10 +171,10 @@ NamesArray getAvailableAudioCodecsNames() { if(c->type == AVMEDIA_TYPE_AUDIO) { - if(!c->name && !c->long_name) + if(!c->name) continue; - std::pair codecNames(std::string(c->name ? c->name : ""), + const std::pair codecNames(std::string(c->name), std::string(c->long_name ? c->long_name : "")); // skip duplicates From 0d04bd9756cb55736af0121f3a7d8b86e11b2042 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:06:51 +0100 Subject: [PATCH 06/18] util: do not skip format with undefined video codec --- src/AvTranscoder/util.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index f00e18bd..9130fa83 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -124,10 +124,6 @@ NamesArray getAvailableFormatsNames() AVOutputFormat* fmt = NULL; while((fmt = av_oformat_next(fmt))) { - // skip undefined codec - if(fmt->video_codec == AV_CODEC_ID_NONE) - continue; - if(!fmt->name) continue; From 17bfc7d94704e28900dd2c7e6c468ebc7293d4d1 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:08:13 +0100 Subject: [PATCH 07/18] util: get formats without private context when getAvailableOptionsPerOutputFormat --- src/AvTranscoder/util.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 9130fa83..ef980f74 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -192,18 +192,16 @@ OptionArrayMap getAvailableOptionsPerOutputFormat() // iterate on formats while(outputFormat) { - // add only format with video track - // outputFormat->audio_codec ? - if(outputFormat->video_codec != AV_CODEC_ID_NONE) + if(!outputFormat->name) + continue; + + const std::string outputFormatName(outputFormat->name); + OptionArray options; + if(outputFormat->priv_class) { - if(outputFormat->priv_class) - { - const std::string outputFormatName(outputFormat->name); - OptionArray options; - loadOptions(options, (void*)&outputFormat->priv_class, 0); - optionsPerFormat.insert(std::make_pair(outputFormatName, options)); - } + loadOptions(options, (void*)&outputFormat->priv_class, 0); } + optionsPerFormat.insert(std::make_pair(outputFormatName, options)); outputFormat = av_oformat_next(outputFormat); } return optionsPerFormat; From 558e59c0d058a7989ba2223db72628e94d1d3b32 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:08:41 +0100 Subject: [PATCH 08/18] util: get codecs without private context when getAvailableOptionsPerVideo/AudioCodec --- src/AvTranscoder/util.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index ef980f74..0b522c34 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -216,16 +216,19 @@ OptionArrayMap getAvailableOptionsPerVideoCodec() // iterate on codecs while(codec) { + if(!codec->name) + continue; + // add only video codec if(codec->type == AVMEDIA_TYPE_VIDEO) { + const std::string videoCodecName(codec->name); + OptionArray options; if(codec->priv_class) { - std::string videoCodecName(codec->name); - OptionArray options; loadOptions(options, (void*)&codec->priv_class, 0); - videoCodecOptions.insert(std::make_pair(videoCodecName, options)); } + videoCodecOptions.insert(std::make_pair(videoCodecName, options)); } codec = av_codec_next(codec); } @@ -241,16 +244,19 @@ OptionArrayMap getAvailableOptionsPerAudioCodec() // iterate on codecs while(codec) { + if(!codec->name) + continue; + // add only audio codec if(codec->type == AVMEDIA_TYPE_AUDIO) { + const std::string audioCodecName(codec->name); + OptionArray options; if(codec->priv_class) { - std::string audioCodecName(codec->name); - OptionArray options; loadOptions(options, (void*)&codec->priv_class, 0); - audioCodecOptions.insert(std::make_pair(audioCodecName, options)); } + audioCodecOptions.insert(std::make_pair(audioCodecName, options)); } codec = av_codec_next(codec); } From 1993920547f621d0af0a5a7f714dc61ece759491 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:10:14 +0100 Subject: [PATCH 09/18] util: added documentation when get formats/codecs --- src/AvTranscoder/util.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 87219a2d..5c7afc0c 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -65,31 +65,37 @@ std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); #ifndef SWIG /** * @brief Get array of short/long names of all format available by FFmpeg / libav. + * @note Need to call preloadCodecsAndFormats before using this function. */ NamesArray AvExport getAvailableFormatsNames(); /** * @brief Get array of short/long names of all video codec available by FFmpeg / libav. + * @note Need to call preloadCodecsAndFormats before using this function. */ NamesArray AvExport getAvailableVideoCodecsNames(); /** * @brief Get array of short/long names of all audio codec available by FFmpeg / libav. + * @note Need to call preloadCodecsAndFormats before using this function. */ NamesArray AvExport getAvailableAudioCodecsNames(); /** * @brief Get the list of options for each output format + * @note Need to call preloadCodecsAndFormats before using this function. */ OptionArrayMap AvExport getAvailableOptionsPerOutputFormat(); /** * @brief Get the list of options for each video codec + * @note Need to call preloadCodecsAndFormats before using this function. */ OptionArrayMap AvExport getAvailableOptionsPerVideoCodec(); /** * @brief Get the list of options for each audio codec + * @note Need to call preloadCodecsAndFormats before using this function. */ OptionArrayMap AvExport getAvailableOptionsPerAudioCodec(); #endif From 96aed902c482a0073a733525fc1e5e5295578d4a Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:46:05 +0100 Subject: [PATCH 10/18] util: updated NamesArray type It is a map instead of a vector (no need to manage duplicates!). --- src/AvTranscoder/util.cpp | 22 +++++----------------- src/AvTranscoder/util.hpp | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 0b522c34..54af67b1 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -127,7 +127,7 @@ NamesArray getAvailableFormatsNames() if(!fmt->name) continue; - formatsNames.push_back( + formatsNames.insert( std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); } return formatsNames; @@ -145,14 +145,8 @@ NamesArray getAvailableVideoCodecsNames() if(!c->name) continue; - std::pair codecNames(std::string(c->name), - std::string(c->long_name ? c->long_name : "")); - - // skip duplicates - if(std::find(videoCodecsNames.begin(), videoCodecsNames.end(), codecNames) != videoCodecsNames.end()) - continue; - - videoCodecsNames.push_back(codecNames); + videoCodecsNames.insert( + std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); } } return videoCodecsNames; @@ -170,14 +164,8 @@ NamesArray getAvailableAudioCodecsNames() if(!c->name) continue; - const std::pair codecNames(std::string(c->name), - std::string(c->long_name ? c->long_name : "")); - - // skip duplicates - if(std::find(audioCodecsNames.begin(), audioCodecsNames.end(), codecNames) != audioCodecsNames.end()) - continue; - - audioCodecsNames.push_back(codecNames); + audioCodecsNames.insert( + std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); } } return audioCodecsNames; diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 5c7afc0c..622a3387 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -17,7 +17,7 @@ namespace avtranscoder { typedef std::map OptionArrayMap; -typedef std::vector > NamesArray; //< short/long names of format/video codec/audio codec +typedef std::map NamesArray; //< short/long names of format/video codec/audio codec /** * @brief Check if a format name corresponds to the format of a given filename From 6be73f08ebc74528ba3a12d56724ec6a10eccd18 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 17:47:16 +0100 Subject: [PATCH 11/18] SWIG: added getAvailableFormats/Video/AudioCodecsNames methods --- src/AvTranscoder/util.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 622a3387..4fed8e00 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -62,7 +62,6 @@ std::string AvExport getPixelFormatName(const AVPixelFormat pixelFormat); */ std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); -#ifndef SWIG /** * @brief Get array of short/long names of all format available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. @@ -81,6 +80,7 @@ NamesArray AvExport getAvailableVideoCodecsNames(); */ NamesArray AvExport getAvailableAudioCodecsNames(); +#ifndef SWIG /** * @brief Get the list of options for each output format * @note Need to call preloadCodecsAndFormats before using this function. From 981e7c7b67d2ea64627e2ff0fe1aceec16537b5e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 18:05:08 +0100 Subject: [PATCH 12/18] util: removed matchFormat method Used only once, inside OutputFile class. --- src/AvTranscoder/file/OutputFile.cpp | 2 +- src/AvTranscoder/util.cpp | 6 ------ src/AvTranscoder/util.hpp | 5 ----- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/AvTranscoder/file/OutputFile.cpp b/src/AvTranscoder/file/OutputFile.cpp index 8edecbc0..ff4944a0 100644 --- a/src/AvTranscoder/file/OutputFile.cpp +++ b/src/AvTranscoder/file/OutputFile.cpp @@ -266,7 +266,7 @@ void OutputFile::setupWrapping(const ProfileLoader::Profile& profile) } // check if output format indicated is valid with the filename extension - if(!matchFormat(profile.find(constants::avProfileFormat)->second, getFilename())) + if(!av_guess_format(profile.find(constants::avProfileFormat)->second.c_str(), getFilename().c_str(), NULL)) { throw std::runtime_error("Invalid format according to the file extension."); } diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 54af67b1..dc81bc5b 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -12,12 +12,6 @@ extern "C" { namespace avtranscoder { -bool matchFormat(const std::string& format, const std::string& filename) -{ - AVOutputFormat* avOutputFormat = av_guess_format(format.c_str(), filename.c_str(), NULL); - return avOutputFormat != NULL; -} - std::vector getSupportedPixelFormats(const std::string& videoCodecName) { std::vector pixelFormats; diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 4fed8e00..9f8d1b61 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -19,11 +19,6 @@ namespace avtranscoder typedef std::map OptionArrayMap; typedef std::map NamesArray; //< short/long names of format/video codec/audio codec -/** - * @brief Check if a format name corresponds to the format of a given filename - */ -bool AvExport matchFormat(const std::string& format, const std::string& filename); - /** * @brief Get pixel format supported by a video codec. * @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video From ef30efd85c18b172cf5c572302f82baf93119c8a Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 9 Mar 2016 18:29:29 +0100 Subject: [PATCH 13/18] pyTest: added tests to check util functions --- test/pyTest/testUtil.py | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test/pyTest/testUtil.py diff --git a/test/pyTest/testUtil.py b/test/pyTest/testUtil.py new file mode 100644 index 00000000..1addeb70 --- /dev/null +++ b/test/pyTest/testUtil.py @@ -0,0 +1,81 @@ +from nose.tools import * + +from pyAvTranscoder import avtranscoder as av + + +def testSupportedPixelFormats(): + """ + Check supported pixel formats of mpeg2video codec. + Check access to the list of all supported pixel formats. + """ + # Check supported pixel formats of mpeg2video codec + videoCodecName = "mpeg2video" + mpeg2videoSupportedPixelFormats = av.getSupportedPixelFormats(videoCodecName) + assert_equals(len(mpeg2videoSupportedPixelFormats), 2) + assert_in("yuv420p", mpeg2videoSupportedPixelFormats) + assert_in("yuv422p", mpeg2videoSupportedPixelFormats) + + # Check if there is more pixel formats available + allSupportedPixelFormats = av.getSupportedPixelFormats() + assert_less(len(mpeg2videoSupportedPixelFormats), len(allSupportedPixelFormats)) + + +def testSupportedSampleFormats(): + """ + Check supported sample formats of pcm_s24le codec. + Check access to the list of all supported sample formats. + """ + # Check supported sample formats of pcm_s24le codec + audioCodecName = "pcm_s24le" + pcmSupportedSampleFormats = av.getSupportedSampleFormats(audioCodecName) + assert_equals(len(pcmSupportedSampleFormats), 1) + assert_in("s32", pcmSupportedSampleFormats) + + # Check if there is more sample formats available + allSupportedSampleFormats = av.getSupportedSampleFormats() + assert_less(len(pcmSupportedSampleFormats), len(allSupportedSampleFormats)) + + +def testAccessToAPixelFormat(): + """ + Check if we can access an AVPixelFormat from a name, and retrieve the name from this constant value. + """ + strPixelFormat = "yuv420p" + avPixelFormat = av.getAVPixelFormat(strPixelFormat) + assert_equals(av.getPixelFormatName(avPixelFormat), strPixelFormat) + + +def testAccessToASampleFormat(): + """ + Check if we can access an AVSampleFormat from a name, and retrieve the name from this constant value. + """ + strSampleFormat = "s32" + avSampleFormat = av.getAVSampleFormat(strSampleFormat) + assert_equals(av.getSampleFormatName(avSampleFormat), strSampleFormat) + + +def testAccessToAvailableFormatsNames(): + """ + Check if we can access the list of available formats. + @note Tested with ffmpeg-2.4.2 + """ + availableFormats = av.getAvailableFormatsNames() + assert_greater_equal(len(availableFormats), 135) + + +def testAccessToAvailableVideoCodecsNames(): + """ + Check if we can access the list of available video codecs. + @note Tested with ffmpeg-2.4.2 + """ + availableVideoCodecs = av.getAvailableVideoCodecsNames() + assert_greater_equal(len(availableVideoCodecs), 204) + + +def testAccessToAvailableAudioCodecsNames(): + """ + Check if we can access the list of available audio codecs. + @note Tested with ffmpeg-2.4.2 + """ + availableAudioCodecs = av.getAvailableAudioCodecsNames() + assert_greater_equal(len(availableAudioCodecs), 152) From 92689e15df7fac7a1a1f3ad7db2abff550edc753 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 10 Mar 2016 10:50:31 +0100 Subject: [PATCH 14/18] util: renamed typedef NamesArray to NamesMap Because this is a map since commit 96aed90 --- src/AvTranscoder/util.cpp | 12 ++++++------ src/AvTranscoder/util.hpp | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index dc81bc5b..2cae0238 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -111,9 +111,9 @@ std::string getSampleFormatName(const AVSampleFormat sampleFormat) return formatName ? std::string(formatName) : ""; } -NamesArray getAvailableFormatsNames() +NamesMap getAvailableFormatsNames() { - NamesArray formatsNames; + NamesMap formatsNames; AVOutputFormat* fmt = NULL; while((fmt = av_oformat_next(fmt))) @@ -127,9 +127,9 @@ NamesArray getAvailableFormatsNames() return formatsNames; } -NamesArray getAvailableVideoCodecsNames() +NamesMap getAvailableVideoCodecsNames() { - NamesArray videoCodecsNames; + NamesMap videoCodecsNames; AVCodec* c = NULL; while((c = av_codec_next(c)) != NULL) @@ -146,9 +146,9 @@ NamesArray getAvailableVideoCodecsNames() return videoCodecsNames; } -NamesArray getAvailableAudioCodecsNames() +NamesMap getAvailableAudioCodecsNames() { - NamesArray audioCodecsNames; + NamesMap audioCodecsNames; AVCodec* c = NULL; while((c = av_codec_next(c)) != NULL) diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 9f8d1b61..304b5ee8 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -17,7 +17,7 @@ namespace avtranscoder { typedef std::map OptionArrayMap; -typedef std::map NamesArray; //< short/long names of format/video codec/audio codec +typedef std::map NamesMap; //< short/long names of format/video codec/audio codec /** * @brief Get pixel format supported by a video codec. @@ -58,22 +58,22 @@ std::string AvExport getPixelFormatName(const AVPixelFormat pixelFormat); std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); /** - * @brief Get array of short/long names of all format available by FFmpeg / libav. + * @brief Get a map of short/long names of all format available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ -NamesArray AvExport getAvailableFormatsNames(); +NamesMap AvExport getAvailableFormatsNames(); /** - * @brief Get array of short/long names of all video codec available by FFmpeg / libav. + * @brief Get a map of short/long names of all video codec available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ -NamesArray AvExport getAvailableVideoCodecsNames(); +NamesMap AvExport getAvailableVideoCodecsNames(); /** - * @brief Get array of short/long names of all audio codec available by FFmpeg / libav. + * @brief Get a map of short/long names of all audio codec available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ -NamesArray AvExport getAvailableAudioCodecsNames(); +NamesMap AvExport getAvailableAudioCodecsNames(); #ifndef SWIG /** From 0f56476bd3bed810f878d16157d927b5660419a6 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 10 Mar 2016 11:54:22 +0100 Subject: [PATCH 15/18] util: added getAvailableVideo/AudioFormatsNames functions --- src/AvTranscoder/util.cpp | 45 +++++++++++++++++++++++++++++++++------ src/AvTranscoder/util.hpp | 18 +++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index 2cae0238..e1d0a3bf 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -121,8 +121,43 @@ NamesMap getAvailableFormatsNames() if(!fmt->name) continue; - formatsNames.insert( - std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); + formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); + } + return formatsNames; +} + +NamesMap getAvailableVideoFormatsNames() +{ + NamesMap formatsNames; + + AVOutputFormat* fmt = NULL; + while((fmt = av_oformat_next(fmt))) + { + if(!fmt->name) + continue; + + if(fmt->video_codec == AV_CODEC_ID_NONE) + continue; + + formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); + } + return formatsNames; +} + +NamesMap getAvailableAudioFormatsNames() +{ + NamesMap formatsNames; + + AVOutputFormat* fmt = NULL; + while((fmt = av_oformat_next(fmt))) + { + if(!fmt->name) + continue; + + if(fmt->audio_codec == AV_CODEC_ID_NONE) + continue; + + formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); } return formatsNames; } @@ -139,8 +174,7 @@ NamesMap getAvailableVideoCodecsNames() if(!c->name) continue; - videoCodecsNames.insert( - std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); + videoCodecsNames.insert(std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); } } return videoCodecsNames; @@ -158,8 +192,7 @@ NamesMap getAvailableAudioCodecsNames() if(!c->name) continue; - audioCodecsNames.insert( - std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); + audioCodecsNames.insert(std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); } } return audioCodecsNames; diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 304b5ee8..8b87a59d 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -58,19 +58,31 @@ std::string AvExport getPixelFormatName(const AVPixelFormat pixelFormat); std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); /** - * @brief Get a map of short/long names of all format available by FFmpeg / libav. + * @brief Get a map of short/long names of all formats available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableFormatsNames(); /** - * @brief Get a map of short/long names of all video codec available by FFmpeg / libav. + * @brief Get a map of short/long names of all formats dedicate for video available by FFmpeg / libav. + * @note Need to call preloadCodecsAndFormats before using this function. + */ +NamesMap AvExport getAvailableVideoFormatsNames(); + +/** + * @brief Get a map of short/long names of all formats dedicate for video available by FFmpeg / libav. + * @note Need to call preloadCodecsAndFormats before using this function. + */ +NamesMap AvExport getAvailableAudioFormatsNames(); + +/** + * @brief Get a map of short/long names of all video codecs available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableVideoCodecsNames(); /** - * @brief Get a map of short/long names of all audio codec available by FFmpeg / libav. + * @brief Get a map of short/long names of all audio codecs available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableAudioCodecsNames(); From f78e266a117905f4251d4c3d917942b0c15d7966 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 10 Mar 2016 12:15:25 +0100 Subject: [PATCH 16/18] util: added getAvailableFormats/Codecs functions * Call them in other functions. * Hide them from SWIG (unknown type). --- src/AvTranscoder/util.cpp | 73 +++++++++++++++++++++++---------------- src/AvTranscoder/util.hpp | 15 ++++++++ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/AvTranscoder/util.cpp b/src/AvTranscoder/util.cpp index e1d0a3bf..30fe9a1b 100644 --- a/src/AvTranscoder/util.cpp +++ b/src/AvTranscoder/util.cpp @@ -1,8 +1,6 @@ #include "util.hpp" extern "C" { -#include -#include #include } @@ -111,9 +109,9 @@ std::string getSampleFormatName(const AVSampleFormat sampleFormat) return formatName ? std::string(formatName) : ""; } -NamesMap getAvailableFormatsNames() +std::vector getAvailableFormats() { - NamesMap formatsNames; + std::vector formats; AVOutputFormat* fmt = NULL; while((fmt = av_oformat_next(fmt))) @@ -121,6 +119,18 @@ NamesMap getAvailableFormatsNames() if(!fmt->name) continue; + formats.push_back(fmt); + } + return formats; +} + +NamesMap getAvailableFormatsNames() +{ + NamesMap formatsNames; + std::vector formats = getAvailableFormats(); + for(size_t i = 0; i < formats.size(); ++i) + { + AVOutputFormat* fmt = formats.at(i); formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); } return formatsNames; @@ -129,16 +139,13 @@ NamesMap getAvailableFormatsNames() NamesMap getAvailableVideoFormatsNames() { NamesMap formatsNames; - - AVOutputFormat* fmt = NULL; - while((fmt = av_oformat_next(fmt))) + std::vector formats = getAvailableFormats(); + for(size_t i = 0; i < formats.size(); ++i) { - if(!fmt->name) - continue; - + AVOutputFormat* fmt = formats.at(i); + // skip format which cannot handle video if(fmt->video_codec == AV_CODEC_ID_NONE) continue; - formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); } return formatsNames; @@ -147,33 +154,42 @@ NamesMap getAvailableVideoFormatsNames() NamesMap getAvailableAudioFormatsNames() { NamesMap formatsNames; - - AVOutputFormat* fmt = NULL; - while((fmt = av_oformat_next(fmt))) + std::vector formats = getAvailableFormats(); + for(size_t i = 0; i < formats.size(); ++i) { - if(!fmt->name) - continue; - + AVOutputFormat* fmt = formats.at(i); + // skip format which cannot handle audio if(fmt->audio_codec == AV_CODEC_ID_NONE) continue; - formatsNames.insert(std::make_pair(std::string(fmt->name), std::string(fmt->long_name ? fmt->long_name : ""))); } return formatsNames; } -NamesMap getAvailableVideoCodecsNames() +std::vector getAvailableCodecs() { - NamesMap videoCodecsNames; + std::vector codecs; AVCodec* c = NULL; - while((c = av_codec_next(c)) != NULL) + while((c = av_codec_next(c))) + { + if(!c->name) + continue; + + codecs.push_back(c); + } + return codecs; +} + +NamesMap getAvailableVideoCodecsNames() +{ + NamesMap videoCodecsNames; + std::vector codecs = getAvailableCodecs(); + for(size_t i = 0; i < codecs.size(); ++i) { + AVCodec* c = codecs.at(i); if(c->type == AVMEDIA_TYPE_VIDEO) { - if(!c->name) - continue; - videoCodecsNames.insert(std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); } } @@ -183,15 +199,12 @@ NamesMap getAvailableVideoCodecsNames() NamesMap getAvailableAudioCodecsNames() { NamesMap audioCodecsNames; - - AVCodec* c = NULL; - while((c = av_codec_next(c)) != NULL) + std::vector codecs = getAvailableCodecs(); + for(size_t i = 0; i < codecs.size(); ++i) { + AVCodec* c = codecs.at(i); if(c->type == AVMEDIA_TYPE_AUDIO) { - if(!c->name) - continue; - audioCodecsNames.insert(std::make_pair(std::string(c->name), std::string(c->long_name ? c->long_name : ""))); } } diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 8b87a59d..9bc65d3c 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -5,6 +5,8 @@ #include "Option.hpp" extern "C" { +#include +#include #include #include } @@ -57,6 +59,12 @@ std::string AvExport getPixelFormatName(const AVPixelFormat pixelFormat); */ std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); +#ifndef SWIG +/** + * @return The list of all formats available by FFmpeg / libav. + */ +std::vector getAvailableFormats(); +#endif /** * @brief Get a map of short/long names of all formats available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. @@ -75,6 +83,13 @@ NamesMap AvExport getAvailableVideoFormatsNames(); */ NamesMap AvExport getAvailableAudioFormatsNames(); +#ifndef SWIG +/** + * @return The list of all codecs available by FFmpeg / libav. + */ +std::vector getAvailableCodecs(); +#endif + /** * @brief Get a map of short/long names of all video codecs available by FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. From ddbd3771c7d0ac09007277a0ff669f2062976980 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 10 Mar 2016 12:15:58 +0100 Subject: [PATCH 17/18] pyTest: updated tests to check available formats --- test/pyTest/testUtil.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/pyTest/testUtil.py b/test/pyTest/testUtil.py index 1addeb70..7895d884 100644 --- a/test/pyTest/testUtil.py +++ b/test/pyTest/testUtil.py @@ -62,6 +62,12 @@ def testAccessToAvailableFormatsNames(): availableFormats = av.getAvailableFormatsNames() assert_greater_equal(len(availableFormats), 135) + availableVideoFormats = av.getAvailableVideoFormatsNames() + assert_greater_equal(len(availableVideoFormats), 71) + + availableAudioFormats = av.getAvailableAudioFormatsNames() + assert_greater_equal(len(availableAudioFormats), 99) + def testAccessToAvailableVideoCodecsNames(): """ From 6ce13be82e2bc38efcd9556ee9c4f1147cc117e7 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 10 Mar 2016 13:56:49 +0100 Subject: [PATCH 18/18] util: fixed documentation --- src/AvTranscoder/util.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AvTranscoder/util.hpp b/src/AvTranscoder/util.hpp index 9bc65d3c..af35be31 100644 --- a/src/AvTranscoder/util.hpp +++ b/src/AvTranscoder/util.hpp @@ -61,43 +61,43 @@ std::string AvExport getSampleFormatName(const AVSampleFormat sampleFormat); #ifndef SWIG /** - * @return The list of all formats available by FFmpeg / libav. + * @return The list of all formats available in FFmpeg / libav. */ std::vector getAvailableFormats(); #endif /** - * @brief Get a map of short/long names of all formats available by FFmpeg / libav. + * @brief Get a map of short/long names of all formats available in FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableFormatsNames(); /** - * @brief Get a map of short/long names of all formats dedicate for video available by FFmpeg / libav. + * @brief Get a map of short/long names of all formats dedicate for video available in FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableVideoFormatsNames(); /** - * @brief Get a map of short/long names of all formats dedicate for video available by FFmpeg / libav. + * @brief Get a map of short/long names of all formats dedicate for video available in FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableAudioFormatsNames(); #ifndef SWIG /** - * @return The list of all codecs available by FFmpeg / libav. + * @return The list of all codecs available in FFmpeg / libav. */ std::vector getAvailableCodecs(); #endif /** - * @brief Get a map of short/long names of all video codecs available by FFmpeg / libav. + * @brief Get a map of short/long names of all video codecs available in FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableVideoCodecsNames(); /** - * @brief Get a map of short/long names of all audio codecs available by FFmpeg / libav. + * @brief Get a map of short/long names of all audio codecs available in FFmpeg / libav. * @note Need to call preloadCodecsAndFormats before using this function. */ NamesMap AvExport getAvailableAudioCodecsNames();